Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend message with value inspecting while raises TypeCastingError #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

# [0.8.0] - 2021-12-09
### Added
- Extend message with value inspecting while raises TypeCastingError;

# [0.7.0] - 2021-11-22
### Added
- Added Github Actions CI;
Expand Down
77 changes: 38 additions & 39 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,43 @@ PATH
remote: .
specs:
smart_types (0.7.0)
smart_engine (~> 0.11)
smart_engine (~> 0.12)

GEM
remote: https://rubygems.org/
specs:
activesupport (6.1.1)
activesupport (6.1.4.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
armitage-rubocop (1.7.0.1)
rubocop (= 1.7.0)
rubocop-performance (= 1.9.1)
rubocop-rails (= 2.9.1)
rubocop-rake (= 0.5.1)
rubocop-rspec (= 2.1.0)
ast (2.4.1)
armitage-rubocop (1.23.0.1)
rubocop (= 1.23.0)
rubocop-performance (= 1.12.0)
rubocop-rails (= 2.12.4)
rubocop-rake (= 0.6.0)
rubocop-rspec (= 2.6.0)
ast (2.4.2)
coderay (1.1.3)
concurrent-ruby (1.1.7)
concurrent-ruby (1.1.9)
diff-lcs (1.4.4)
docile (1.3.5)
i18n (1.8.7)
docile (1.4.0)
i18n (1.8.11)
concurrent-ruby (~> 1.0)
method_source (1.0.0)
minitest (5.14.3)
parallel (1.20.1)
parser (3.0.0.0)
minitest (5.14.4)
parallel (1.21.0)
parser (3.0.3.2)
ast (~> 2.4.1)
pry (0.13.1)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
rack (2.2.3)
rainbow (3.0.0)
rake (13.0.3)
regexp_parser (2.0.3)
rexml (3.2.4)
rake (13.0.6)
regexp_parser (2.2.0)
rexml (3.2.5)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
Expand All @@ -48,46 +48,45 @@ GEM
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.1)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.1)
rubocop (1.7.0)
rspec-support (3.10.3)
rubocop (1.23.0)
parallel (~> 1.10)
parser (>= 2.7.1.5)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.2.0, < 2.0)
rubocop-ast (>= 1.12.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (1.4.0)
parser (>= 2.7.1.5)
rubocop-performance (1.9.1)
rubocop (>= 0.90.0, < 2.0)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.14.0)
parser (>= 3.0.1.1)
rubocop-performance (1.12.0)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.9.1)
rubocop-rails (2.12.4)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 0.90.0, < 2.0)
rubocop-rake (0.5.1)
rubocop
rubocop-rspec (2.1.0)
rubocop (>= 1.7.0, < 2.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-ast (>= 1.1.0)
rubocop-rspec (2.6.0)
rubocop (~> 1.19)
ruby-progressbar (1.11.0)
simplecov (0.21.2)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov-lcov (0.8.0)
simplecov_json_formatter (0.1.2)
smart_engine (0.11.0)
simplecov_json_formatter (0.1.3)
smart_engine (0.12.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (1.7.0)
zeitwerk (2.4.2)
unicode-display_width (2.1.0)
zeitwerk (2.5.1)

PLATFORMS
x86_64-darwin-19
Expand Down
2 changes: 1 addition & 1 deletion lib/smart_core/types/value/big_decimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
begin
::Kernel.BigDecimal(value.to_d)
rescue ::ArgumentError, ::TypeError, ::NoMethodError
raise(SmartCore::Types::TypeCastingError, 'Non-castable to BigDecimal')
raise(SmartCore::Types::TypeCastingError, "#{value.inspect} non-castable to BigDecimal")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/smart_core/types/value/date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
begin
::Date.parse(value)
rescue ::ArgumentError, ::TypeError
raise(SmartCore::Types::TypeCastingError, 'Non-castable to Date')
raise(SmartCore::Types::TypeCastingError, "#{value.inspect} non-castable to Date")
end
end
end
2 changes: 1 addition & 1 deletion lib/smart_core/types/value/date_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
begin
::DateTime.parse(value)
rescue ::ArgumentError, ::TypeError
raise(SmartCore::Types::TypeCastingError, 'Non-castable to DateTime')
raise(SmartCore::Types::TypeCastingError, "#{value.inspect} non-castable to DateTime")
end
end
end
2 changes: 1 addition & 1 deletion lib/smart_core/types/value/float.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
begin
::Kernel.Float(value.to_f)
rescue ::NoMethodError, ::TypeError, ::ArgumentError
raise(SmartCore::Types::TypeCastingError, 'Non-castable to Float')
raise(SmartCore::Types::TypeCastingError, "#{value.inspect} non-castable to Float")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/smart_core/types/value/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# - ::Kernel.Hash is used to validate the returned value from `#to_h`
::Kernel.Hash(value.to_h)
rescue ::TypeError, ::NoMethodError, ::ArgumentError
raise(SmartCore::Types::TypeCastingError, 'Non-castable to Hash')
raise(SmartCore::Types::TypeCastingError, "#{value.inspect} non-castable to Hash")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/smart_core/types/value/integer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# => ::Kernel.Integer(nil.to_i) # => 0 (::Kernel.Integer used as validation layer)
::Kernel.Integer(value.to_i)
rescue ::TypeError, ::NoMethodError, ::ArgumentError, ::FloatDomainError
raise(SmartCore::Types::TypeCastingError, 'Non-castable to Integer')
raise(SmartCore::Types::TypeCastingError, "#{value.inspect} non-castable to Integer")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/smart_core/types/value/numeric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
begin
SmartCore::Types::Value::BigDecimal.cast(value)
rescue SmartCore::Types::TypeCastingError
raise(SmartCore::Types::TypeCastingError, 'Non-castable to Numeric')
raise(SmartCore::Types::TypeCastingError, "#{value.inspect} non-castable to Numeric")
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/smart_core/types/value/proc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
begin
value.to_proc.tap do |result|
unless result.is_a?(::Proc)
raise(SmartCore::Types::TypeCastingError, 'Non-castable to Proc')
raise(SmartCore::Types::TypeCastingError, "#{value.inspect} non-castable to Proc")
end
end
rescue ::NoMethodError
raise(SmartCore::Types::TypeCastingError, 'Non-castable to Proc')
raise(SmartCore::Types::TypeCastingError, "#{value.inspect} non-castable to Proc")
end
end
end
2 changes: 1 addition & 1 deletion lib/smart_core/types/value/set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
begin
::Set.new(SmartCore::Types::Value::Array.cast(value))
rescue ::ArgumentError, ::NoMethodError
raise(SmartCore::Types::TypeCastingError, 'Non-castable to Set')
raise(SmartCore::Types::TypeCastingError, "#{value.inspect} non-castable to Set")
end
end
end
2 changes: 1 addition & 1 deletion lib/smart_core/types/value/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
begin
::Kernel.String(value)
rescue ::TypeError, ::ArgumentError
raise(SmartCore::Types::TypeCastingError, 'Non-castable to String')
raise(SmartCore::Types::TypeCastingError, "#{value.inspect} non-castable to String")
end
end
end
2 changes: 1 addition & 1 deletion lib/smart_core/types/value/symbol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
begin
value.to_sym
rescue ::NoMethodError, ::ArgumentError
raise(SmartCore::Types::TypeCastingError, 'Non-castable to Symbol')
raise(SmartCore::Types::TypeCastingError, "#{value.inspect} non-castable to Symbol")
end
end
end
4 changes: 3 additions & 1 deletion lib/smart_core/types/value/text.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

using SmartCore::Ext::BasicObjectAsObject

# @api public
# @since 0.1.0
# @version 0.3.0
Expand All @@ -18,7 +20,7 @@
begin
SmartCore::Types::Value::Symbol.cast(value)
rescue SmartCore::Types::TypeCastingError
raise(SmartCore::Types::TypeCastingError, 'Non-castable to text')
raise(SmartCore::Types::TypeCastingError, "#{value.inspect} non-castable to text")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/smart_core/types/value/time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
begin
SmartCore::Types::Value::Integer.valid?(value) ? ::Time.at(value) : ::Time.parse(value)
rescue ::TypeError, ::ArgumentError
raise(SmartCore::Types::TypeCastingError, 'Non-castable to Time')
raise(SmartCore::Types::TypeCastingError, "#{value.inspect} non-castable to Time")
end
end
end
7 changes: 6 additions & 1 deletion lib/smart_core/types/value/time_based.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

using SmartCore::Ext::BasicObjectAsObject

# @api public
# @since 0.1.0
# @version 0.3.0
Expand All @@ -24,7 +26,10 @@
begin
SmartCore::Types::Value::Date.cast(value)
rescue SmartCore::Types::TypeCastingError
raise(SmartCore::Types::TypeCastingError, 'Non-castable to time-based type')
raise(
SmartCore::Types::TypeCastingError,
"#{value.inspect} non-castable to time-based type"
)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/smart_core/types/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Types
#
# @api public
# @since 0.1.0
# @version 0.7.0
VERSION = '0.7.0'
# @version 0.8.0
VERSION = '0.8.0'
end
end
2 changes: 1 addition & 1 deletion smart_types.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'smart_engine', '~> 0.11'
spec.add_dependency 'smart_engine', '~> 0.12'

spec.add_development_dependency 'bundler', '~> 2.1'
spec.add_development_dependency 'rake', '~> 13.0'
Expand Down