constructable 0.2.0 → 0.2.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.
- data/VERSION +1 -1
- data/constructable.gemspec +2 -2
- data/lib/constructable/attribute.rb +6 -0
- data/lib/constructable/constructor.rb +1 -1
- data/test/constructable/test_constructor.rb +6 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/constructable.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{constructable}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Manuel Korfmann"]
|
12
|
-
s.date = %q{2011-06-
|
12
|
+
s.date = %q{2011-06-10}
|
13
13
|
s.description = %q{
|
14
14
|
Adds the class macro Class#constructable to easily define what attributes a Class accepts provided as a hash to Class#new.
|
15
15
|
Attributes can be configured in their behaviour in case they are not provided or are in the wrong format.
|
@@ -30,6 +30,10 @@ module Constructable
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
+
def defined?
|
34
|
+
@defined
|
35
|
+
end
|
36
|
+
|
33
37
|
def accessible=(boolean)
|
34
38
|
if boolean
|
35
39
|
self.readable = true
|
@@ -56,9 +60,11 @@ module Constructable
|
|
56
60
|
check_for_requirement(requirement, constructor_hash)
|
57
61
|
end
|
58
62
|
value = constructor_hash[self.name]
|
63
|
+
@defined = true
|
59
64
|
self.converter ? converter.(value) : value
|
60
65
|
else
|
61
66
|
check_for_requirement(REQUIRED_REQUIREMENT, constructor_hash)
|
67
|
+
@defined = false
|
62
68
|
self.default
|
63
69
|
end.tap { |value| @value = value }
|
64
70
|
end
|
@@ -30,7 +30,7 @@ module Constructable
|
|
30
30
|
|
31
31
|
define_method(attribute.group) do
|
32
32
|
attributes.group_by(&:group)[attribute.group].inject({}) do |hash, attribute|
|
33
|
-
hash[attribute.name] = attribute.value
|
33
|
+
hash[attribute.name] = attribute.value if attribute.defined?
|
34
34
|
hash
|
35
35
|
end
|
36
36
|
end if attribute.group && !method_defined?(attribute.group)
|
@@ -32,6 +32,12 @@ describe 'Constructor' do
|
|
32
32
|
instance = @klass.new(foo: 1, bar: 2)
|
33
33
|
assert_equal({foo: 1, bar: 2}, instance.foobar)
|
34
34
|
end
|
35
|
+
|
36
|
+
it 'ONLY returns attributes acutally provided' do
|
37
|
+
@klass.constructable foobar: [:foo, :bar]
|
38
|
+
instance = @klass.new(foo: 1)
|
39
|
+
assert_equal false, instance.foobar.has_key?(:bar)
|
40
|
+
end
|
35
41
|
end
|
36
42
|
|
37
43
|
describe 'permission' do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: constructable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Manuel Korfmann
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-10 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -104,7 +104,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
104
|
requirements:
|
105
105
|
- - ">="
|
106
106
|
- !ruby/object:Gem::Version
|
107
|
-
hash: -
|
107
|
+
hash: -1729575163689007260
|
108
108
|
segments:
|
109
109
|
- 0
|
110
110
|
version: "0"
|