post_json 1.0.12 → 1.0.13
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/post_json/base.rb +9 -5
- data/lib/post_json/version.rb +1 -1
- data/spec/models/base_spec.rb +4 -1
- data/spec/models/derived_base_spec.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d00197439ef2828a5a9f92f800c029d8a396134
|
4
|
+
data.tar.gz: 59223ff032a986b240b83d0557f53c36aabcf708
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa5492848c38164755418dc96b8c3e13ff97032e8d9d7f0b4f377b2ca72b86a7c381db5a47004cde68abb12c1b4aa8d1f63df90de287549d6bd7fa085c9a2610
|
7
|
+
data.tar.gz: 5d55d2a5331b57b5d12abe3b4cac590765f50ee116bc55db28b313c64f4b1cad11b3e2c49598cea7dca1b8b20182df5997c6f07886ca9991792a543f7b4a907e
|
data/README.md
CHANGED
@@ -141,7 +141,7 @@ puts me.attributes
|
|
141
141
|
|
142
142
|
PostJson will serialize Time and DateTime to format `strftime('%Y-%m-%dT%H:%M:%S.%LZ')` when persisting documents.
|
143
143
|
|
144
|
-
PostJson will also parse an attribute's value to a `
|
144
|
+
PostJson will also parse an attribute's value to a `DateTime` object, if the value is a string and matches the format.
|
145
145
|
|
146
146
|
### Supported methods
|
147
147
|
|
data/lib/post_json/base.rb
CHANGED
@@ -43,7 +43,7 @@ module PostJson
|
|
43
43
|
def cache_key
|
44
44
|
@dashed_name ||= self.class.name.underscore.dasherize
|
45
45
|
__local__unique_version = __doc__version || Digest::MD5.hexdigest(attributes.inspect)
|
46
|
-
"#{@dashed_name}-#{
|
46
|
+
"#{@dashed_name}-#{self[self.class.primary_key]}-version-#{__local__unique_version}"
|
47
47
|
end
|
48
48
|
|
49
49
|
def attributes
|
@@ -58,6 +58,10 @@ module PostJson
|
|
58
58
|
attributes.deep_dup
|
59
59
|
end
|
60
60
|
|
61
|
+
def inspect
|
62
|
+
"#<#{self.class.name} #{attributes.map{ |k, v| "#{k}: #{v.inspect}" }.join(", ")}>"
|
63
|
+
end
|
64
|
+
|
61
65
|
def write_attribute(attribute_name, value)
|
62
66
|
attribute_name = attribute_name.to_s
|
63
67
|
if attribute_name == '__doc__body'
|
@@ -110,7 +114,7 @@ module PostJson
|
|
110
114
|
def __doc__body_convert_attribute_type(attribute_name, value)
|
111
115
|
case value
|
112
116
|
when /^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\.[0-9]{3}Z$/
|
113
|
-
|
117
|
+
DateTime.parse(value)
|
114
118
|
when Hash
|
115
119
|
value.inject(HashWithIndifferentAccess.new) do |result, (key, value)|
|
116
120
|
result[key] = __doc__body_convert_attribute_type("#{attribute_name}.#{key}", value)
|
@@ -314,9 +318,9 @@ module PostJson
|
|
314
318
|
end
|
315
319
|
|
316
320
|
def create_record
|
317
|
-
self.
|
318
|
-
if self.
|
319
|
-
self.
|
321
|
+
write_attribute(self.class.primary_key, self.__doc__body[self.class.primary_key].to_s.strip.downcase)
|
322
|
+
if read_attribute(self.class.primary_key).blank?
|
323
|
+
write_attribute(self.class.primary_key, (self.__doc__body[self.class.primary_key] = SecureRandom.uuid))
|
320
324
|
end
|
321
325
|
|
322
326
|
self.__doc__model_settings_id = self.class.persisted_settings.id
|
data/lib/post_json/version.rb
CHANGED
data/spec/models/base_spec.rb
CHANGED
@@ -438,7 +438,7 @@ describe "Base model" do
|
|
438
438
|
let(:time) { Time.now }
|
439
439
|
let(:time_in_zone) { time.in_time_zone }
|
440
440
|
let(:date_time) { time.to_datetime }
|
441
|
-
let(:time_result) {
|
441
|
+
let(:time_result) { DateTime.parse(time_in_zone.strftime('%Y-%m-%dT%H:%M:%S.%LZ')) }
|
442
442
|
let(:time_hash) { { 'time' => time, 'time_in_zone' => time_in_zone, 'date_time' => date_time } }
|
443
443
|
let(:time_array) { [time, time_in_zone, date_time] }
|
444
444
|
let(:record) { PostJson::Collection["dates"].new(time: time, time_in_zone: time_in_zone, date_time: date_time, time_hash: time_hash, time_array: time_array) }
|
@@ -474,8 +474,11 @@ describe "Base model" do
|
|
474
474
|
end
|
475
475
|
|
476
476
|
its(:time) { should == time_result }
|
477
|
+
its(:time) { should be_a(DateTime) }
|
477
478
|
its(:time_in_zone) { should == time_result }
|
479
|
+
its(:time_in_zone) { should be_a(DateTime) }
|
478
480
|
its(:date_time) { should == time_result }
|
481
|
+
its(:date_time) { should be_a(DateTime) }
|
479
482
|
its(:time_hash) { should == { 'time' => time_result, 'time_in_zone' => time_result, 'date_time' => time_result } }
|
480
483
|
its(:time_array) { should == [time_result]*3 }
|
481
484
|
end
|
@@ -16,4 +16,9 @@ describe "Base model as superclass" do
|
|
16
16
|
subject { ChildModel.create(name: name) }
|
17
17
|
its(:name) { should == name.upcase }
|
18
18
|
end
|
19
|
+
|
20
|
+
context "inspect" do
|
21
|
+
subject { ChildModel.create(number: 1234) }
|
22
|
+
its(:inspect) { should == "#<#{subject.class.name} #{subject.attributes.map{ |k, v| "#{k}: #{v.inspect}" }.join(", ")}>" }
|
23
|
+
end
|
19
24
|
end
|