setsumei 0.0.10 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -0
- data/.travis.yml +7 -0
- data/README.md +1 -0
- data/Rakefile +7 -0
- data/lib/setsumei/describable.rb +17 -18
- data/lib/setsumei/describable/attribute.rb +43 -0
- data/lib/setsumei/describable/boolean_attribute.rb +4 -29
- data/lib/setsumei/describable/date_time_attribute.rb +21 -0
- data/lib/setsumei/describable/float_attribute.rb +4 -29
- data/lib/setsumei/describable/int_attribute.rb +4 -28
- data/lib/setsumei/describable/object_attribute.rb +9 -35
- data/lib/setsumei/describable/string_attribute.rb +4 -28
- data/lib/setsumei/version.rb +1 -1
- data/setsumei.gemspec +3 -2
- data/spec/setsumei/describable/attribute_spec.rb +94 -0
- data/spec/setsumei/describable/boolean_attribute_spec.rb +13 -71
- data/spec/setsumei/describable/date_attribute_spec.rb +18 -79
- data/spec/setsumei/describable/float_attribute_spec.rb +8 -69
- data/spec/setsumei/describable/int_attribute_spec.rb +10 -69
- data/spec/setsumei/describable/object_attribute_spec.rb +20 -75
- data/spec/setsumei/describable/string_attribute_spec.rb +7 -66
- data/spec/setsumei/describable/time_attribute_spec.rb +20 -78
- data/spec/setsumei/describable_spec.rb +2 -2
- data/spec/spec_helper.rb +0 -1
- data/spec/support/shared_examples/attribute_options.rb +4 -4
- data/spec/support/shared_examples/attribute_type_creation.rb +1 -1
- metadata +65 -35
- metadata.gz.sig +3 -0
- data/lib/setsumei/describable/date_attribute.rb +0 -40
- data/lib/setsumei/describable/time_attribute.rb +0 -40
- data/spec/support/shared_examples/attribute_lookup_key_support.rb +0 -15
metadata.gz.sig
ADDED
@@ -1,40 +0,0 @@
|
|
1
|
-
module Setsumei
|
2
|
-
module Describable
|
3
|
-
class DateAttribute
|
4
|
-
def DateAttribute.named(name,options = {})
|
5
|
-
options = options.dup
|
6
|
-
new.tap do |attribute|
|
7
|
-
attribute.name = name
|
8
|
-
attribute.format = options.delete(:format) || '%Y-%m-%d'
|
9
|
-
attribute.lookup_key = options.delete(:from_within)
|
10
|
-
attribute.options = options.tap { |o| o.delete :as_a }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
attr_accessor :name, :options, :lookup_key, :format
|
15
|
-
|
16
|
-
def is_an_attribute_of_type?(type)
|
17
|
-
type == :date || type == self.class
|
18
|
-
end
|
19
|
-
|
20
|
-
def value_for(pre_type_cast_value)
|
21
|
-
Date.strptime pre_type_cast_value, format
|
22
|
-
end
|
23
|
-
|
24
|
-
def set_value_on(object, options)
|
25
|
-
object.send accessor, value_from_hash(options[:from_value_in])
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
def accessor
|
30
|
-
:"#{name}="
|
31
|
-
end
|
32
|
-
def value_from_hash(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)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module Setsumei
|
2
|
-
module Describable
|
3
|
-
class TimeAttribute
|
4
|
-
def TimeAttribute.named(name,options = {})
|
5
|
-
options = options.dup
|
6
|
-
new.tap do |attribute|
|
7
|
-
attribute.name = name
|
8
|
-
attribute.format = options.delete(:format) || '%Y-%m-%d %H:%M'
|
9
|
-
attribute.lookup_key = options.delete(:from_within)
|
10
|
-
attribute.options = options.tap { |o| o.delete :as_a }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
attr_accessor :name, :options, :lookup_key, :format
|
15
|
-
|
16
|
-
def is_an_attribute_of_type?(type)
|
17
|
-
type == :time || type == self.class
|
18
|
-
end
|
19
|
-
|
20
|
-
def value_for(pre_type_cast_value)
|
21
|
-
Time.strptime(pre_type_cast_value.to_s,format)
|
22
|
-
end
|
23
|
-
|
24
|
-
def set_value_on(object, options)
|
25
|
-
object.send accessor, value_from_hash(options[:from_value_in])
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
def accessor
|
30
|
-
:"#{name}="
|
31
|
-
end
|
32
|
-
def value_from_hash(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)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,15 +0,0 @@
|
|
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
|