hexx 6.0.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.rdoc +3 -3
- data/lib/hexx/coercible.rb +8 -6
- data/lib/hexx/version.rb +1 -1
- data/spec/hexx/coercible_spec.rb +0 -19
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0cdf93b0a9b2731e1132c5987fdc18d3d8d86817
|
4
|
+
data.tar.gz: e3de7b204aa8c259b104de8474c78ddbdf444b94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc228d070214f05121017f3a52c6356d7d0edd66cb284a87dcf088f1bda1542e94578c193af9f5036d067c7053f5210c57242916c7e1b80b19fa989c7efcfa7c
|
7
|
+
data.tar.gz: bdef6fd6763889be4504d0960e634ea4b0870f00dce640f959019df447002aa1303a3d4d365a4830c6ebafe71bea5197ad479b23570c2d9e57d5d2598e79eb5b
|
data/README.rdoc
CHANGED
@@ -105,14 +105,14 @@ the +Coercer+ class.
|
|
105
105
|
# #<Coercer @wrapped_string="Ivo" >
|
106
106
|
|
107
107
|
Be careful when designing a coercer class. Its constructor should accept both
|
108
|
-
the raw value ("Ivo") and the coerced one (
|
108
|
+
the raw value (<tt>"Ivo"</tt>) and the coerced one (<tt>#<Coercer @wrapped_string = "Ivo"></tt>).
|
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
112
|
This feature is added for comparison with +ActiveRecord+ attributes coersion
|
113
113
|
where the getter is given with stored raw values (a string etc.)
|
114
114
|
|
115
|
-
*Note*: The coercer from +hexx+ gem itself won't work for +ActiveRecord+ models.
|
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
|
117
117
|
so that the +attr_coerced+ reloads +ActiveRecord+ attributes properly.
|
118
118
|
|
@@ -254,7 +254,7 @@ Inside a service use the +add_message+ to add message to the +messages+ array:
|
|
254
254
|
|
255
255
|
The class implements the {Null object}[http://robots.thoughtbot.com/rails-refactoring-example-introduce-null-object] pattern. The object:
|
256
256
|
|
257
|
-
* responds like +nil+ to
|
257
|
+
* responds like +nil+ to <tt><=></tt>, +eq?+, +nil?+, +false?+, +true?+, +to_s+,
|
258
258
|
+to_i+, +to_f+, +to_c+, +to_r+, +to_nil+
|
259
259
|
* responds with +self+ to any other method call
|
260
260
|
|
data/lib/hexx/coercible.rb
CHANGED
@@ -22,12 +22,6 @@ module Hexx
|
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
-
# @api hide
|
26
|
-
def self.extended(klass)
|
27
|
-
klass.send :extend, Configurable
|
28
|
-
klass.send :depends_on, :coersion, default: Helpers::Coersion
|
29
|
-
end
|
30
|
-
|
31
25
|
# @!method attr_coerced(*names, options)
|
32
26
|
# Coerced the attribute(s) with given type.
|
33
27
|
# @example (see Hexx::Coercible)
|
@@ -37,5 +31,13 @@ module Hexx
|
|
37
31
|
def attr_coerced(*names, type:)
|
38
32
|
names.flatten.each { |name| coersion.add self, name, type }
|
39
33
|
end
|
34
|
+
|
35
|
+
# @api hide
|
36
|
+
# The method returns a coersion creator for PORO object only.
|
37
|
+
# To be reloaded for ActiveRecord models
|
38
|
+
# @return [Class] attribute coersion (Hexx::Helpers::Coersion by default)
|
39
|
+
def coersion
|
40
|
+
@coersion ||= Hexx::Helpers::Coersion
|
41
|
+
end
|
40
42
|
end
|
41
43
|
end
|
data/lib/hexx/version.rb
CHANGED
data/spec/hexx/coercible_spec.rb
CHANGED
@@ -23,25 +23,6 @@ module Hexx
|
|
23
23
|
# Run tests
|
24
24
|
# ==========================================================================
|
25
25
|
|
26
|
-
describe ".coersion" do
|
27
|
-
|
28
|
-
it "is defined" do
|
29
|
-
expect(test_model).to respond_to :coersion
|
30
|
-
end
|
31
|
-
|
32
|
-
it "is set by default" do
|
33
|
-
expect(test_model.coersion).to be_kind_of Module
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe ".coersion=" do
|
38
|
-
|
39
|
-
it "sets the .coersion" do
|
40
|
-
expect { test_model.coersion = test_module }
|
41
|
-
.to change { test_model.coersion }.to test_module
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
26
|
describe ".attr_coerced" do
|
46
27
|
|
47
28
|
before { test_model.send :attr_coerced, :name, type: test_coersion }
|