setsumei 0.0.10 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -3,23 +3,19 @@ require 'spec_helper'
3
3
  module Setsumei
4
4
  module Describable
5
5
  describe StringAttribute do
6
- its(:name) { should == nil }
7
6
 
8
- describe ".named(name)" do
9
- let(:name) { :my_string_field }
7
+ describe "#== other" do
8
+ subject { StringAttribute.new }
10
9
 
11
- subject { StringAttribute.named(name) }
12
-
13
- it { should be_a StringAttribute }
14
- its(:name) { should == name }
15
-
16
- it_should_behave_like "it handles options properly"
10
+ it { should == :string }
11
+ it { should == StringAttribute }
12
+ it { should_not eq double }
17
13
  end
18
14
 
19
- describe "#value_for(pre_type_cast_value)" do
15
+ describe "#cast value" do
20
16
  let(:string_attribute) { StringAttribute.new }
21
17
 
22
- subject { string_attribute.value_for pre_type_cast_value }
18
+ subject { string_attribute.cast pre_type_cast_value }
23
19
 
24
20
  context "where the value is a string" do
25
21
  let(:pre_type_cast_value) { "I'm already a string" }
@@ -35,61 +31,6 @@ module Setsumei
35
31
  end
36
32
  end
37
33
 
38
- describe "#is_an_attribute_of_type?" do
39
- let(:string_attribute) { StringAttribute.new }
40
-
41
- subject { string_attribute.is_an_attribute_of_type? type }
42
-
43
- context "where type is :string" do
44
- let(:type) { :string }
45
- it { should be_true }
46
- end
47
-
48
- context "where type is StringAttribute" do
49
- let(:type) { StringAttribute }
50
- it { should be_true }
51
- end
52
-
53
- context "where type is unknown" do
54
- let(:type) { mock "an unknown type" }
55
- it { should be_false }
56
- end
57
- end
58
-
59
- describe "set_value_on object, from_value_in: hash" do
60
- let(:hash) { Hash.new }
61
- let(:key) { "key" }
62
- let(:hash_keys) { mock "hash_keys" }
63
- let(:value_in_hash) { mock "value_in_hash" }
64
- let(:converted_value) { mock "converted_value" }
65
-
66
- let(:object) { mock "object", :my_string_attribute= => nil }
67
-
68
- let(:string_attribute) { StringAttribute.named :my_string_attribute }
69
-
70
- before do
71
- Build::Key.stub(:for).and_return(key)
72
- hash[key] = value_in_hash
73
- string_attribute.stub(:value_for).and_return(converted_value)
74
- end
75
-
76
- subject { string_attribute.set_value_on object, from_value_in: hash }
77
-
78
- it "should detect the key it should use to retrieve the value from the hash" do
79
- hash.should_receive(:keys).and_return(hash_keys)
80
- Build::Key.should_receive(:for).with(:my_string_attribute, given: hash_keys ).and_return(key)
81
- subject
82
- end
83
- it "should convert the value" do
84
- string_attribute.should_receive(:value_for).with(value_in_hash).and_return(converted_value)
85
- subject
86
- end
87
- it "should pass object a value to the attribute described by this class" do
88
- object.should_receive(:my_string_attribute=).with(converted_value)
89
- subject
90
- end
91
- it_should_behave_like "it handles lookup keys properly"
92
- end
93
34
  end
94
35
  end
95
36
  end
@@ -2,100 +2,42 @@ require 'spec_helper'
2
2
 
3
3
  module Setsumei
4
4
  module Describable
5
- describe TimeAttribute do
6
- its(:name) { should == nil }
5
+ describe DateTimeAttribute do
7
6
 
8
- describe ".named(name)" do
9
- let(:name) { :my_time_field }
10
-
11
- subject { TimeAttribute.named(name) }
12
-
13
- it { should be_a TimeAttribute }
14
- its(:name) { should == name }
15
- its(:format) { should == '%Y-%m-%d %H:%M' }
16
-
17
- context 'format specified' do
18
- let(:format) { mock "format" }
19
-
20
- subject { TimeAttribute.named name, format: format }
7
+ describe "#initialize(format)" do
8
+ it 'will default to %Y-%m-%d %H:%M' do
9
+ DateTimeAttribute.new(:time, nil, Time).format.should == '%Y-%m-%d %H:%M'
10
+ end
21
11
 
22
- its(:format) { should == format }
12
+ it 'is configurable' do
13
+ format = double
14
+ DateTimeAttribute.new(:time, format, Time).format.should == format
23
15
  end
16
+ end
17
+
18
+ describe "#== other" do
19
+ subject { DateTimeAttribute.new :time, '%Y-%m-%d %H:%M', Time }
24
20
 
25
- it_should_behave_like "it handles options properly"
21
+ it { should == :time }
22
+ it { should == DateTimeAttribute }
23
+ it { should_not eq double }
26
24
  end
27
25
 
28
- describe "#value_for(pre_type_cast_value)" do
29
- let(:attribute) { TimeAttribute.new }
26
+ describe "#cast value" do
27
+ let(:attribute) { DateTimeAttribute.new :time, '%Y-%m-%d %H:%M', Time }
30
28
 
31
- subject { attribute.value_for pre_type_cast_value }
29
+ subject { attribute.cast value }
32
30
 
33
31
  context "where pre_type_cast_value is a string" do
34
- let(:pre_type_cast_value) { "time" }
32
+ let(:value) { "time" }
35
33
  let(:formatted_value) { mock "formatted_value" }
36
34
 
37
35
  it "should parse it into a time with format" do
38
- Time.should_receive(:strptime).with(pre_type_cast_value,attribute.format).and_return(formatted_value)
36
+ Time.should_receive(:strptime).with(value, '%Y-%m-%d %H:%M').and_return(formatted_value)
39
37
  subject.should == formatted_value
40
38
  end
41
39
  end
42
40
  end
43
-
44
- describe "#is_an_attribute_of_type?" do
45
- let(:attribute) { TimeAttribute.new }
46
-
47
- subject { attribute.is_an_attribute_of_type? type }
48
-
49
- context "where type is :time" do
50
- let(:type) { :time }
51
- it { should be_true }
52
- end
53
-
54
- context "where type is TimeAttribute" do
55
- let(:type) { TimeAttribute }
56
- it { should be_true }
57
- end
58
-
59
- context "where type is unknown" do
60
- let(:type) { mock "an unknown type" }
61
- it { should be_false }
62
- end
63
- end
64
-
65
- describe "set_value_on object, from_value_in: hash" do
66
- let(:hash) { Hash.new }
67
- let(:key) { "key" }
68
- let(:hash_keys) { mock "hash_keys" }
69
- let(:value_in_hash) { mock "value_in_hash" }
70
- let(:converted_value) { mock "converted_value" }
71
-
72
- let(:object) { mock "object", :my_time_attribute= => nil }
73
-
74
- let(:time_attribute) { TimeAttribute.named :my_time_attribute }
75
-
76
- before do
77
- Build::Key.stub(:for).and_return(key)
78
- hash[key] = value_in_hash
79
- time_attribute.stub(:value_for).and_return(converted_value)
80
- end
81
-
82
- subject { time_attribute.set_value_on object, from_value_in: hash }
83
-
84
- it "should detect the key it should use to retrieve the value from the hash" do
85
- hash.should_receive(:keys).and_return(hash_keys)
86
- Build::Key.should_receive(:for).with(:my_time_attribute, given: hash_keys ).and_return(key)
87
- subject
88
- end
89
- it "should convert the value" do
90
- time_attribute.should_receive(:value_for).with(value_in_hash).and_return(converted_value)
91
- subject
92
- end
93
- it "should pass object a value to the attribute described by this class" do
94
- object.should_receive(:my_time_attribute=).with(converted_value)
95
- subject
96
- end
97
- it_should_behave_like "it handles lookup keys properly"
98
- end
99
41
  end
100
42
  end
101
43
  end
@@ -47,8 +47,8 @@ module Setsumei
47
47
  it_should_behave_like "it creates an attribute of type", :string, creating_a: Describable::StringAttribute
48
48
  it_should_behave_like "it creates an attribute of type", :float, creating_a: Describable::FloatAttribute
49
49
  it_should_behave_like "it creates an attribute of type", :int, creating_a: Describable::IntAttribute
50
- it_should_behave_like "it creates an attribute of type", :date, creating_a: Describable::DateAttribute
51
- it_should_behave_like "it creates an attribute of type", :time, creating_a: Describable::TimeAttribute
50
+ it_should_behave_like "it creates an attribute of type", :date, creating_a: Describable::DateTimeAttribute
51
+ it_should_behave_like "it creates an attribute of type", :time, creating_a: Describable::DateTimeAttribute
52
52
 
53
53
  it_should_behave_like "it creates an attribute of type", Class.new, creating_a: Describable::ObjectAttribute
54
54
  end
@@ -1,4 +1,3 @@
1
- require 'ruby-debug'
2
1
  require 'setsumei'
3
2
 
4
3
  Dir[File.join(File.dirname(__FILE__),"support/**/*.rb")].each { |f| require f }
@@ -1,10 +1,10 @@
1
- shared_examples_for "it handles options properly" do
1
+ shared_examples_for "it handles options properly" do |extras = {}|
2
2
  its(:lookup_key) { should be_nil }
3
- its(:options) { should == {} }
3
+ its(:options) { should == {}.merge(extras) }
4
4
 
5
5
  context "when options are specified" do
6
6
  subject { described_class.named name, as_a: described_class.to_s.downcase.gsub(/(.*::|attribute)/,'').to_sym, with_additional: :options }
7
- its(:options) { should == { with_additional: :options } }
7
+ its(:options) { should == { with_additional: :options }.merge(extras) }
8
8
  end
9
9
 
10
10
  context "when from_within: is specified" do
@@ -18,7 +18,7 @@ shared_examples_for "it handles options properly" do
18
18
  subject { described_class.named name, as_a: described_class.to_s.downcase.gsub(/(.*::|attribute)/,'').to_sym, from_within: key, with_additional: :options }
19
19
 
20
20
  its(:lookup_key) { should == key }
21
- its(:options) { should == { with_additional: :options } }
21
+ its(:options) { should == { with_additional: :options }.merge(extras) }
22
22
  end
23
23
  end
24
24
  end
@@ -12,7 +12,7 @@ shared_examples "it creates an attribute of type" do |_type,options|
12
12
  context "where options are specified" do
13
13
  it "should set the options upon the attribute" do
14
14
  subject.define :field, as_a: _type, with: :options
15
- subject.defined_attributes[:field].options.should == { with: :options }
15
+ subject.defined_attributes[:field].options.should == { with: :options }.merge(options.fetch(:extra_options,{}))
16
16
  end
17
17
  end
18
18
  end
metadata CHANGED
@@ -1,61 +1,92 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: setsumei
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
5
- prerelease:
4
+ version: 0.0.12
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jon Rowe
9
8
  autorequire:
10
9
  bindir: bin
11
- cert_chain: []
12
- date: 2011-07-18 00:00:00.000000000 +01:00
13
- default_executable:
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDVjCCAj6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBRMQ4wDAYDVQQDDAVoZWxs
14
+ bzEXMBUGCgmSJomT8ixkARkWB2pvbnJvd2UxEjAQBgoJkiaJk/IsZAEZFgJjbzES
15
+ MBAGCgmSJomT8ixkARkWAnVrMB4XDTEzMDIwMzA4MTgwNloXDTE0MDIwMzA4MTgw
16
+ NlowUTEOMAwGA1UEAwwFaGVsbG8xFzAVBgoJkiaJk/IsZAEZFgdqb25yb3dlMRIw
17
+ EAYKCZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJ1azCCASIwDQYJKoZI
18
+ hvcNAQEBBQADggEPADCCAQoCggEBAMhs6ng/SRrYfG7RtQx8liJTZs8tpz7PBnlH
19
+ qyOwuU0weJc7nh6C9C8LGyJzpkbjJJo1rfTMg7huDyL14Py82dfMDomApif8jNNI
20
+ 8KtviAgB1DrWq0fCDLtu/M77+yuVV3OhDdrAFaBkT/euvdJ8cAKrLxbJ+klgvrcB
21
+ FK+c4PUV3/zBKghe0l7FuDhyQCsuLNDbWyFvDS97tPjeN6yWuszwg22vZMDdsuzN
22
+ Cj3M4LLSkbrt+AOUcysEJxI4t6uv2U1bRzHsDfAF0RI/Q7OMtUr+Dtz/2YJ47KKs
23
+ 51ZRjLLGHd10XrIfFSfGyJj1dMbDgLsEBj1sFH4e6dy7gau8TaUCAwEAAaM5MDcw
24
+ CQYDVR0TBAIwADAdBgNVHQ4EFgQULu5JH2g7RAjoXaZt+fbrfNDI9IkwCwYDVR0P
25
+ BAQDAgSwMA0GCSqGSIb3DQEBBQUAA4IBAQAf5A4kB769DPKGjPZ++v42FwVi7X7v
26
+ RpufPs6R4YHyzHXaJmAqnhleZhVJijBgsdb2SigNRbg+IK8XYHg7jkonMgO8OS3D
27
+ C6w8VB5bI0PqyDOwCGcQkYHYlZZWCghAyBTSBowHAekMb9V3QjJtJ8XkizjshETO
28
+ ZCVI2AObjlJi8I10aK2tSo9sv2riCKZ92BVSM13zYWn+C/eCP/m9BDiw37UQtuQq
29
+ 2feWfO4gCNmvfFjULOAYHq9JHEjN5SLSXvj5HdSnDcCyIfJKn5Ya3JahWQaWIsXf
30
+ /NPE/mB57TOwj+d7XUa2NC4HUadF8R51IYEcIB0PpIEzJlKtfXFcOZxO
31
+ -----END CERTIFICATE-----
32
+ date: 2013-07-16 00:00:00.000000000 Z
14
33
  dependencies:
15
34
  - !ruby/object:Gem::Dependency
16
35
  name: json
17
- requirement: &2161615340 !ruby/object:Gem::Requirement
18
- none: false
36
+ requirement: !ruby/object:Gem::Requirement
19
37
  requirements:
20
- - - ! '>='
38
+ - - '>='
21
39
  - !ruby/object:Gem::Version
22
40
  version: '0'
23
41
  type: :runtime
24
42
  prerelease: false
25
- version_requirements: *2161615340
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
26
48
  - !ruby/object:Gem::Dependency
27
- name: rspec
28
- requirement: &2161614920 !ruby/object:Gem::Requirement
29
- none: false
49
+ name: rake
50
+ requirement: !ruby/object:Gem::Requirement
30
51
  requirements:
31
- - - ! '>='
52
+ - - '>='
32
53
  - !ruby/object:Gem::Version
33
54
  version: '0'
34
55
  type: :development
35
56
  prerelease: false
36
- version_requirements: *2161614920
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
37
62
  - !ruby/object:Gem::Dependency
38
- name: autotest-standalone
39
- requirement: &2161614500 !ruby/object:Gem::Requirement
40
- none: false
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
41
65
  requirements:
42
- - - ! '>='
66
+ - - '>='
43
67
  - !ruby/object:Gem::Version
44
68
  version: '0'
45
69
  type: :development
46
70
  prerelease: false
47
- version_requirements: *2161614500
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
48
76
  - !ruby/object:Gem::Dependency
49
- name: ruby-debug19
50
- requirement: &2161614080 !ruby/object:Gem::Requirement
51
- none: false
77
+ name: autotest-standalone
78
+ requirement: !ruby/object:Gem::Requirement
52
79
  requirements:
53
- - - ! '>='
80
+ - - '>='
54
81
  - !ruby/object:Gem::Version
55
82
  version: '0'
56
83
  type: :development
57
84
  prerelease: false
58
- version_requirements: *2161614080
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
59
90
  description: A tool for describing API's as ruby objects. Currently supports building
60
91
  these objects from JSON
61
92
  email:
@@ -66,6 +97,7 @@ extra_rdoc_files: []
66
97
  files:
67
98
  - .gitignore
68
99
  - .rspec
100
+ - .travis.yml
69
101
  - Gemfile
70
102
  - README.md
71
103
  - Rakefile
@@ -73,18 +105,19 @@ files:
73
105
  - lib/setsumei/build.rb
74
106
  - lib/setsumei/build/key.rb
75
107
  - lib/setsumei/describable.rb
108
+ - lib/setsumei/describable/attribute.rb
76
109
  - lib/setsumei/describable/boolean_attribute.rb
77
110
  - lib/setsumei/describable/collection.rb
78
- - lib/setsumei/describable/date_attribute.rb
111
+ - lib/setsumei/describable/date_time_attribute.rb
79
112
  - lib/setsumei/describable/float_attribute.rb
80
113
  - lib/setsumei/describable/int_attribute.rb
81
114
  - lib/setsumei/describable/object_attribute.rb
82
115
  - lib/setsumei/describable/string_attribute.rb
83
- - lib/setsumei/describable/time_attribute.rb
84
116
  - lib/setsumei/version.rb
85
117
  - setsumei.gemspec
86
118
  - spec/setsumei/build/key_spec.rb
87
119
  - spec/setsumei/build_spec.rb
120
+ - spec/setsumei/describable/attribute_spec.rb
88
121
  - spec/setsumei/describable/boolean_attribute_spec.rb
89
122
  - spec/setsumei/describable/collection_spec.rb
90
123
  - spec/setsumei/describable/date_attribute_spec.rb
@@ -96,37 +129,35 @@ files:
96
129
  - spec/setsumei/describable_spec.rb
97
130
  - spec/spec_helper.rb
98
131
  - spec/support/be_an_attribute_of_type_matcher.rb
99
- - spec/support/shared_examples/attribute_lookup_key_support.rb
100
132
  - spec/support/shared_examples/attribute_options.rb
101
133
  - spec/support/shared_examples/attribute_type_creation.rb
102
- has_rdoc: true
103
134
  homepage: https://github.com/JonRowe/setsumei
104
135
  licenses: []
136
+ metadata: {}
105
137
  post_install_message:
106
138
  rdoc_options: []
107
139
  require_paths:
108
140
  - lib
109
141
  required_ruby_version: !ruby/object:Gem::Requirement
110
- none: false
111
142
  requirements:
112
- - - ! '>='
143
+ - - '>='
113
144
  - !ruby/object:Gem::Version
114
145
  version: '0'
115
146
  required_rubygems_version: !ruby/object:Gem::Requirement
116
- none: false
117
147
  requirements:
118
- - - ! '>='
148
+ - - '>='
119
149
  - !ruby/object:Gem::Version
120
150
  version: '0'
121
151
  requirements: []
122
152
  rubyforge_project:
123
- rubygems_version: 1.6.2
153
+ rubygems_version: 2.0.3
124
154
  signing_key:
125
- specification_version: 3
155
+ specification_version: 4
126
156
  summary: A tool for describing API's as ruby objects
127
157
  test_files:
128
158
  - spec/setsumei/build/key_spec.rb
129
159
  - spec/setsumei/build_spec.rb
160
+ - spec/setsumei/describable/attribute_spec.rb
130
161
  - spec/setsumei/describable/boolean_attribute_spec.rb
131
162
  - spec/setsumei/describable/collection_spec.rb
132
163
  - spec/setsumei/describable/date_attribute_spec.rb
@@ -138,6 +169,5 @@ test_files:
138
169
  - spec/setsumei/describable_spec.rb
139
170
  - spec/spec_helper.rb
140
171
  - spec/support/be_an_attribute_of_type_matcher.rb
141
- - spec/support/shared_examples/attribute_lookup_key_support.rb
142
172
  - spec/support/shared_examples/attribute_options.rb
143
173
  - spec/support/shared_examples/attribute_type_creation.rb