setsumei 0.0.4 → 0.0.5
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/lib/setsumei/describable/boolean_attribute.rb +7 -4
- data/lib/setsumei/describable/float_attribute.rb +8 -3
- data/lib/setsumei/describable/int_attribute.rb +7 -4
- data/lib/setsumei/describable/object_attribute.rb +6 -2
- data/lib/setsumei/describable/string_attribute.rb +8 -3
- data/lib/setsumei/version.rb +1 -1
- data/spec/setsumei/describable/boolean_attribute_spec.rb +1 -0
- data/spec/setsumei/describable/float_attribute_spec.rb +1 -0
- data/spec/setsumei/describable/int_attribute_spec.rb +1 -0
- data/spec/setsumei/describable/object_attribute_spec.rb +1 -0
- data/spec/setsumei/describable/string_attribute_spec.rb +1 -0
- data/spec/support/shared_examples/attribute_lookup_key_support.rb +15 -0
- data/spec/support/shared_examples/attribute_options.rb +17 -0
- metadata +4 -2
@@ -6,12 +6,12 @@ module Setsumei
|
|
6
6
|
options = options.dup
|
7
7
|
new.tap do |attribute|
|
8
8
|
attribute.name = name
|
9
|
-
options.delete(:
|
10
|
-
attribute.options = options
|
9
|
+
attribute.lookup_key = options.delete(:from_within)
|
10
|
+
attribute.options = options.tap { |o| o.delete :as_a }
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
attr_accessor :name, :options
|
14
|
+
attr_accessor :name, :options, :lookup_key
|
15
15
|
|
16
16
|
def is_an_attribute_of_type?(type)
|
17
17
|
type == :boolean || type == self.class
|
@@ -30,7 +30,10 @@ module Setsumei
|
|
30
30
|
:"#{name}="
|
31
31
|
end
|
32
32
|
def value_from_hash(hash)
|
33
|
-
value_for hash[
|
33
|
+
value_for hash[ key_for(hash)]
|
34
|
+
end
|
35
|
+
def key_for(hash)
|
36
|
+
lookup_key || Build::Key.for(name, given: hash.keys)
|
34
37
|
end
|
35
38
|
end
|
36
39
|
end
|
@@ -3,13 +3,15 @@ module Setsumei
|
|
3
3
|
class FloatAttribute
|
4
4
|
|
5
5
|
def FloatAttribute.named(name, options = {})
|
6
|
+
options = options.dup
|
6
7
|
new.tap do |attribute|
|
7
8
|
attribute.name = name
|
8
|
-
attribute.
|
9
|
+
attribute.lookup_key = options.delete(:from_within)
|
10
|
+
attribute.options = options.tap { |o| o.delete :as_a }
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
12
|
-
attr_accessor :name, :options
|
14
|
+
attr_accessor :name, :options, :lookup_key
|
13
15
|
|
14
16
|
def is_an_attribute_of_type?(type)
|
15
17
|
type == :float || type == self.class
|
@@ -28,7 +30,10 @@ module Setsumei
|
|
28
30
|
:"#{name}="
|
29
31
|
end
|
30
32
|
def value_from_hash(hash)
|
31
|
-
value_for hash[
|
33
|
+
value_for hash[ key_for(hash)]
|
34
|
+
end
|
35
|
+
def key_for(hash)
|
36
|
+
lookup_key || Build::Key.for(name, given: hash.keys)
|
32
37
|
end
|
33
38
|
end
|
34
39
|
end
|
@@ -5,12 +5,12 @@ module Setsumei
|
|
5
5
|
options = options.dup
|
6
6
|
new.tap do |attribute|
|
7
7
|
attribute.name = name
|
8
|
-
options.delete(:
|
9
|
-
attribute.options = options
|
8
|
+
attribute.lookup_key = options.delete(:from_within)
|
9
|
+
attribute.options = options.tap { |o| o.delete :as_a }
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
attr_accessor :name, :options
|
13
|
+
attr_accessor :name, :options, :lookup_key
|
14
14
|
|
15
15
|
def is_an_attribute_of_type?(type)
|
16
16
|
type == :int || type == self.class
|
@@ -29,7 +29,10 @@ module Setsumei
|
|
29
29
|
:"#{name}="
|
30
30
|
end
|
31
31
|
def value_from_hash(hash)
|
32
|
-
value_for hash[
|
32
|
+
value_for hash[ key_for(hash)]
|
33
|
+
end
|
34
|
+
def key_for(hash)
|
35
|
+
lookup_key || Build::Key.for(name, given: hash.keys)
|
33
36
|
end
|
34
37
|
end
|
35
38
|
end
|
@@ -8,11 +8,12 @@ module Setsumei
|
|
8
8
|
new.tap do |attribute|
|
9
9
|
attribute.name = name
|
10
10
|
attribute.klass = options.delete(:as_a)
|
11
|
+
attribute.lookup_key = options.delete(:from_within)
|
11
12
|
attribute.options = options
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
15
|
-
attr_accessor :name, :klass, :options
|
16
|
+
attr_accessor :name, :klass, :options, :lookup_key
|
16
17
|
|
17
18
|
def initialize
|
18
19
|
self.klass = Object
|
@@ -41,7 +42,10 @@ module Setsumei
|
|
41
42
|
:"#{name}="
|
42
43
|
end
|
43
44
|
def value_from_hash(hash)
|
44
|
-
value_for hash[
|
45
|
+
value_for hash[ key_for(hash)]
|
46
|
+
end
|
47
|
+
def key_for(hash)
|
48
|
+
lookup_key || Build::Key.for(name, given: hash.keys)
|
45
49
|
end
|
46
50
|
end
|
47
51
|
end
|
@@ -2,13 +2,15 @@ module Setsumei
|
|
2
2
|
module Describable
|
3
3
|
class StringAttribute
|
4
4
|
def StringAttribute.named(name,options = {})
|
5
|
+
options = options.dup
|
5
6
|
new.tap do |attribute|
|
6
7
|
attribute.name = name
|
7
|
-
attribute.
|
8
|
+
attribute.lookup_key = options.delete(:from_within)
|
9
|
+
attribute.options = options.tap { |o| o.delete :as_a }
|
8
10
|
end
|
9
11
|
end
|
10
12
|
|
11
|
-
attr_accessor :name, :options
|
13
|
+
attr_accessor :name, :options, :lookup_key
|
12
14
|
|
13
15
|
def is_an_attribute_of_type?(type)
|
14
16
|
type == :string || type == self.class
|
@@ -27,7 +29,10 @@ module Setsumei
|
|
27
29
|
:"#{name}="
|
28
30
|
end
|
29
31
|
def value_from_hash(hash)
|
30
|
-
value_for hash[
|
32
|
+
value_for hash[ key_for(hash)]
|
33
|
+
end
|
34
|
+
def key_for(hash)
|
35
|
+
lookup_key || Build::Key.for(name, given: hash.keys)
|
31
36
|
end
|
32
37
|
end
|
33
38
|
end
|
data/lib/setsumei/version.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
shared_examples_for "it handles lookup keys properly" do
|
2
|
+
let(:attribute) { send described_class.to_s.slice(/::([^:]*)$/,1).gsub(/[a-z][A-Z]/) { |s| s[0]+'_'+s[1] }.downcase }
|
3
|
+
context "where a specific key has been specified" do
|
4
|
+
before do
|
5
|
+
hash["MySpecialKey"] = hash.delete key
|
6
|
+
attribute.lookup_key = "MySpecialKey"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should use this key for the hash lookup instead" do
|
10
|
+
Setsumei::Build::Key.should_not_receive(:for)
|
11
|
+
attribute.should_receive(:value_for).with(value_in_hash).and_return(converted_value)
|
12
|
+
subject
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,7 +1,24 @@
|
|
1
1
|
shared_examples_for "it handles options properly" do
|
2
|
+
its(:lookup_key) { should be_nil }
|
2
3
|
its(:options) { should == {} }
|
4
|
+
|
3
5
|
context "when options are specified" do
|
4
6
|
subject { described_class.named name, as_a: described_class.to_s.downcase.gsub(/(.*::|attribute)/,'').to_sym, with_additional: :options }
|
5
7
|
its(:options) { should == { with_additional: :options } }
|
6
8
|
end
|
9
|
+
|
10
|
+
context "when from_within: is specified" do
|
11
|
+
let(:key) { "specialKey" }
|
12
|
+
|
13
|
+
subject { described_class.named name, as_a: described_class.to_s.downcase.gsub(/(.*::|attribute)/,'').to_sym, from_within: key }
|
14
|
+
|
15
|
+
its(:lookup_key) { should == key }
|
16
|
+
|
17
|
+
context "with addition options" do
|
18
|
+
subject { described_class.named name, as_a: described_class.to_s.downcase.gsub(/(.*::|attribute)/,'').to_sym, from_within: key, with_additional: :options }
|
19
|
+
|
20
|
+
its(:lookup_key) { should == key }
|
21
|
+
its(:options) { should == { with_additional: :options } }
|
22
|
+
end
|
23
|
+
end
|
7
24
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: setsumei
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jon Rowe
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-27 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -95,6 +95,7 @@ files:
|
|
95
95
|
- spec/setsumei/describable_spec.rb
|
96
96
|
- spec/spec_helper.rb
|
97
97
|
- spec/support/be_an_attribute_of_type_matcher.rb
|
98
|
+
- spec/support/shared_examples/attribute_lookup_key_support.rb
|
98
99
|
- spec/support/shared_examples/attribute_options.rb
|
99
100
|
- spec/support/shared_examples/attribute_type_creation.rb
|
100
101
|
has_rdoc: true
|
@@ -137,5 +138,6 @@ test_files:
|
|
137
138
|
- spec/setsumei/describable_spec.rb
|
138
139
|
- spec/spec_helper.rb
|
139
140
|
- spec/support/be_an_attribute_of_type_matcher.rb
|
141
|
+
- spec/support/shared_examples/attribute_lookup_key_support.rb
|
140
142
|
- spec/support/shared_examples/attribute_options.rb
|
141
143
|
- spec/support/shared_examples/attribute_type_creation.rb
|