setsumei 0.0.10 → 0.0.12

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.
Files changed (33) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +1 -0
  4. data/.travis.yml +7 -0
  5. data/README.md +1 -0
  6. data/Rakefile +7 -0
  7. data/lib/setsumei/describable.rb +17 -18
  8. data/lib/setsumei/describable/attribute.rb +43 -0
  9. data/lib/setsumei/describable/boolean_attribute.rb +4 -29
  10. data/lib/setsumei/describable/date_time_attribute.rb +21 -0
  11. data/lib/setsumei/describable/float_attribute.rb +4 -29
  12. data/lib/setsumei/describable/int_attribute.rb +4 -28
  13. data/lib/setsumei/describable/object_attribute.rb +9 -35
  14. data/lib/setsumei/describable/string_attribute.rb +4 -28
  15. data/lib/setsumei/version.rb +1 -1
  16. data/setsumei.gemspec +3 -2
  17. data/spec/setsumei/describable/attribute_spec.rb +94 -0
  18. data/spec/setsumei/describable/boolean_attribute_spec.rb +13 -71
  19. data/spec/setsumei/describable/date_attribute_spec.rb +18 -79
  20. data/spec/setsumei/describable/float_attribute_spec.rb +8 -69
  21. data/spec/setsumei/describable/int_attribute_spec.rb +10 -69
  22. data/spec/setsumei/describable/object_attribute_spec.rb +20 -75
  23. data/spec/setsumei/describable/string_attribute_spec.rb +7 -66
  24. data/spec/setsumei/describable/time_attribute_spec.rb +20 -78
  25. data/spec/setsumei/describable_spec.rb +2 -2
  26. data/spec/spec_helper.rb +0 -1
  27. data/spec/support/shared_examples/attribute_options.rb +4 -4
  28. data/spec/support/shared_examples/attribute_type_creation.rb +1 -1
  29. metadata +65 -35
  30. metadata.gz.sig +3 -0
  31. data/lib/setsumei/describable/date_attribute.rb +0 -40
  32. data/lib/setsumei/describable/time_attribute.rb +0 -40
  33. data/spec/support/shared_examples/attribute_lookup_key_support.rb +0 -15
@@ -0,0 +1,3 @@
1
+ ����6 �a�5?�̑��M��ت�?���OK��}CWO�O��Q=Ql�ٔyS)۰l3�M<�|ŷ,���H�|�b�?2�+�lY��ч�|��ldI�É�o�?נ�{����+�R��� �m� �
2
+ ��sG��ߔ��{3f8���π���E���2���JW p5X��gt� [ɳA�#;��I0���C¼a�@
3
+ �
@@ -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