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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 52a70dfcec7f3478c9b2fab7e465c5b33c97229b
4
- data.tar.gz: 7d302f9d087bc00360e203320e0afd5b64e3eb1d
3
+ metadata.gz: 9d00197439ef2828a5a9f92f800c029d8a396134
4
+ data.tar.gz: 59223ff032a986b240b83d0557f53c36aabcf708
5
5
  SHA512:
6
- metadata.gz: b17682fa4780f53680fc7c7c55bb423974208d79356ba6ec70a9ab2ebc16ce9c83a7cc60b6101b71b507797434d84ef33cf9c818b40bbeed268c4b7045d69782
7
- data.tar.gz: 99bbe826b5aab7659aaa74fa2e8413023b398940b4bf50aa98ed540989d339a2488c9e7300fb0af0c35cebcbcb4c37dc7d54d7180f41c5f4509e486ce476d4b2
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 `Time` object, if the value is a string and matches the format.
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
 
@@ -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}-#{id}-version-#{__local__unique_version}"
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
- Time.zone.parse(value)
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.id = self.__doc__body['id'].to_s.strip.downcase
318
- if self.id.blank?
319
- self.id = self.__doc__body['id'] = SecureRandom.uuid
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
@@ -1,3 +1,3 @@
1
1
  module PostJson
2
- VERSION = "1.0.12"
2
+ VERSION = "1.0.13"
3
3
  end
@@ -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) { Time.parse(time_in_zone.strftime('%Y-%m-%dT%H:%M:%S.%LZ')) }
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: post_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Madsen and Martin Thoegersen