hexx 6.0.1 → 6.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +2 -2
- data/lib/hexx/coercible.rb +7 -7
- data/lib/hexx/helpers/{coersion.rb → coercion.rb} +9 -9
- data/lib/hexx/version.rb +1 -1
- data/spec/hexx/coercible_spec.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5363a542691cf187bc33c6af98944fddd629b593
|
4
|
+
data.tar.gz: b86bd725ce6048ddb028316b574918980b844012
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e451529cfaecd38210afa3d8e4206d23fbce09a1f966a8da564f20959eac30fc96c47e15ecf595ff7fd8b32ff818e5e06523e67b1f0d047f7fe678efddea4525
|
7
|
+
data.tar.gz: cb9ad8b597a55ce3f10c8c0246bb4e439489f528dd5806ced91a4547bfb1dc57fee7bf6a86ab5197feb9309ec5155c97b1912a15bdc8ae275d153e2bd791cede
|
data/README.rdoc
CHANGED
@@ -109,8 +109,8 @@ the raw value (<tt>"Ivo"</tt>) and the coerced one (<tt>#<Coercer @wrapped_strin
|
|
109
109
|
This is needed because the coercer works twofold - it coerces both the
|
110
110
|
setter and getter. The getter coercer will take the coerced value.
|
111
111
|
|
112
|
-
This feature is added for
|
113
|
-
|
112
|
+
This feature is added for compatibility with +ActiveRecord+ attributes
|
113
|
+
whose getters gives raw values from a database.
|
114
114
|
|
115
115
|
*Note*: The coercer from the +hexx+ gem itself won't work for +ActiveRecord+ models.
|
116
116
|
Use the +hexx-active_record+ gem instead. The gem extends the +Coercible+ model
|
data/lib/hexx/coercible.rb
CHANGED
@@ -26,18 +26,18 @@ module Hexx
|
|
26
26
|
# Coerced the attribute(s) with given type.
|
27
27
|
# @example (see Hexx::Coercible)
|
28
28
|
# @param [Array<Symbol, String>] names The list of attributes to be coerced.
|
29
|
-
# @param [Hash] options The
|
30
|
-
# @option options [Class] :type The class for
|
29
|
+
# @param [Hash] options The coercion options.
|
30
|
+
# @option options [Class] :type The class for coercion.
|
31
31
|
def attr_coerced(*names, type:)
|
32
|
-
names.flatten.each { |name|
|
32
|
+
names.flatten.each { |name| coercion.add self, name, type }
|
33
33
|
end
|
34
34
|
|
35
35
|
# @api hide
|
36
|
-
# The method returns a
|
36
|
+
# The method returns a coercion creator for PORO object only.
|
37
37
|
# To be reloaded for ActiveRecord models
|
38
|
-
# @return [Class] attribute
|
39
|
-
def
|
40
|
-
|
38
|
+
# @return [Class] attribute coercion (Hexx::Helpers::Coercion by default)
|
39
|
+
def coercion
|
40
|
+
Hexx::Helpers::Coercion
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -8,13 +8,13 @@ module Hexx
|
|
8
8
|
# Coerces class attribute getter and setter with given type.
|
9
9
|
#
|
10
10
|
# @example
|
11
|
-
#
|
11
|
+
# Coercion.add MyClass, :name, Multibyte::Chars
|
12
12
|
# object = MyClass.new
|
13
13
|
#
|
14
14
|
# object.name = "Ivo"
|
15
15
|
# object.name
|
16
16
|
# # => #<Multibyte::Chars @wrapped_string="Ivo" >
|
17
|
-
class
|
17
|
+
class Coercion < Base
|
18
18
|
|
19
19
|
# @api hide
|
20
20
|
# @!scope class
|
@@ -22,11 +22,11 @@ module Hexx
|
|
22
22
|
# Reloads the Base class initializer by adding the type of the attribute
|
23
23
|
# to coerce with.
|
24
24
|
#
|
25
|
-
# @example (see Hexx::Helpers::
|
25
|
+
# @example (see Hexx::Helpers::Coercion)
|
26
26
|
# @param (see Hexx::Helpers::Base.add)
|
27
27
|
# @param [Module] type The type of the attribute.
|
28
|
-
# @raise (see Hexx::Helpers::
|
29
|
-
# @return [Hexx::Helpers::
|
28
|
+
# @raise (see Hexx::Helpers::Coercion#validate)
|
29
|
+
# @return [Hexx::Helpers::Coercion] the coercion object.
|
30
30
|
def initialize(target, name, type)
|
31
31
|
super target, name
|
32
32
|
@type = type
|
@@ -38,14 +38,14 @@ module Hexx
|
|
38
38
|
attr_accessor :type
|
39
39
|
|
40
40
|
# @api hide
|
41
|
-
# Validates parameters of the
|
41
|
+
# Validates parameters of the coercion declaration.
|
42
42
|
#
|
43
|
-
# Adds validation of the
|
43
|
+
# Adds validation of the coercion type to the
|
44
44
|
# {Hexx::Helper::Base#validate}.
|
45
45
|
#
|
46
46
|
# @raise (see Hexx::Helpers::Base.validate)
|
47
|
-
# @raise (see Hexx::Helpers::
|
48
|
-
# @return [Hexx::Helpers::
|
47
|
+
# @raise (see Hexx::Helpers::Coercion#check_type)
|
48
|
+
# @return [Hexx::Helpers::Coercion] +self+
|
49
49
|
def validate
|
50
50
|
check_type
|
51
51
|
super
|
data/lib/hexx/version.rb
CHANGED
data/spec/hexx/coercible_spec.rb
CHANGED
@@ -9,13 +9,13 @@ module Hexx
|
|
9
9
|
|
10
10
|
before { class TestModel; extend Coercible; end }
|
11
11
|
before { module TestModule; end }
|
12
|
-
before { class
|
12
|
+
before { class TestCoercion < Struct.new(:string); end }
|
13
13
|
|
14
14
|
let(:test_model) { TestModel }
|
15
15
|
let(:test_module) { TestModule }
|
16
|
-
let(:
|
16
|
+
let(:test_coercion) { TestCoercion }
|
17
17
|
|
18
|
-
after { Hexx.send :remove_const, :
|
18
|
+
after { Hexx.send :remove_const, :TestCoercion }
|
19
19
|
after { Hexx.send :remove_const, :TestModule }
|
20
20
|
after { Hexx.send :remove_const, :TestModel }
|
21
21
|
|
@@ -25,12 +25,12 @@ module Hexx
|
|
25
25
|
|
26
26
|
describe ".attr_coerced" do
|
27
27
|
|
28
|
-
before { test_model.send :attr_coerced, :name, type:
|
28
|
+
before { test_model.send :attr_coerced, :name, type: test_coercion }
|
29
29
|
subject { test_model.new }
|
30
30
|
|
31
31
|
it "coerces an attribute with given type" do
|
32
32
|
subject.name = "some name"
|
33
|
-
expect(subject.name).to be_kind_of
|
33
|
+
expect(subject.name).to be_kind_of test_coercion
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hexx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0.
|
4
|
+
version: 6.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kozin
|
@@ -153,7 +153,7 @@ files:
|
|
153
153
|
- lib/hexx/configurable.rb
|
154
154
|
- lib/hexx/dependable.rb
|
155
155
|
- lib/hexx/helpers/base.rb
|
156
|
-
- lib/hexx/helpers/
|
156
|
+
- lib/hexx/helpers/coercion.rb
|
157
157
|
- lib/hexx/helpers/dependency.rb
|
158
158
|
- lib/hexx/helpers/module_dependency.rb
|
159
159
|
- lib/hexx/helpers/parameter.rb
|