statham 0.1.1 → 0.1.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/lib/statham/document.rb +14 -3
- data/lib/statham/serializer.rb +10 -3
- data/lib/statham/version.rb +1 -1
- data/statham.gemspec +1 -1
- metadata +19 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 986ac2d10681cc489f76a4b6d5df789374b86470
|
4
|
+
data.tar.gz: 061bb36945081bfb8b5a435a4c35a4000e25b860
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64fcbfdc01cfd951be99f099c59c1e91a7bf3d6aabc2e2203673d8b6459e7a529f3d1b2347928622f4f11fa73c1f2c4f3deb8615a805d5c81bea67e6be16283d
|
7
|
+
data.tar.gz: bd06fc3f406601a1fff2ff2a895b5525e708c75d543eed33b2ed8aeb9a3455fe9c3ebce49740dacbc96366dabb4e512df06a04af3de40580c62acd947a2efb03
|
data/lib/statham/document.rb
CHANGED
@@ -32,7 +32,18 @@ module Statham
|
|
32
32
|
|
33
33
|
yield attribute_set if block_given?
|
34
34
|
|
35
|
-
apply_statham_attribute_set(attribute_set)
|
35
|
+
apply_statham_attribute_set(attribute_set, json_type_column?(column_name))
|
36
|
+
end
|
37
|
+
|
38
|
+
# Internal: Tests if column with specified name has json type.
|
39
|
+
#
|
40
|
+
# column_name - Name of the column.
|
41
|
+
#
|
42
|
+
# Returns true if type is json, false otherwise.
|
43
|
+
def json_type_column?(column_name)
|
44
|
+
columns.detect do |column|
|
45
|
+
column.name == column_name.to_s
|
46
|
+
end.type == :json
|
36
47
|
end
|
37
48
|
|
38
49
|
# Internal: Collection of JSON attributes used as parent attributes for a
|
@@ -74,8 +85,8 @@ module Statham
|
|
74
85
|
# set - AttributeSet object to apply.
|
75
86
|
#
|
76
87
|
# Returns attributes in AttributeSet object.
|
77
|
-
def apply_statham_attribute_set(attribute_set)
|
78
|
-
serialize attribute_set.name, Statham::Serializer.new(attribute_set)
|
88
|
+
def apply_statham_attribute_set(attribute_set, implicit_serialization = false)
|
89
|
+
serialize attribute_set.name, Statham::Serializer.new(attribute_set, implicit_serialization)
|
79
90
|
|
80
91
|
attribute_set.attributes.each do |name, attribute|
|
81
92
|
define_method(name) do
|
data/lib/statham/serializer.rb
CHANGED
@@ -6,8 +6,9 @@ module Statham
|
|
6
6
|
# attribute_set - AttributeSet object for definition of the attributes.
|
7
7
|
#
|
8
8
|
# Returns new Serializer object.
|
9
|
-
def initialize(attribute_set)
|
9
|
+
def initialize(attribute_set, implicit_serialization = false)
|
10
10
|
@attribute_set = attribute_set
|
11
|
+
@implicit_serialization = implicit_serialization
|
11
12
|
end
|
12
13
|
|
13
14
|
# Internal: Serializes object.
|
@@ -16,7 +17,9 @@ module Statham
|
|
16
17
|
#
|
17
18
|
# Returns JSON string for the object.
|
18
19
|
def dump(object)
|
19
|
-
|
20
|
+
@implicit_serialization ?
|
21
|
+
serialize_with_attributes(object) :
|
22
|
+
ActiveSupport::JSON.encode(serialize_with_attributes(object))
|
20
23
|
end
|
21
24
|
|
22
25
|
# Internal: Deserializes JSON string into object.
|
@@ -25,7 +28,11 @@ module Statham
|
|
25
28
|
#
|
26
29
|
# Returns Hash object deserialized from the JSON.
|
27
30
|
def load(json)
|
28
|
-
object =
|
31
|
+
object = if @implicit_serialization
|
32
|
+
ActiveSupport::HashWithIndifferentAccess.new(json || {})
|
33
|
+
else
|
34
|
+
json ? ActiveSupport::HashWithIndifferentAccess.new(ActiveSupport::JSON.decode(json)) : Hash.new
|
35
|
+
end
|
29
36
|
|
30
37
|
deserialize_with_attributes(object)
|
31
38
|
end
|
data/lib/statham/version.rb
CHANGED
data/statham.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ['hwanginbeom@gmail.com']
|
11
11
|
spec.description = %q{Manage JSON object in string typed attributes for ActiveRecord models}
|
12
12
|
spec.summary = %q{JSON objects for attributes}
|
13
|
-
spec.homepage = ''
|
13
|
+
spec.homepage = 'https://github.com/inbeom/statham'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
metadata
CHANGED
@@ -1,97 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statham
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Inbeom Hwang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.3'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: sqlite3
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
description: Manage JSON object in string typed attributes for ActiveRecord models
|
@@ -101,7 +101,7 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
-
- .gitignore
|
104
|
+
- ".gitignore"
|
105
105
|
- Gemfile
|
106
106
|
- LICENSE.txt
|
107
107
|
- README.md
|
@@ -120,7 +120,7 @@ files:
|
|
120
120
|
- spec/unit/document_spec.rb
|
121
121
|
- spec/unit/serializer_spec.rb
|
122
122
|
- statham.gemspec
|
123
|
-
homepage:
|
123
|
+
homepage: https://github.com/inbeom/statham
|
124
124
|
licenses:
|
125
125
|
- MIT
|
126
126
|
metadata: {}
|
@@ -130,17 +130,17 @@ require_paths:
|
|
130
130
|
- lib
|
131
131
|
required_ruby_version: !ruby/object:Gem::Requirement
|
132
132
|
requirements:
|
133
|
-
- -
|
133
|
+
- - ">="
|
134
134
|
- !ruby/object:Gem::Version
|
135
135
|
version: '0'
|
136
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
137
|
requirements:
|
138
|
-
- -
|
138
|
+
- - ">="
|
139
139
|
- !ruby/object:Gem::Version
|
140
140
|
version: '0'
|
141
141
|
requirements: []
|
142
142
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.0
|
143
|
+
rubygems_version: 2.2.0
|
144
144
|
signing_key:
|
145
145
|
specification_version: 4
|
146
146
|
summary: JSON objects for attributes
|
@@ -152,4 +152,3 @@ test_files:
|
|
152
152
|
- spec/unit/attribute_spec.rb
|
153
153
|
- spec/unit/document_spec.rb
|
154
154
|
- spec/unit/serializer_spec.rb
|
155
|
-
has_rdoc:
|