loginator 0.0.4 → 0.0.6
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e096d117d2fc6ad0d615b29e0c99a28f74e58835
|
4
|
+
data.tar.gz: faab9d2862bdf8a389628ed91978d63be0d25f2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daec5f46f2cbc7096182e1316058c1356578bb28080f05a6b526e72dbecd071ed99ff7d4078259237be029b787f952cc40f1be94307f95f2192b3ed75cdd597c
|
7
|
+
data.tar.gz: 271a9200bdf43ba6cfb1c06514f159df266d9474049fd4ac71d3ba6f0ba788de962ca344c274e64ed2102810c9fdf0f0606614da87432120433022c544c191a9
|
@@ -2,7 +2,7 @@ require 'multi_json'
|
|
2
2
|
|
3
3
|
module Loginator
|
4
4
|
# Makes a Struct easily serializable and deserializable. Adds the
|
5
|
-
#
|
5
|
+
# from_json class method and to_json instance method to Struct
|
6
6
|
# classes.
|
7
7
|
module JsonableStruct
|
8
8
|
def self.included(base)
|
@@ -11,9 +11,15 @@ module Loginator
|
|
11
11
|
|
12
12
|
# class level mixins
|
13
13
|
module ClassMethods #:nodoc
|
14
|
-
def
|
15
|
-
|
16
|
-
|
14
|
+
def from_json(json)
|
15
|
+
json_type = json.delete('type')
|
16
|
+
fail(ArgumentError, format('Incorrect message type: %s', json_type)) unless json_type == type
|
17
|
+
fail(ArgumentError, format('Hash must contain keys: %s', members.join(', '))) unless valid_hash?(json)
|
18
|
+
new(*json.values)
|
19
|
+
end
|
20
|
+
|
21
|
+
def type
|
22
|
+
@type ||= name.split('::').last.downcase.freeze
|
17
23
|
end
|
18
24
|
|
19
25
|
private
|
@@ -27,7 +33,8 @@ module Loginator
|
|
27
33
|
end #:rubocop:enable documentation
|
28
34
|
|
29
35
|
def to_json
|
30
|
-
MultiJson.dump(to_h)
|
36
|
+
MultiJson.dump(to_h.merge(type: self.class.type))
|
31
37
|
end
|
38
|
+
alias_method :to_s, :to_json
|
32
39
|
end
|
33
40
|
end
|
data/lib/loginator/version.rb
CHANGED
data/lib/loginator.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
shared_examples_for 'jsonable_struct' do
|
2
2
|
describe '#to_json' do
|
3
3
|
it 'faithfully serializes' do
|
4
|
-
expect(subject.to_json).to eq(MultiJson.dump(subject.to_h))
|
4
|
+
expect(subject.to_json).to eq(MultiJson.dump(subject.to_h.merge(type: described_class.type)))
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
|
-
describe '.
|
8
|
+
describe '.from_json' do
|
9
9
|
it 'faithfully deserializes' do
|
10
|
-
expect(described_class.
|
10
|
+
expect(described_class.from_json(MultiJson.load(subject.to_json))).to eq(subject)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -29,9 +29,9 @@ shared_examples_for 'struct_with_defaults' do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
describe '.
|
32
|
+
describe '.from_json' do
|
33
33
|
it 'faithfully deserializes' do
|
34
|
-
expect(described_class.
|
34
|
+
expect(described_class.from_json(MultiJson.load(subject.to_json))).to eq(subject)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loginator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Poirier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|