eapi 0.1.2 → 0.2.0

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.
@@ -4,7 +4,7 @@ RSpec.describe Eapi do
4
4
 
5
5
  context '#to_h' do
6
6
  class MyTestClassToH
7
- include Eapi::Common
7
+ include Eapi::Item
8
8
 
9
9
  property :something, required: true
10
10
  property :other
@@ -6,7 +6,7 @@ RSpec.describe Eapi do
6
6
 
7
7
  context 'type check' do
8
8
  class MyTestTypeKlass
9
- include Eapi::Common
9
+ include Eapi::Item
10
10
  is :one_thing, :other_thing, SomeType
11
11
  end
12
12
 
@@ -84,7 +84,7 @@ RSpec.describe Eapi do
84
84
 
85
85
  context 'using symbol as type' do
86
86
  class MyTestTypeKlassSymbol
87
- include Eapi::Common
87
+ include Eapi::Item
88
88
  is :SomeType
89
89
  end
90
90
 
@@ -6,7 +6,7 @@ RSpec.describe Eapi do
6
6
  describe '#valid?' do
7
7
  it 'true if no validations' do
8
8
  class MyTestClassVal
9
- include Eapi::Common
9
+ include Eapi::Item
10
10
 
11
11
  property :something
12
12
  end
@@ -17,7 +17,7 @@ RSpec.describe Eapi do
17
17
 
18
18
  it 'false if validations not met' do
19
19
  class MyTestClassVal2
20
- include Eapi::Common
20
+ include Eapi::List
21
21
 
22
22
  property :something
23
23
 
@@ -33,7 +33,7 @@ RSpec.describe Eapi do
33
33
 
34
34
  it 'if required, same as validate presence' do
35
35
  class MyTestClassVal3
36
- include Eapi::Common
36
+ include Eapi::List
37
37
 
38
38
  property :something, required: true
39
39
  end
@@ -46,7 +46,7 @@ RSpec.describe Eapi do
46
46
 
47
47
  it 'if validate_with: specified with a class, uses it to validate the property' do
48
48
  class MyTestClassVal4
49
- include Eapi::Common
49
+ include Eapi::List
50
50
 
51
51
  property :something, validate_with: ->(record, attr, value) do
52
52
  record.errors.add(attr, "must pass my custom validation") unless value == :valid_val
@@ -65,7 +65,7 @@ RSpec.describe Eapi do
65
65
 
66
66
  it 'normal ActiveModel::Validations can be used' do
67
67
  class MyTestClassVal5
68
- include Eapi::Common
68
+ include Eapi::List
69
69
 
70
70
  property :something
71
71
 
@@ -92,7 +92,7 @@ RSpec.describe Eapi do
92
92
 
93
93
  describe 'using a class as type' do
94
94
  class MyTestClassValType
95
- include Eapi::Common
95
+ include Eapi::List
96
96
 
97
97
  property :something, type: Hash
98
98
  end
@@ -118,7 +118,7 @@ RSpec.describe Eapi do
118
118
 
119
119
  describe 'using a symbol as type' do
120
120
  class MyTestClassValTypeSymbol
121
- include Eapi::Common
121
+ include Eapi::List
122
122
 
123
123
  property :something, type: :Hash
124
124
  end
@@ -144,7 +144,7 @@ RSpec.describe Eapi do
144
144
 
145
145
  describe 'using a string as type' do
146
146
  class MyTestClassValTypeString
147
- include Eapi::Common
147
+ include Eapi::List
148
148
 
149
149
  property :something, type: 'Hash'
150
150
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Turiño
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-29 00:00:00.000000000 Z
11
+ date: 2014-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: fluent_accessors
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: activesupport
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -182,14 +196,19 @@ files:
182
196
  - lib/eapi.rb
183
197
  - lib/eapi/children.rb
184
198
  - lib/eapi/common.rb
185
- - lib/eapi/definition_runner.rb
199
+ - lib/eapi/definition_runners.rb
200
+ - lib/eapi/definition_runners/list.rb
201
+ - lib/eapi/definition_runners/property.rb
202
+ - lib/eapi/definition_runners/runner.rb
186
203
  - lib/eapi/errors.rb
204
+ - lib/eapi/item.rb
205
+ - lib/eapi/list.rb
187
206
  - lib/eapi/methods.rb
188
207
  - lib/eapi/methods/accessor.rb
189
208
  - lib/eapi/methods/names.rb
190
209
  - lib/eapi/methods/properties.rb
191
210
  - lib/eapi/methods/types.rb
192
- - lib/eapi/multiple.rb
211
+ - lib/eapi/multiple_value.rb
193
212
  - lib/eapi/type_checker.rb
194
213
  - lib/eapi/value_converter.rb
195
214
  - lib/eapi/version.rb
@@ -197,6 +216,7 @@ files:
197
216
  - spec/definition_spec.rb
198
217
  - spec/extension_spec.rb
199
218
  - spec/function_spec.rb
219
+ - spec/list_elements_spec.rb
200
220
  - spec/list_spec.rb
201
221
  - spec/spec_helper.rb
202
222
  - spec/to_h_spec.rb
@@ -232,6 +252,7 @@ test_files:
232
252
  - spec/definition_spec.rb
233
253
  - spec/extension_spec.rb
234
254
  - spec/function_spec.rb
255
+ - spec/list_elements_spec.rb
235
256
  - spec/list_spec.rb
236
257
  - spec/spec_helper.rb
237
258
  - spec/to_h_spec.rb
@@ -1,109 +0,0 @@
1
- module Eapi
2
- class DefinitionRunner < Struct.new(:klass, :field, :definition)
3
- def run
4
- run_multiple_accessor
5
- run_init
6
- run_validations
7
- end
8
-
9
- private
10
- def run_validations
11
- run_required
12
- run_validate_type
13
- run_validate_with
14
- run_validate_element_type
15
- run_validate_element_with
16
- end
17
-
18
- def run_validate_type
19
- if type
20
- klass.send :validates_each, field do |record, attr, value|
21
- unless Eapi::TypeChecker.new(type).is_valid_type?(value)
22
- record.errors.add(attr, "must be a #{type}")
23
- end
24
- end
25
- end
26
- end
27
-
28
- def run_validate_element_with
29
- if multiple && validate_element_with
30
- klass.send :validates_each, field do |record, attr, value|
31
- if value.respond_to?(:each)
32
- value.each do |v|
33
- validate_element_with.call(record, attr, v)
34
- end
35
- end
36
- end
37
- end
38
- end
39
-
40
- def run_validate_element_type
41
- if multiple && element_type
42
- klass.send :validates_each, field do |record, attr, value|
43
- if value.respond_to?(:each)
44
- value.each do |v|
45
- record.errors.add(attr, "element must be a #{element_type}") unless v.kind_of?(element_type)
46
- end
47
- end
48
- end
49
- end
50
- end
51
-
52
- def run_validate_with
53
- if validate_with
54
- klass.send :validates_each, field do |record, attr, value|
55
- validate_with.call(record, attr, value)
56
- end
57
- end
58
- end
59
-
60
- def run_required
61
- if required
62
- klass.send :validates_presence_of, field
63
- end
64
- end
65
-
66
- def run_init
67
- if type || multiple
68
- klass.send :define_init, field, type || Array
69
- end
70
- end
71
-
72
- def run_multiple_accessor
73
- if multiple
74
- klass.send :define_multiple_accessor, field
75
- end
76
- end
77
-
78
- def type_multiple?(type)
79
- return false if type.nil?
80
- return true if type == Array || type == Set
81
-
82
- type.respond_to?(:is_multiple?) && type.is_multiple?
83
- end
84
-
85
- def validate_element_with
86
- definition.fetch(:validate_element_with, nil)
87
- end
88
-
89
- def multiple
90
- definition.fetch(:multiple, false) || type_multiple?(type)
91
- end
92
-
93
- def required
94
- definition.fetch(:required, false)
95
- end
96
-
97
- def validate_with
98
- definition.fetch(:validate_with, nil)
99
- end
100
-
101
- def element_type
102
- definition.fetch(:element_type, nil)
103
- end
104
-
105
- def type
106
- definition.fetch(:type, nil)
107
- end
108
- end
109
- end