varia_model 0.2.0 → 0.3.2

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: 77dd327b0e41d985df1a161e39a5147b507e1df5
4
- data.tar.gz: 347a99f528442382d89e7766f12492a5b1154522
3
+ metadata.gz: 457c80c1232f3aeacb043568d15ad03fbba619cd
4
+ data.tar.gz: edb591454d0f6737f8ea10a41e4d5a8c7db18859
5
5
  SHA512:
6
- metadata.gz: b2b42df3bd92530a95735c97e6091849d93bd75a321e85027204390087364690f93be687aaa82babec153f139a94cf6ad94be123353ba8ebca33ad911c1f5cb5
7
- data.tar.gz: 36ee952987081d8a69f9a9f58d37d5688b0d7caca1657860f8be7a1c6c5ea754c4782847b7de6c838d890864c9449f4aea9f91531af53ea43feeb7c086ff2090
6
+ metadata.gz: 0839c79c10112b517caed124a2b3b76ee7e682e55ee9e66461068485f9bac4d714c1ffea45f6d124a7cdd8fca9f11c4e55d5e2e82e4960c977327266547bd29e
7
+ data.tar.gz: 80db8a3d942cdb91b7533f7e9e40a67374d8e75b39ea2a8c8695456d39b5c25faeadde065cacc4f00a4e1d70afd124e85f637b368d5a89e2768cac2b1404de79
@@ -1,7 +1,6 @@
1
1
  script: "bundle exec thor spec"
2
2
  language: ruby
3
3
  rvm:
4
- - 1.9.2
5
4
  - 1.9.3
6
5
  - 2.0.0
7
6
  - jruby-19mode
@@ -253,10 +253,16 @@ module VariaModel
253
253
  # @option options [Class, Symbol, String] :adapter
254
254
  #
255
255
  # @return [String]
256
- def to_json(options = {})
257
- JSON.generate(to_hash, options)
256
+ def to_json(*options)
257
+ as_json.to_json(*options)
258
+ end
259
+
260
+ # @return [Hash]
261
+ def as_json(*)
262
+ opts = {}
263
+ opts[JSON.create_id] = self.class.name if JSON.create_id
264
+ to_hash.merge(opts)
258
265
  end
259
- alias_method :as_json, :to_json
260
266
 
261
267
  # Convert the object to a hash.
262
268
  def to_hash
@@ -1,3 +1,3 @@
1
1
  module VariaModel
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -623,27 +623,47 @@ describe VariaModel do
623
623
  end
624
624
 
625
625
  describe "#to_json" do
626
- subject do
627
- Class.new do
628
- include VariaModel
626
+ class Playa
627
+ include VariaModel
629
628
 
630
- attribute 'first_name', type: String
631
- attribute 'nick', type: String
632
- end.new
629
+ attribute 'first_name', type: String
630
+ attribute 'nick', type: String
631
+ end
632
+
633
+ subject do
634
+ Playa.new
633
635
  end
634
636
 
635
637
  it "returns a JSON string containin the serialized attributes" do
636
638
  subject.first_name = "brooke"
637
639
  subject.nick = "leblanc"
638
640
 
639
- expect(subject.to_json).to eql(JSON.dump(first_name: "brooke", nick: "leblanc"))
641
+ expect(subject.to_json).to eql(JSON.dump(first_name: "brooke", nick: "leblanc", json_class: "Playa"))
640
642
  end
641
643
 
642
644
  it "includes the most recent value for any Procs" do
643
645
  subject.first_name = ->{ "seth".capitalize }
644
646
  subject.nick = ->{ "name".upcase }
645
647
 
646
- expect(subject.to_json).to eql(JSON.dump(first_name: "Seth", nick: "NAME"))
648
+ expect(subject.to_json).to eql(JSON.dump(first_name: "Seth", nick: "NAME", json_class: "Playa"))
649
+ end
650
+
651
+ describe "when JSON.create_id is nil" do
652
+ before do
653
+ @_old_create_id = JSON.create_id
654
+ JSON.create_id = nil
655
+ end
656
+
657
+ after do
658
+ JSON.create_id = @_old_create_id
659
+ end
660
+
661
+ it "does not include a nil key" do
662
+ subject.first_name = "brooke"
663
+ subject.nick = "leblanc"
664
+
665
+ expect(subject.to_json).to eql(JSON.dump(first_name: "brooke", nick: "leblanc"))
666
+ end
647
667
  end
648
668
  end
649
669
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: varia_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Winsor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-15 00:00:00.000000000 Z
11
+ date: 2014-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -220,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
220
  version: '0'
221
221
  requirements: []
222
222
  rubyforge_project:
223
- rubygems_version: 2.0.3
223
+ rubygems_version: 2.0.7
224
224
  signing_key:
225
225
  specification_version: 4
226
226
  summary: A mixin to provide objects with magic attribute reading and writing