trax_core 0.0.83 → 0.0.84
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/lib/trax/core/types.rb +1 -0
- data/lib/trax/core/types/boolean.rb +5 -0
- data/lib/trax/core/types/set.rb +15 -0
- data/lib/trax/core/types/struct.rb +21 -1
- data/lib/trax/core/types/value_object.rb +8 -0
- data/lib/trax_core/version.rb +1 -1
- data/spec/trax/core/types/array_spec.rb +13 -0
- data/spec/trax/core/types/struct_spec.rb +34 -1
- data/trax_core.gemspec +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc61a40b6e173df7ff14e66550fd7c5fa558ab4c
|
4
|
+
data.tar.gz: 9b5f6b14a3b4c714b094f8020b66f3d532a79855
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18b3e5d1d9dc44a315bc88480c76b68ecb81a00d07dd41d14b831040ea3e62c7c696477ba9965c34f449a5f168aa35529f94ef3619f7ef2ebc99af8a5457bab7
|
7
|
+
data.tar.gz: 1013d42d2b1900af67bd2e46edf65c0e28a59c301c400ae60423d945acf7d06ae2656b260a95d5baec813671323b50adabcfefb4438fd40102be00f349e47a47
|
data/Gemfile
CHANGED
@@ -3,6 +3,10 @@ source 'https://rubygems.org'
|
|
3
3
|
# Specify your gem's dependencies in trax_core.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
+
# gem 'hashie', :github => "intridea/hashie"
|
7
|
+
#pointing at branch until default value procs for dash is merged
|
8
|
+
gem 'hashie', :github => "jasonayre/hashie"
|
9
|
+
|
6
10
|
group :development do
|
7
11
|
gem 'guard-bundler'
|
8
12
|
end
|
data/lib/trax/core/types.rb
CHANGED
@@ -22,6 +22,7 @@ module Trax
|
|
22
22
|
:float => 0.0,
|
23
23
|
:integer => nil,
|
24
24
|
:json => {},
|
25
|
+
:set => [],
|
25
26
|
:string => "",
|
26
27
|
:struct => {},
|
27
28
|
:time => nil
|
@@ -70,6 +71,10 @@ module Trax
|
|
70
71
|
define_attribute_class_for_type(:json, name, *args, **options, &block)
|
71
72
|
end
|
72
73
|
|
74
|
+
def self.set_property(name, *args, **options, &block)
|
75
|
+
define_attribute_class_for_type(:set, name, *args, :coerce => true, **options, &block)
|
76
|
+
end
|
77
|
+
|
73
78
|
def self.string_property(name, *args, **options, &block)
|
74
79
|
define_attribute_class_for_type(:string, name, *args, :coerce => ::String, **options, &block)
|
75
80
|
end
|
@@ -79,7 +84,20 @@ module Trax
|
|
79
84
|
end
|
80
85
|
|
81
86
|
def self.time_property(name, *args, **options, &block)
|
82
|
-
define_attribute_class_for_type(:time, name, *args, :coerce => ->(value){
|
87
|
+
define_attribute_class_for_type(:time, name, *args, :coerce => ->(value){
|
88
|
+
result = if value
|
89
|
+
case value
|
90
|
+
when ::String
|
91
|
+
::Time.parse(value)
|
92
|
+
when ::Time
|
93
|
+
value
|
94
|
+
when ::Proc
|
95
|
+
value.call
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
result
|
100
|
+
}, **options, &block)
|
83
101
|
end
|
84
102
|
|
85
103
|
def self.to_schema
|
@@ -110,6 +128,7 @@ module Trax
|
|
110
128
|
alias :float :float_property
|
111
129
|
alias :integer :integer_property
|
112
130
|
alias :json :json_property
|
131
|
+
alias :set :set_property
|
113
132
|
alias :string :string_property
|
114
133
|
alias :struct :struct_property
|
115
134
|
alias :time :time_property
|
@@ -136,6 +155,7 @@ module Trax
|
|
136
155
|
end
|
137
156
|
|
138
157
|
options[:default] = options.key?(:default) ? options[:default] : DEFAULT_VALUES_FOR_PROPERTY_TYPES[type_name]
|
158
|
+
|
139
159
|
property(property_name.to_sym, *args, **options)
|
140
160
|
|
141
161
|
if coerce.is_a?(::Proc)
|
data/lib/trax_core/version.rb
CHANGED
@@ -17,6 +17,19 @@ describe ::Trax::Core::Types::Array do
|
|
17
17
|
let(:test_subject) { subject.new({:width => 1}) }
|
18
18
|
it { test_subject[0].width.should eq 1 }
|
19
19
|
it { test_subject[0].height.should eq 0 }
|
20
|
+
|
21
|
+
context "does not duplicate values" do
|
22
|
+
it {
|
23
|
+
test_subject << {:width => 2, :height => 2}
|
24
|
+
expect(test_subject.length).to eq 2
|
25
|
+
}
|
26
|
+
|
27
|
+
it {
|
28
|
+
test_subject << {}
|
29
|
+
test_subject << {}
|
30
|
+
expect(test_subject.last.width).to eq 0
|
31
|
+
}
|
32
|
+
end
|
20
33
|
end
|
21
34
|
|
22
35
|
context "ArrayOf" do
|
@@ -16,6 +16,13 @@ describe ::Trax::Core::Types::Struct do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
time :created_at
|
19
|
+
time :last_updated_at, :default => lambda{|record| ::Time.mktime(1980,1,1) }
|
20
|
+
|
21
|
+
float :latitude, :default => 1.0
|
22
|
+
float :longitude, :default => 5.0
|
23
|
+
|
24
|
+
set :place_ids
|
25
|
+
set :lat_long_with_sum, :default => lambda{|record| [ record.latitude, record.longitude, (record.latitude + record.longitude) ] }
|
19
26
|
end
|
20
27
|
|
21
28
|
struct :Locale do
|
@@ -85,6 +92,27 @@ describe ::Trax::Core::Types::Struct do
|
|
85
92
|
end
|
86
93
|
end
|
87
94
|
|
95
|
+
context "with set property" do
|
96
|
+
let(:definition) { "::MyFakeStructNamespace::Location".constantize.new(:place_ids => [1, 2]) }
|
97
|
+
|
98
|
+
subject { definition }
|
99
|
+
it { expect(definition.place_ids.first).to eq(1) }
|
100
|
+
|
101
|
+
context "behaves like a set" do
|
102
|
+
it {
|
103
|
+
subject.place_ids << 1
|
104
|
+
subject.place_ids << 1
|
105
|
+
expect(subject.place_ids.length).to eq 2
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
context "default value" do
|
110
|
+
it {
|
111
|
+
expect(subject.lat_long_with_sum).to eq [1.0, 5.0, 6.0].to_set
|
112
|
+
}
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
88
116
|
context "with boolean property" do
|
89
117
|
let(:definition) { "::MyFakeStructNamespace::Locale".constantize }
|
90
118
|
subject { definition.new(:is_whatever => false) }
|
@@ -107,10 +135,15 @@ describe ::Trax::Core::Types::Struct do
|
|
107
135
|
subject { definition.new(:created_at => fake_time1) }
|
108
136
|
it { expect(subject.created_at).to eq fake_time1 }
|
109
137
|
|
110
|
-
context do
|
138
|
+
context "parsing timestamps" do
|
111
139
|
let(:db_timestamp) { "2015-12-05 15:34:57.701289" }
|
112
140
|
let(:test_subject) { definition.new(:created_at => db_timestamp) }
|
113
141
|
it { test_subject.created_at.should be_a(::Time) }
|
114
142
|
end
|
143
|
+
|
144
|
+
context "default value" do
|
145
|
+
subject{ definition.new }
|
146
|
+
it { expect(subject.last_updated_at).to eq ::Time.mktime(1980,1,1) }
|
147
|
+
end
|
115
148
|
end
|
116
149
|
end
|
data/trax_core.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "hashie"
|
21
|
+
spec.add_dependency "hashie", '~>3.4.4'
|
22
22
|
spec.add_dependency "activesupport"
|
23
23
|
spec.add_dependency "activemodel"
|
24
24
|
spec.add_dependency "wannabe_bool"
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trax_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.84
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Ayre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.4.4
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.4.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -239,6 +239,7 @@ files:
|
|
239
239
|
- lib/trax/core/types/float.rb
|
240
240
|
- lib/trax/core/types/integer.rb
|
241
241
|
- lib/trax/core/types/json.rb
|
242
|
+
- lib/trax/core/types/set.rb
|
242
243
|
- lib/trax/core/types/string.rb
|
243
244
|
- lib/trax/core/types/struct.rb
|
244
245
|
- lib/trax/core/types/time.rb
|