object_attorney 2.9.0 → 2.9.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 +8 -8
- data/lib/object_attorney/delegation.rb +1 -1
- data/lib/object_attorney/serialization.rb +43 -0
- data/lib/object_attorney/version.rb +1 -1
- data/lib/object_attorney.rb +2 -2
- data/spec/object_attorney/{exposed_data_spec.rb → serialization_spec.rb} +1 -2
- data/spec/support/form_objects/post_form.rb +2 -2
- metadata +4 -4
- data/lib/object_attorney/exposed_data.rb +0 -38
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
OTNmNTI5YThjYjcxYThjNmM2YWFmZjY5NjJlNjlkYTYzNGM1MWUwMw==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
MjY5YWNhNmI1ODUwZDUxNzExNzRiMWJhNDE0N2VjZDlkNzlkYzQ2OQ==
|
|
7
7
|
SHA512:
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
ODA1NzdlY2U2NmY0Mzc2YTA1NDk1NGY1ZWQ3ZDhjOTY5Zjg0ZTk1YmZjOTM1
|
|
10
|
+
MTU5NDMxODAyMmJjYjVhY2ZhZTZlYWFmY2ViOTVjNzI0NjQ1ZTk2ZWQwNGQ5
|
|
11
|
+
MmM1MzJjMjYyMTRmYWU5YjI5YTRkZDFkYzhjZTViNzBjYmU2NGQ=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
NjY2YmM2NzNkZWQ0YjZlMTQyOTVmMDNlMTUyZDVjY2FmMjUxNzBhNzMxYzc0
|
|
14
|
+
ZmZjZjMwNGVlMGFkM2Y1Y2U5NGQ2YWQzMGUxMTI5MmFmNDUwNGQ1OTc5M2E1
|
|
15
|
+
ZjM4MGMyYTk3MzBkYmQ1ODhlN2YwZjY2ODIwODk3NjgyMTg1OWI=
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module ObjectAttorney
|
|
2
|
+
|
|
3
|
+
module Serialization
|
|
4
|
+
|
|
5
|
+
def attributes
|
|
6
|
+
self.class.attributes_keys.reduce({}) do |data, getter|
|
|
7
|
+
data[getter.to_s] = send(getter)
|
|
8
|
+
data
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def to_hash(options = {})
|
|
13
|
+
serializable_hash(options)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def to_json(options = {})
|
|
17
|
+
serializable_hash(options).to_json
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.included(base)
|
|
21
|
+
base.class_eval { include ActiveModel::Serialization }
|
|
22
|
+
base.extend(ClassMethods)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
module ClassMethods
|
|
26
|
+
|
|
27
|
+
def attributes_keys
|
|
28
|
+
return @attributes_keys if defined?(@attributes_keys)
|
|
29
|
+
|
|
30
|
+
@attributes_keys = zuper_method(:attributes_keys)
|
|
31
|
+
|
|
32
|
+
@attributes_keys ||= represented_object_class.present? && represented_object_class.method_defined?(:id) ? [:id] : []
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def add_attribute_key(*getters)
|
|
36
|
+
attributes_keys.push(*getters) unless attributes_keys.include?(getters)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
data/lib/object_attorney.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
require "object_attorney/attribute_assignment"
|
|
3
3
|
require "object_attorney/delegation"
|
|
4
|
-
require "object_attorney/exposed_data"
|
|
5
4
|
require "object_attorney/helpers"
|
|
6
5
|
require "object_attorney/naming"
|
|
7
6
|
require "object_attorney/reflection"
|
|
@@ -10,6 +9,7 @@ require "object_attorney/nested_objects"
|
|
|
10
9
|
require "object_attorney/record"
|
|
11
10
|
require "object_attorney/translation"
|
|
12
11
|
require "object_attorney/representation"
|
|
12
|
+
require "object_attorney/serialization"
|
|
13
13
|
require 'active_record'
|
|
14
14
|
|
|
15
15
|
require "object_attorney/version"
|
|
@@ -49,7 +49,7 @@ module ObjectAttorney
|
|
|
49
49
|
include NestedObjects
|
|
50
50
|
include Record
|
|
51
51
|
include Representation
|
|
52
|
-
include
|
|
52
|
+
include Serialization
|
|
53
53
|
|
|
54
54
|
validate :validate_represented_object
|
|
55
55
|
end
|
|
@@ -14,7 +14,6 @@ describe PostForm::GrandSon do
|
|
|
14
14
|
post_form = described_class.new(params[:post], post)
|
|
15
15
|
|
|
16
16
|
post_form.save.should == true
|
|
17
|
-
described_class.exposed_data.should == [:id, :title, :email, :author, :body, :date]
|
|
18
17
|
|
|
19
18
|
Post.all.count.should == 1
|
|
20
19
|
post = Post.first
|
|
@@ -34,7 +33,7 @@ describe PostForm::GrandSon do
|
|
|
34
33
|
|
|
35
34
|
data = { id:1, title: "altered title", email: "test@gmail.com", author: "test", body: "post body", date: "20-10-2010" }
|
|
36
35
|
|
|
37
|
-
post_form.
|
|
36
|
+
post_form.serializable_hash.symbolize_keys.should == data
|
|
38
37
|
post_form.to_json.should == data.to_json
|
|
39
38
|
end
|
|
40
39
|
|
|
@@ -100,7 +100,7 @@ module PostForm
|
|
|
100
100
|
class Father < GrandFather
|
|
101
101
|
properties :title
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
add_attribute_key :email, :author
|
|
104
104
|
|
|
105
105
|
attr_accessor :email, :author
|
|
106
106
|
end
|
|
@@ -112,7 +112,7 @@ module PostForm
|
|
|
112
112
|
class GrandSon < Son
|
|
113
113
|
setters :user_id
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
add_attribute_key :date
|
|
116
116
|
|
|
117
117
|
attr_accessor :date
|
|
118
118
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: object_attorney
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.9.
|
|
4
|
+
version: 2.9.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- João Gonçalves
|
|
@@ -76,7 +76,6 @@ files:
|
|
|
76
76
|
- lib/object_attorney/association_reflection.rb
|
|
77
77
|
- lib/object_attorney/attribute_assignment.rb
|
|
78
78
|
- lib/object_attorney/delegation.rb
|
|
79
|
-
- lib/object_attorney/exposed_data.rb
|
|
80
79
|
- lib/object_attorney/helpers.rb
|
|
81
80
|
- lib/object_attorney/naming.rb
|
|
82
81
|
- lib/object_attorney/nested_objects.rb
|
|
@@ -84,6 +83,7 @@ files:
|
|
|
84
83
|
- lib/object_attorney/record.rb
|
|
85
84
|
- lib/object_attorney/reflection.rb
|
|
86
85
|
- lib/object_attorney/representation.rb
|
|
86
|
+
- lib/object_attorney/serialization.rb
|
|
87
87
|
- lib/object_attorney/translation.rb
|
|
88
88
|
- lib/object_attorney/validations.rb
|
|
89
89
|
- lib/object_attorney/version.rb
|
|
@@ -94,7 +94,6 @@ files:
|
|
|
94
94
|
- spec/object_attorney/bulk_posts_allow_only_new_form_spec.rb
|
|
95
95
|
- spec/object_attorney/bulk_posts_with_form_objects_form_spec.rb
|
|
96
96
|
- spec/object_attorney/delegation_spec.rb
|
|
97
|
-
- spec/object_attorney/exposed_data_spec.rb
|
|
98
97
|
- spec/object_attorney/post_form_spec.rb
|
|
99
98
|
- spec/object_attorney/post_validations_form_spec.rb
|
|
100
99
|
- spec/object_attorney/post_with_comment_form_spec.rb
|
|
@@ -102,6 +101,7 @@ files:
|
|
|
102
101
|
- spec/object_attorney/post_with_comments_and_address_form_spec.rb
|
|
103
102
|
- spec/object_attorney/post_with_only_existing_comments_form_spec.rb
|
|
104
103
|
- spec/object_attorney/post_with_only_new_comments_form_spec.rb
|
|
104
|
+
- spec/object_attorney/serialization_spec.rb
|
|
105
105
|
- spec/object_attorney/user_form_spec.rb
|
|
106
106
|
- spec/spec_helper.rb
|
|
107
107
|
- spec/support/active_model/validations.rb
|
|
@@ -155,7 +155,6 @@ test_files:
|
|
|
155
155
|
- spec/object_attorney/bulk_posts_allow_only_new_form_spec.rb
|
|
156
156
|
- spec/object_attorney/bulk_posts_with_form_objects_form_spec.rb
|
|
157
157
|
- spec/object_attorney/delegation_spec.rb
|
|
158
|
-
- spec/object_attorney/exposed_data_spec.rb
|
|
159
158
|
- spec/object_attorney/post_form_spec.rb
|
|
160
159
|
- spec/object_attorney/post_validations_form_spec.rb
|
|
161
160
|
- spec/object_attorney/post_with_comment_form_spec.rb
|
|
@@ -163,6 +162,7 @@ test_files:
|
|
|
163
162
|
- spec/object_attorney/post_with_comments_and_address_form_spec.rb
|
|
164
163
|
- spec/object_attorney/post_with_only_existing_comments_form_spec.rb
|
|
165
164
|
- spec/object_attorney/post_with_only_new_comments_form_spec.rb
|
|
165
|
+
- spec/object_attorney/serialization_spec.rb
|
|
166
166
|
- spec/object_attorney/user_form_spec.rb
|
|
167
167
|
- spec/spec_helper.rb
|
|
168
168
|
- spec/support/active_model/validations.rb
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
module ObjectAttorney
|
|
2
|
-
|
|
3
|
-
module ExposedData
|
|
4
|
-
|
|
5
|
-
def to_hash
|
|
6
|
-
self.class.exposed_data.reduce({}) do |data, getter|
|
|
7
|
-
data[getter] = send(getter)
|
|
8
|
-
data
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def to_json(options = {})
|
|
13
|
-
to_hash.to_json
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def self.included(base)
|
|
17
|
-
base.extend(ClassMethods)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
module ClassMethods
|
|
21
|
-
|
|
22
|
-
def exposed_data
|
|
23
|
-
return @exposed_data if defined?(@exposed_data)
|
|
24
|
-
|
|
25
|
-
@exposed_data = zuper_method(:exposed_data)
|
|
26
|
-
|
|
27
|
-
@exposed_data ||= represented_object_class.present? && represented_object_class.method_defined?(:id) ? [:id] : []
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def add_exposed_data(*getters)
|
|
31
|
-
exposed_data.push(*getters) unless exposed_data.include?(getters)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
end
|