trax_core 0.0.84 → 0.0.85

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +2 -2
  4. data/lib/trax/core/definitions.rb +4 -4
  5. data/lib/trax/core/ext/hash.rb +15 -5
  6. data/lib/trax/core/ext/method.rb +95 -0
  7. data/lib/trax/core/ext/object.rb +7 -2
  8. data/lib/trax/core/fields.rb +4 -0
  9. data/lib/trax/core/has_mixins.rb +5 -1
  10. data/lib/trax/core/transformer.rb +244 -0
  11. data/lib/trax/core/types/boolean.rb +1 -0
  12. data/lib/trax/core/types/enum.rb +7 -8
  13. data/lib/trax/core/types/enum_value.rb +4 -10
  14. data/lib/trax/core/types/json.rb +8 -0
  15. data/lib/trax/core/types/struct.rb +45 -4
  16. data/lib/trax/core/types/value_object.rb +7 -1
  17. data/lib/trax/core.rb +13 -0
  18. data/lib/trax_core/version.rb +1 -1
  19. data/spec/support/defs.rb +29 -1
  20. data/spec/support/storefront/product.rb +2 -0
  21. data/spec/trax/array_spec.rb +2 -6
  22. data/spec/trax/core/definitions_spec.rb +76 -2
  23. data/spec/trax/core/eager_autoload_namespace_spec.rb +4 -4
  24. data/spec/trax/core/errors_spec.rb +10 -15
  25. data/spec/trax/core/ext/array_spec.rb +2 -2
  26. data/spec/trax/core/ext/class_spec.rb +3 -3
  27. data/spec/trax/core/ext/hash_spec.rb +10 -0
  28. data/spec/trax/core/ext/method_spec.rb +104 -0
  29. data/spec/trax/core/ext/module_spec.rb +5 -5
  30. data/spec/trax/core/ext/object_spec.rb +5 -5
  31. data/spec/trax/core/transformer_spec.rb +170 -0
  32. data/spec/trax/core/types/array_spec.rb +4 -4
  33. data/spec/trax/core/types/enum_spec.rb +23 -18
  34. data/spec/trax/core/types/struct_spec.rb +50 -7
  35. data/spec/trax/core/types/value_object_spec.rb +6 -0
  36. data/spec/trax/core_spec.rb +1 -3
  37. data/spec/trax/hash_spec.rb +13 -15
  38. data/trax_core.gemspec +7 -6
  39. metadata +97 -5
  40. data/spec/trax/core/inheritance_spec.rb +0 -0
@@ -12,13 +12,13 @@ describe ::Trax::Core::Types::Enum do
12
12
  end
13
13
 
14
14
  enum :Category do
15
- define :default, 1
16
- define :clothing, 2
17
- define :shoes, 3
18
- define :accessories, 4
15
+ define :default, 1, :display_name => "Default"
16
+ define :clothing, 2, :display_name => "Clothing"
17
+ define :shoes, 3, :display_name => "Shoes"
18
+ define :accessories, 4, :display_name => "Accessories"
19
19
  end
20
20
 
21
- enum :ExtendedCategory, :extend => "MyFakeEnumNamespace::Category" do
21
+ enum :ExtendedCategory, :extends => "MyFakeEnumNamespace::Category" do
22
22
  define :watches, 5
23
23
  define :sunglasses, 6
24
24
  end
@@ -50,31 +50,31 @@ describe ::Trax::Core::Types::Enum do
50
50
  let(:expected_values) { [1,2,3,4] }
51
51
 
52
52
  describe ".key?" do
53
- it { subject.key?(:default).should eq true }
53
+ it { expect(subject.key?(:default)).to eq true }
54
54
  end
55
55
 
56
56
  describe "[](val)" do
57
- it { subject[:default].to_i.should eq 1 }
57
+ it { expect(subject[:default].to_i).to eq 1 }
58
58
  end
59
59
 
60
60
  describe "[](val)" do
61
- it { subject["default"].to_i.should eq 1 }
61
+ it { expect(subject["default"].to_i).to eq 1 }
62
62
  end
63
63
 
64
64
  describe ".value?" do
65
- it { subject.value?(1).should eq true }
65
+ it { expect(subject.value?(1)).to eq true }
66
66
  end
67
67
 
68
68
  describe ".keys" do
69
- it { subject.keys.should eq [:default, :clothing, :shoes, :accessories] }
69
+ it { expect(subject.keys).to eq [:default, :clothing, :shoes, :accessories] }
70
70
  end
71
71
 
72
72
  describe ".names" do
73
- it { subject.keys.should eq expected_names }
73
+ it { expect(subject.keys).to eq expected_names }
74
74
  end
75
75
 
76
76
  describe ".values" do
77
- it { subject.values.should eq expected_values }
77
+ it { expect(subject.values).to eq expected_values }
78
78
  end
79
79
 
80
80
  context "duplicate enum name" do
@@ -91,18 +91,18 @@ describe ::Trax::Core::Types::Enum do
91
91
  end
92
92
  subject { described_object.new(:clothing) }
93
93
 
94
- it { subject.choice.should eq :clothing }
95
- it { subject.choice.should eq 2 }
94
+ it { expect(subject.choice).to eq :clothing }
95
+ it { expect(subject.choice).to eq 2 }
96
96
  it { expect(subject.next_value.to_sym).to eq :shoes }
97
97
  it { expect(subject.previous_value.to_sym).to eq :default }
98
98
 
99
99
  context "selection of values" do
100
- it { subject.select_next_value.should eq described_object.new(:shoes).choice }
100
+ it { expect(subject.select_next_value).to eq described_object.new(:shoes).choice }
101
101
  end
102
102
  context "value is last" do
103
103
  subject { described_object.new(:accessories) }
104
- it { subject.next_value?.should eq false }
105
- it { subject.previous_value?.should eq true }
104
+ it { expect(subject.next_value?).to eq false }
105
+ it { expect(subject.previous_value?).to eq true }
106
106
 
107
107
  context "selection of value" do
108
108
  it { expect(subject.select_next_value).to eq described_object.new(:accessories) }
@@ -125,8 +125,13 @@ describe ::Trax::Core::Types::Enum do
125
125
  let(:described_object) do
126
126
  "::MyFakeEnumNamespace::Category".constantize
127
127
  end
128
-
128
+
129
129
  it { expect(described_object.names).to_not include(:watches)}
130
130
  end
131
131
  end
132
+
133
+ context ".to_schema" do
134
+ subject { "::MyFakeEnumNamespace::Category".constantize.new(2).to_schema }
135
+ it { expect(subject[:attributes][:display_name]).to eq "Clothing" }
136
+ end
132
137
  end
@@ -29,6 +29,7 @@ describe ::Trax::Core::Types::Struct do
29
29
  string :en, :default => ""
30
30
  string :da, :default => ""
31
31
  string :ca, :default => "eh"
32
+ string :fr
32
33
 
33
34
  struct :territories do
34
35
  string :en, :default => "US"
@@ -40,18 +41,15 @@ describe ::Trax::Core::Types::Struct do
40
41
 
41
42
  json :phone_formats
42
43
  json :date_formats, :default => {:en_US => "%m-%d-%y"}
44
+
45
+ set :widgets
43
46
  end
44
47
  end
45
48
  end
46
49
 
47
50
  subject { "::MyFakeStructNamespace::Locale".constantize.new(:en => "something") }
48
51
 
49
- let!(:fake_time1) {
50
- @fake_time1 = ::Time.stub(:now).and_return(::Time.mktime(1970,1,1))
51
- }
52
- let!(:fake_time2) {
53
- @fake_time2 = ::Time.stub(:now).and_return(::Time.mktime(1971,1,1))
54
- }
52
+ let!(:fake_time1) { ::Time.mktime(1970,1,1) }
55
53
 
56
54
  it { expect(subject).to have_key("en") }
57
55
  it { expect(subject.en).to eq "something" }
@@ -138,7 +136,7 @@ describe ::Trax::Core::Types::Struct do
138
136
  context "parsing timestamps" do
139
137
  let(:db_timestamp) { "2015-12-05 15:34:57.701289" }
140
138
  let(:test_subject) { definition.new(:created_at => db_timestamp) }
141
- it { test_subject.created_at.should be_a(::Time) }
139
+ it { expect(test_subject.created_at).to be_a(::Time) }
142
140
  end
143
141
 
144
142
  context "default value" do
@@ -146,4 +144,49 @@ describe ::Trax::Core::Types::Struct do
146
144
  it { expect(subject.last_updated_at).to eq ::Time.mktime(1980,1,1) }
147
145
  end
148
146
  end
147
+
148
+ context "#reverse_merge" do
149
+ subject { "::MyFakeStructNamespace::Locale".constantize.new(:en => "something") }
150
+ let(:other_struct) { "::MyFakeStructNamespace::Locale".constantize.new(:en => "changedvalue", :fr => "somefrench") }
151
+ it {
152
+ expect(subject.fr).to eq nil
153
+ }
154
+
155
+ it {
156
+ expect(subject.fr).to eq nil
157
+ result = subject.reverse_merge(other_struct)
158
+ expect(result.en).to eq "something"
159
+ }
160
+ end
161
+
162
+ context "#reverse_merge_present_values_only!" do
163
+ context "values that do not get overwritten" do
164
+ subject { "::MyFakeStructNamespace::Locale".constantize.new(:en => "something", :is_whatever => false, :widgets => ['one']) }
165
+ let(:other_struct) { "::MyFakeStructNamespace::Locale".constantize.new(:en => "changedvalue", :fr => "somefrench", :is_whatever => true, :widgets => ['two']) }
166
+ it {
167
+ expect(subject.fr).to eq nil
168
+ }
169
+
170
+ it {
171
+ expect(subject.fr).to eq nil
172
+ subject.reverse_merge_present_values_only!(other_struct)
173
+ expect(subject.en).to eq "something"
174
+ expect(subject.fr).to eq "somefrench"
175
+ expect(subject.is_whatever).to eq false
176
+ expect(subject.widgets.first).to eq 'one'
177
+ }
178
+ end
179
+
180
+ context "values which should be overwritten" do
181
+ subject { "::MyFakeStructNamespace::Locale".constantize.new(:en => "", :is_whatever => nil, :widgets => []) }
182
+ let(:other_struct) { "::MyFakeStructNamespace::Locale".constantize.new(:en => "changedvalue", :fr => "somefrench", :is_whatever => true, :widgets => ['two']) }
183
+ it {
184
+ subject.reverse_merge_present_values_only!(other_struct)
185
+ expect(subject.en).to eq "changedvalue"
186
+ expect(subject.fr).to eq "somefrench"
187
+ expect(subject.is_whatever).to eq true
188
+ expect(subject.widgets.first).to eq 'two'
189
+ }
190
+ end
191
+ end
149
192
  end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe ::Trax::Core::Types::ValueObject do
4
+ subject { described_class.new(nil) }
5
+ it{ is_expected.to be_nil }
6
+ end
@@ -1,7 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ::Trax::Core do
4
- it {
5
- expect{ Trax::Core::EagerAutoloadNamespace }.to_not raise_error
6
- }
4
+ it { expect { Trax::Core::EagerAutoloadNamespace }.to_not raise_error }
7
5
  end
@@ -8,10 +8,8 @@ describe ::Hash do
8
8
  ]
9
9
  end
10
10
 
11
- describe "#to_proc" do
12
- it{
13
- subject.map(&{:name => :name, :cost => :price }).map(&[:cost]).sum.should eq 90
14
- }
11
+ describe "#to_transformer" do
12
+ it { expect(subject.map(&{:name => :name, :cost => :price }.to_transformer).map(&[:cost]).sum).to eq 90 }
15
13
 
16
14
  context "single hash" do
17
15
  subject do
@@ -19,8 +17,8 @@ describe ::Hash do
19
17
  end
20
18
 
21
19
  it do
22
- result = subject.tap(&{:cost => :price})
23
- result[:cost].should eq 40
20
+ result = subject.tap(&{:cost => :price}.to_transformer)
21
+ expect(result[:cost]).to eq 40
24
22
  end
25
23
 
26
24
  context "transforming of values" do
@@ -30,9 +28,9 @@ describe ::Hash do
30
28
  result = subject.tap(&{
31
29
  :name => :name,
32
30
  :sale_price => {:price => ->(val){ val / 2 } }
33
- })
31
+ }.to_transformer)
34
32
 
35
- result[:sale_price].should eq 20
33
+ expect(result[:sale_price]).to eq 20
36
34
  end
37
35
  end
38
36
  end
@@ -41,37 +39,37 @@ describe ::Hash do
41
39
  subject { ::OpenStruct.new({:name => "something", :price => 40}) }
42
40
 
43
41
  it do
44
- subject.as!(&{:cost => :price})[:cost].should eq 40
42
+ expect(subject.as!({:cost => :price})[:cost]).to eq 40
45
43
  end
46
44
 
47
45
  context "transforming of values" do
48
46
  let(:original_subject) { ::OpenStruct.new({:name => "something", :price => 40 }) }
49
47
 
50
48
  subject do
51
- original_subject.as!(&{
49
+ original_subject.as!({
52
50
  :name => :name,
53
51
  :sale_price => { :price => ->(val){ val / 2 } }
54
52
  })
55
53
  end
56
54
 
57
55
  it do
58
- subject[:sale_price].should eq 20
56
+ expect(subject[:sale_price]).to eq 20
59
57
  end
60
58
 
61
59
  context "can transform into a new value while reusing value" do
62
60
  subject do
63
- original_subject.as!(&{
61
+ original_subject.as!({
64
62
  :name => :name,
65
63
  :price => :price,
66
64
  :sale_price => { :price => ->(val){ val / 2 } }
67
65
  })
68
66
  end
69
67
 
70
- it { [subject[:sale_price], subject[:price]].should eq [20, 40] }
68
+ it { expect([subject[:sale_price], subject[:price]]).to eq [20, 40] }
71
69
 
72
70
  context "order dependency" do
73
71
  subject do
74
- original_subject.as!(&{
72
+ original_subject.as!({
75
73
  :name => :name,
76
74
  :sale_price => { :price => ->(val){ val / 2 } },
77
75
  :price => :price
@@ -79,7 +77,7 @@ describe ::Hash do
79
77
  end
80
78
 
81
79
  it "should not matter" do
82
- [subject[:sale_price], subject[:price]].should eq [20, 40]
80
+ expect([subject[:sale_price], subject[:price]]).to eq [20, 40]
83
81
  end
84
82
  end
85
83
  end
data/trax_core.gemspec CHANGED
@@ -25,16 +25,17 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_development_dependency "bundler", "~> 1.6"
27
27
  spec.add_development_dependency "rake"
28
- # spec.add_development_dependency "sqlite3"
28
+ spec.add_development_dependency "ruby_dig"
29
+
29
30
  spec.add_development_dependency "rspec"
30
31
  spec.add_development_dependency "rspec-pride"
31
32
  spec.add_development_dependency "pry-nav"
32
33
  spec.add_development_dependency "simplecov"
33
34
  spec.add_development_dependency 'rspec-its', '~> 1'
34
35
  spec.add_development_dependency 'rspec-collection_matchers', '~> 1'
35
- # spec.add_development_dependency 'guard', '~> 2'
36
- # spec.add_development_dependency 'guard-rspec', '~> 4'
37
- # spec.add_development_dependency 'guard-bundler', '~> 2'
38
- # spec.add_development_dependency 'rb-fsevent'
39
- # spec.add_development_dependency 'terminal-notifier-guard'
36
+ spec.add_development_dependency 'guard', '~> 2'
37
+ spec.add_development_dependency 'guard-rspec', '~> 4'
38
+ spec.add_development_dependency 'guard-bundler', '~> 2'
39
+ spec.add_development_dependency 'rb-fsevent'
40
+ spec.add_development_dependency 'terminal-notifier-guard'
40
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trax_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.84
4
+ version: 0.0.85
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Ayre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-02 00:00:00.000000000 Z
11
+ date: 2016-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: ruby_dig
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rspec
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -178,6 +192,76 @@ dependencies:
178
192
  - - "~>"
179
193
  - !ruby/object:Gem::Version
180
194
  version: '1'
195
+ - !ruby/object:Gem::Dependency
196
+ name: guard
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '2'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: '2'
209
+ - !ruby/object:Gem::Dependency
210
+ name: guard-rspec
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: '4'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: '4'
223
+ - !ruby/object:Gem::Dependency
224
+ name: guard-bundler
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: '2'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: '2'
237
+ - !ruby/object:Gem::Dependency
238
+ name: rb-fsevent
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ - !ruby/object:Gem::Dependency
252
+ name: terminal-notifier-guard
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - ">="
263
+ - !ruby/object:Gem::Version
264
+ version: '0'
181
265
  description: Trax core dependencies and utilities
182
266
  email:
183
267
  - jasonayre@gmail.com
@@ -209,6 +293,7 @@ files:
209
293
  - lib/trax/core/ext/enumerable.rb
210
294
  - lib/trax/core/ext/hash.rb
211
295
  - lib/trax/core/ext/is.rb
296
+ - lib/trax/core/ext/method.rb
212
297
  - lib/trax/core/ext/module.rb
213
298
  - lib/trax/core/ext/object.rb
214
299
  - lib/trax/core/ext/string.rb
@@ -228,6 +313,7 @@ files:
228
313
  - lib/trax/core/primitives/enum.rb
229
314
  - lib/trax/core/primitives/enum_value.rb
230
315
  - lib/trax/core/silence_warnings.rb
316
+ - lib/trax/core/transformer.rb
231
317
  - lib/trax/core/types.rb
232
318
  - lib/trax/core/types/array.rb
233
319
  - lib/trax/core/types/array_of.rb
@@ -268,18 +354,21 @@ files:
268
354
  - spec/trax/core/errors_spec.rb
269
355
  - spec/trax/core/ext/array_spec.rb
270
356
  - spec/trax/core/ext/class_spec.rb
357
+ - spec/trax/core/ext/hash_spec.rb
358
+ - spec/trax/core/ext/method_spec.rb
271
359
  - spec/trax/core/ext/module_spec.rb
272
360
  - spec/trax/core/ext/object_spec.rb
273
361
  - spec/trax/core/ext/uri_spec.rb
274
362
  - spec/trax/core/has_dependencies_spec.rb
275
363
  - spec/trax/core/has_mixins_spec.rb
276
- - spec/trax/core/inheritance_spec.rb
277
364
  - spec/trax/core/named_class_spec.rb
278
365
  - spec/trax/core/named_module_spec.rb
279
366
  - spec/trax/core/path_permutations_spec.rb
367
+ - spec/trax/core/transformer_spec.rb
280
368
  - spec/trax/core/types/array_spec.rb
281
369
  - spec/trax/core/types/enum_spec.rb
282
370
  - spec/trax/core/types/struct_spec.rb
371
+ - spec/trax/core/types/value_object_spec.rb
283
372
  - spec/trax/core_spec.rb
284
373
  - spec/trax/hash_spec.rb
285
374
  - trax_core.gemspec
@@ -303,7 +392,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
303
392
  version: '0'
304
393
  requirements: []
305
394
  rubyforge_project:
306
- rubygems_version: 2.4.5
395
+ rubygems_version: 2.5.1
307
396
  signing_key:
308
397
  specification_version: 4
309
398
  summary: Core Trax Dependencies
@@ -330,17 +419,20 @@ test_files:
330
419
  - spec/trax/core/errors_spec.rb
331
420
  - spec/trax/core/ext/array_spec.rb
332
421
  - spec/trax/core/ext/class_spec.rb
422
+ - spec/trax/core/ext/hash_spec.rb
423
+ - spec/trax/core/ext/method_spec.rb
333
424
  - spec/trax/core/ext/module_spec.rb
334
425
  - spec/trax/core/ext/object_spec.rb
335
426
  - spec/trax/core/ext/uri_spec.rb
336
427
  - spec/trax/core/has_dependencies_spec.rb
337
428
  - spec/trax/core/has_mixins_spec.rb
338
- - spec/trax/core/inheritance_spec.rb
339
429
  - spec/trax/core/named_class_spec.rb
340
430
  - spec/trax/core/named_module_spec.rb
341
431
  - spec/trax/core/path_permutations_spec.rb
432
+ - spec/trax/core/transformer_spec.rb
342
433
  - spec/trax/core/types/array_spec.rb
343
434
  - spec/trax/core/types/enum_spec.rb
344
435
  - spec/trax/core/types/struct_spec.rb
436
+ - spec/trax/core/types/value_object_spec.rb
345
437
  - spec/trax/core_spec.rb
346
438
  - spec/trax/hash_spec.rb
File without changes