coercible 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 709edbe22e3e38bb3e2c6408e6dd2c7edd441a3b
4
+ data.tar.gz: dfc9e7750e14888a69cfa6657fe795e0e7b9298d
5
+ SHA512:
6
+ metadata.gz: 0e45ec911eb3e4d22aab74081091b9e2d80911d0875be1b0bdd4b661700b52b54690f08ccb5af80fd84dc9953d17d8eb08e5b2e3b3e8cbd57c00bb6114413067
7
+ data.tar.gz: 652a0700da4b6999628b39c9278316aeaa38d668a8e53bcab7d0e76b2e511d12912d3f12e8607e62d4568337e63d12cbc76308ef8ad1be581fbeae205c63e980
@@ -3,15 +3,11 @@ before_install: gem install bundler
3
3
  bundler_args: --without guard metrics
4
4
  script: "bundle exec rake spec"
5
5
  rvm:
6
- - 1.8.7
7
6
  - 1.9.2
8
7
  - 1.9.3
9
8
  - 2.0.0
10
- - jruby-18mode
11
9
  - jruby-19mode
12
- - rbx-18mode
13
10
  - rbx-19mode
14
- - ree
15
11
  - jruby-head
16
12
 
17
13
  notifications:
@@ -1,3 +1,7 @@
1
+ # v1.0.0 2013-12-10
2
+
3
+ Dropped 1.8.7 support.
4
+
1
5
  # v0.2.0 2013-03-08
2
6
 
3
7
  * [internal] Update to latest backports (solnic)
data/Gemfile CHANGED
@@ -2,5 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'devtools', :git => 'https://github.com/datamapper/devtools.git'
6
- eval File.read('Gemfile.devtools')
5
+ gem 'devtools', :git => 'https://github.com/rom-rb/devtools.git'
6
+ eval_gemfile 'Gemfile.devtools'
@@ -29,7 +29,6 @@ group :guard do
29
29
  end
30
30
 
31
31
  group :metrics do
32
- gem 'backports', '~> 3.0', '>= 3.1.0'
33
32
  gem 'flay', '~> 2.1.0'
34
33
  gem 'flog', '~> 3.2.2'
35
34
  gem 'reek', '~> 1.3.1', :git => 'https://github.com/troessner/reek.git'
@@ -11,12 +11,12 @@ Gem::Specification.new do |gem|
11
11
  gem.description = %q{Powerful, flexible and configurable coercion library. And nothing more.}
12
12
  gem.summary = gem.description
13
13
  gem.homepage = "https://github.com/solnic/coercible"
14
+ gem.license = "MIT"
14
15
 
15
16
  gem.files = `git ls-files`.split($/)
16
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
19
  gem.require_paths = ["lib"]
19
20
 
20
- gem.add_dependency 'backports', [ '~> 3.0', '>= 3.1.0' ]
21
21
  gem.add_dependency 'descendants_tracker', '~> 0.0.1'
22
22
  end
@@ -3,6 +3,15 @@ module Coercible
3
3
 
4
4
  UnsupportedCoercion = Class.new(StandardError)
5
5
 
6
+ # Test for rubinius platform
7
+ #
8
+ # @return [true]
9
+ # if running under rubinius
10
+ #
11
+ # @return [false]
12
+ # otherwise
13
+ #
14
+ # @api private
6
15
  def self.rbx?
7
16
  @is_rbx ||= defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
8
17
  end
@@ -13,7 +22,6 @@ require 'time'
13
22
  require 'bigdecimal'
14
23
  require 'bigdecimal/util'
15
24
  require 'set'
16
- require 'backports'
17
25
 
18
26
  require 'descendants_tracker'
19
27
  require 'support/options'
@@ -48,6 +48,10 @@ module Coercible
48
48
  name.downcase.split('::').last.to_sym
49
49
  end
50
50
 
51
+ # Return configuration class
52
+ #
53
+ # @return [Class:Configuration]
54
+ #
51
55
  # @api private
52
56
  def configuration_class
53
57
  Configuration
@@ -31,6 +31,9 @@ module Coercible
31
31
 
32
32
  # Inspect the coercer object
33
33
  #
34
+ # @example
35
+ # coercer[Object].inspect # => "<Coercer::Object primitive=Object>"
36
+ #
34
37
  # @return [String]
35
38
  #
36
39
  # @api public
@@ -76,7 +79,7 @@ module Coercible
76
79
  #
77
80
  # @api public
78
81
  def to_hash(value)
79
- coerce_with_method(value, :to_hash)
82
+ coerce_with_method(value, :to_hash, __method__)
80
83
  end
81
84
 
82
85
  # Create a String from the Object if possible
@@ -96,7 +99,7 @@ module Coercible
96
99
  #
97
100
  # @api public
98
101
  def to_string(value)
99
- coerce_with_method(value, :to_str)
102
+ coerce_with_method(value, :to_str, __method__)
100
103
  end
101
104
 
102
105
  # Create an Integer from the Object if possible
@@ -116,11 +119,17 @@ module Coercible
116
119
  #
117
120
  # @api public
118
121
  def to_integer(value)
119
- coerce_with_method(value, :to_int)
122
+ coerce_with_method(value, :to_int, __method__)
120
123
  end
121
124
 
122
125
  # Return if the value was successfuly coerced
123
126
  #
127
+ # @example when coercion was successful
128
+ # coercer[String].coerced?(1) # => true
129
+ #
130
+ # @example when coercion was NOT successful
131
+ # coercer[String].coerced?("foo") # => false
132
+ #
124
133
  # @return [TrueClass,FalseClass]
125
134
  #
126
135
  # @api public
@@ -168,8 +177,8 @@ module Coercible
168
177
  # @return [Object]
169
178
  #
170
179
  # @api private
171
- def coerce_with_method(value, method)
172
- value.respond_to?(method) ? value.public_send(method) : value
180
+ def coerce_with_method(value, method, ref_method)
181
+ value.respond_to?(method) ? value.public_send(method) : raise_unsupported_coercion(value, ref_method)
173
182
  end
174
183
 
175
184
  end # class Object
@@ -159,9 +159,10 @@ module Coercible
159
159
  else
160
160
  # coerce to a Float first to evaluate scientific notation (if any)
161
161
  # that may change the integer part, then convert to an integer
162
- coerced = to_float(value)
163
- ::Float === coerced ? coerced.to_i : coerced
162
+ to_float(value).to_i
164
163
  end
164
+ rescue UnsupportedCoercion
165
+ raise_unsupported_coercion(value, __method__)
165
166
  end
166
167
 
167
168
  # Coerce value to float
@@ -176,6 +177,8 @@ module Coercible
176
177
  # @api public
177
178
  def to_float(value)
178
179
  to_numeric(value, :to_f)
180
+ rescue UnsupportedCoercion
181
+ raise_unsupported_coercion(value, __method__)
179
182
  end
180
183
 
181
184
  # Coerce value to decimal
@@ -190,6 +193,8 @@ module Coercible
190
193
  # @api public
191
194
  def to_decimal(value)
192
195
  to_numeric(value, :to_d)
196
+ rescue UnsupportedCoercion
197
+ raise_unsupported_coercion(value, __method__)
193
198
  end
194
199
 
195
200
  private
@@ -226,7 +231,7 @@ module Coercible
226
231
  if value =~ NUMERIC_REGEXP
227
232
  $1.public_send(method)
228
233
  else
229
- value
234
+ raise_unsupported_coercion(value, method)
230
235
  end
231
236
  end
232
237
 
@@ -73,11 +73,10 @@ module Coercible
73
73
  #
74
74
  # @api private
75
75
  def coerce_with_method(value, method)
76
- coerced = super
77
- if coerced.equal?(value)
78
- coercers[::String].public_send(method, to_string(value))
76
+ if value.respond_to?(method)
77
+ value.public_send(method)
79
78
  else
80
- coerced
79
+ coercers[::String].public_send(method, to_string(value))
81
80
  end
82
81
  end
83
82
 
@@ -1,3 +1,3 @@
1
1
  module Coercible
2
- VERSION = "0.2.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -4,6 +4,12 @@ module Coercible
4
4
  module Options
5
5
  Undefined = Class.new.freeze
6
6
 
7
+ # Hook called when descendant was extended
8
+ #
9
+ # @param [Class,Module] descendant
10
+ #
11
+ # @return [undefined]
12
+ #
7
13
  # @api private
8
14
  def self.extended(descendant)
9
15
  descendant.extend(DescendantsTracker)
@@ -17,6 +17,6 @@ describe Coercer::Object, '.to_hash' do
17
17
  end
18
18
 
19
19
  context 'when the value does not respond to #to_hash' do
20
- it { should be(value) }
20
+ specify { expect { subject }.to raise_error(UnsupportedCoercion) }
21
21
  end
22
22
  end
@@ -17,6 +17,6 @@ describe Coercer::Object, '.to_integer' do
17
17
  end
18
18
 
19
19
  context 'when the value does not respond to #to_int' do
20
- it { should be(value) }
20
+ specify { expect { subject }.to raise_error(UnsupportedCoercion) }
21
21
  end
22
22
  end
@@ -17,6 +17,6 @@ describe Coercer::Object, '.to_string' do
17
17
  end
18
18
 
19
19
  context 'when the value does not respond to #to_str' do
20
- it { should be(value) }
20
+ specify { expect { subject }.to raise_error(UnsupportedCoercion) }
21
21
  end
22
22
  end
@@ -42,6 +42,6 @@ describe Coercer::String, '.to_decimal' do
42
42
  context 'with an invalid decimal string' do
43
43
  let(:string) { 'non-decimal' }
44
44
 
45
- it { should equal(string) }
45
+ specify { expect { subject }.to raise_error(UnsupportedCoercion) }
46
46
  end
47
47
  end
@@ -45,13 +45,12 @@ describe Coercer::String, '.to_float' do
45
45
  context 'with an invalid float string' do
46
46
  let(:string) { 'non-float' }
47
47
 
48
- it { should equal(string) }
48
+ specify { expect { subject }.to raise_error(UnsupportedCoercion) }
49
49
  end
50
50
 
51
51
  context 'string starts with e' do
52
52
  let(:string) { 'e1' }
53
53
 
54
- # In further version it will raise exception
55
- it { should == 'e1' }
54
+ specify { expect { subject }.to raise_error(UnsupportedCoercion) }
56
55
  end
57
56
  end
@@ -50,7 +50,7 @@ describe Coercer::String, '.to_integer' do
50
50
  context 'with an invalid integer string' do
51
51
  let(:string) { 'non-integer' }
52
52
 
53
- it { should equal(string) }
53
+ specify { expect { subject }.to raise_error(UnsupportedCoercion) }
54
54
  end
55
55
 
56
56
  context 'when integer string is big' do
@@ -62,7 +62,6 @@ describe Coercer::String, '.to_integer' do
62
62
  context 'string starts with e' do
63
63
  let(:string) { 'e1' }
64
64
 
65
- # In further version it will raise exception
66
- it { should == 'e1' }
65
+ specify { expect { subject }.to raise_error(UnsupportedCoercion) }
67
66
  end
68
67
  end
metadata CHANGED
@@ -1,42 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coercible
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Piotr Solnica
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-08 00:00:00.000000000 Z
11
+ date: 2013-12-10 00:00:00.000000000 Z
13
12
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: backports
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '3.0'
22
- - - ! '>='
23
- - !ruby/object:Gem::Version
24
- version: 3.1.0
25
- type: :runtime
26
- prerelease: false
27
- version_requirements: !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ~>
31
- - !ruby/object:Gem::Version
32
- version: '3.0'
33
- - - ! '>='
34
- - !ruby/object:Gem::Version
35
- version: 3.1.0
36
13
  - !ruby/object:Gem::Dependency
37
14
  name: descendants_tracker
38
15
  requirement: !ruby/object:Gem::Requirement
39
- none: false
40
16
  requirements:
41
17
  - - ~>
42
18
  - !ruby/object:Gem::Version
@@ -44,7 +20,6 @@ dependencies:
44
20
  type: :runtime
45
21
  prerelease: false
46
22
  version_requirements: !ruby/object:Gem::Requirement
47
- none: false
48
23
  requirements:
49
24
  - - ~>
50
25
  - !ruby/object:Gem::Version
@@ -72,7 +47,6 @@ files:
72
47
  - config/mutant.yml
73
48
  - config/roodi.yml
74
49
  - config/site.reek
75
- - config/yardstick.yml
76
50
  - lib/coercible.rb
77
51
  - lib/coercible/coercer.rb
78
52
  - lib/coercible/coercer/array.rb
@@ -178,28 +152,28 @@ files:
178
152
  - spec/unit/coercible/coercer/true_class/to_string_spec.rb
179
153
  - spec/unit/coercible/configuration/class_methods/build_spec.rb
180
154
  homepage: https://github.com/solnic/coercible
181
- licenses: []
155
+ licenses:
156
+ - MIT
157
+ metadata: {}
182
158
  post_install_message:
183
159
  rdoc_options: []
184
160
  require_paths:
185
161
  - lib
186
162
  required_ruby_version: !ruby/object:Gem::Requirement
187
- none: false
188
163
  requirements:
189
- - - ! '>='
164
+ - - '>='
190
165
  - !ruby/object:Gem::Version
191
166
  version: '0'
192
167
  required_rubygems_version: !ruby/object:Gem::Requirement
193
- none: false
194
168
  requirements:
195
- - - ! '>='
169
+ - - '>='
196
170
  - !ruby/object:Gem::Version
197
171
  version: '0'
198
172
  requirements: []
199
173
  rubyforge_project:
200
- rubygems_version: 1.8.24
174
+ rubygems_version: 2.0.3
201
175
  signing_key:
202
- specification_version: 3
176
+ specification_version: 4
203
177
  summary: Powerful, flexible and configurable coercion library. And nothing more.
204
178
  test_files:
205
179
  - spec/integration/configuring_coercers_spec.rb
@@ -1,2 +0,0 @@
1
- ---
2
- threshold: 100.0