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 +4 -4
- data/.travis.yml +0 -1
- data/lib/varia_model.rb +9 -3
- data/lib/varia_model/version.rb +1 -1
- data/spec/unit/varia_model_spec.rb +28 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 457c80c1232f3aeacb043568d15ad03fbba619cd
|
4
|
+
data.tar.gz: edb591454d0f6737f8ea10a41e4d5a8c7db18859
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0839c79c10112b517caed124a2b3b76ee7e682e55ee9e66461068485f9bac4d714c1ffea45f6d124a7cdd8fca9f11c4e55d5e2e82e4960c977327266547bd29e
|
7
|
+
data.tar.gz: 80db8a3d942cdb91b7533f7e9e40a67374d8e75b39ea2a8c8695456d39b5c25faeadde065cacc4f00a4e1d70afd124e85f637b368d5a89e2768cac2b1404de79
|
data/.travis.yml
CHANGED
data/lib/varia_model.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/varia_model/version.rb
CHANGED
@@ -623,27 +623,47 @@ describe VariaModel do
|
|
623
623
|
end
|
624
624
|
|
625
625
|
describe "#to_json" do
|
626
|
-
|
627
|
-
|
628
|
-
include VariaModel
|
626
|
+
class Playa
|
627
|
+
include VariaModel
|
629
628
|
|
630
|
-
|
631
|
-
|
632
|
-
|
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
|
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:
|
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.
|
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
|