arrest 0.0.85 → 0.0.86
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/arrest.rb +1 -1
- data/lib/arrest/abstract_resource.rb +2 -0
- data/lib/arrest/attributes/attribute.rb +21 -2
- data/lib/arrest/attributes/has_attributes.rb +30 -12
- data/lib/arrest/attributes/polymorphic_attribute.rb +10 -2
- data/lib/arrest/transport/http_source.rb +1 -4
- data/lib/arrest/version.rb +1 -1
- metadata +22 -22
data/lib/arrest.rb
CHANGED
@@ -15,12 +15,12 @@ require "arrest/transport/resource_proxy"
|
|
15
15
|
|
16
16
|
require "arrest/attributes/belongs_to"
|
17
17
|
require "arrest/attributes/has_attributes"
|
18
|
+
require "arrest/attributes/converter"
|
18
19
|
require "arrest/attributes/attribute"
|
19
20
|
require "arrest/attributes/nested_attribute"
|
20
21
|
require "arrest/attributes/nested_collection"
|
21
22
|
require "arrest/attributes/belongs_to_attribute"
|
22
23
|
require "arrest/attributes/polymorphic_attribute"
|
23
|
-
require "arrest/attributes/converter"
|
24
24
|
require "arrest/handler"
|
25
25
|
require "arrest/helper/filter"
|
26
26
|
require "arrest/helper/ordered_collection"
|
@@ -146,6 +146,7 @@ module Arrest
|
|
146
146
|
req_type = new_record? ? :post : :put
|
147
147
|
success = !!AbstractResource::source.send(req_type, @context, self)
|
148
148
|
self.context.cache.flush
|
149
|
+
self.reset_dirtiness
|
149
150
|
success
|
150
151
|
else
|
151
152
|
false
|
@@ -166,6 +167,7 @@ module Arrest
|
|
166
167
|
@belongs_tos = {}
|
167
168
|
hash = internal_reload
|
168
169
|
self.attributes= hash
|
170
|
+
self.reset_dirtiness
|
169
171
|
end
|
170
172
|
|
171
173
|
def new_record?
|
@@ -1,11 +1,22 @@
|
|
1
1
|
module Arrest
|
2
|
+
|
3
|
+
module Dirty
|
4
|
+
end
|
5
|
+
Integer.send(:include, Dirty)
|
6
|
+
String.send(:include, Dirty)
|
7
|
+
Float.send(:include, Dirty)
|
8
|
+
Boolean.send(:include, Dirty)
|
9
|
+
|
10
|
+
|
2
11
|
class Attribute
|
3
|
-
attr_accessor :name, :actions, :clazz, :json_name
|
12
|
+
attr_accessor :name, :actions, :clazz, :json_name, :dirty
|
4
13
|
|
5
|
-
def initialize
|
14
|
+
def initialize(name, clazz, actions = nil)
|
6
15
|
@name = name.to_sym
|
7
16
|
@actions = actions || [:create, :retrieve, :update, :delete]
|
8
17
|
@clazz = clazz
|
18
|
+
@dirty_sensitive = @clazz.ancestors.include?(Dirty)
|
19
|
+
@dirty = false
|
9
20
|
@json_name = Source.json_key_converter.key_to_json(name).to_sym
|
10
21
|
end
|
11
22
|
|
@@ -17,6 +28,14 @@ module Arrest
|
|
17
28
|
@actions.include?(:create) || @actions.include?(:update)
|
18
29
|
end
|
19
30
|
|
31
|
+
def dirty?
|
32
|
+
if @dirty_sensitive
|
33
|
+
@dirty
|
34
|
+
else
|
35
|
+
true # treat as 'always' dirty
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
20
39
|
def from_hash(parent, value)
|
21
40
|
return if value == nil
|
22
41
|
|
@@ -48,7 +48,7 @@ module Arrest
|
|
48
48
|
|
49
49
|
def init_from_hash(as_i={}, from_json = false)
|
50
50
|
raise "hash expected but got #{as_i.class}" unless as_i.is_a?(Hash)
|
51
|
-
@attribute_values
|
51
|
+
@attribute_values ||= {}
|
52
52
|
as = {}
|
53
53
|
as_i.each_pair do |k,v|
|
54
54
|
as[k.to_sym] = v
|
@@ -68,6 +68,12 @@ module Arrest
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
+
def reset_dirtiness
|
72
|
+
self.class.all_fields.each do |field|
|
73
|
+
field.dirty = false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
71
77
|
def attributes
|
72
78
|
@attribute_values ||= {}
|
73
79
|
end
|
@@ -103,22 +109,31 @@ module Arrest
|
|
103
109
|
def to_hash(show_all_fields = true, json_names = false, action = nil)
|
104
110
|
result = {}
|
105
111
|
|
106
|
-
self.class.all_fields.
|
107
|
-
!action ||
|
108
|
-
a.actions.include?(action)}.each do |field|
|
109
|
-
if json_names
|
110
|
-
json_name = field.json_name
|
111
|
-
else
|
112
|
-
json_name = field.name
|
113
|
-
end
|
114
|
-
val = self.send(field.name)
|
115
|
-
converted = field.to_hash val
|
112
|
+
self.class.all_fields.each do |field|
|
116
113
|
|
117
|
-
|
114
|
+
if render_field_to_hash?(field, show_all_fields, action)
|
115
|
+
|
116
|
+
if json_names
|
117
|
+
json_name = field.json_name
|
118
|
+
else
|
119
|
+
json_name = field.name
|
120
|
+
end
|
121
|
+
val = self.send(field.name)
|
122
|
+
converted = field.to_hash val
|
123
|
+
|
124
|
+
result[json_name] = converted
|
125
|
+
end
|
118
126
|
end
|
119
127
|
result
|
120
128
|
end
|
121
129
|
|
130
|
+
# decides whether attribute field will be rendered to hash
|
131
|
+
# either all, or, if an CRUD action given, only those sensitive to this action
|
132
|
+
# and if the action is update only those being dirty
|
133
|
+
def render_field_to_hash?(field, show_all_fields, action)
|
134
|
+
show_all_fields || !action || (field.actions.include?(action) && (action != :update || field.dirty?))
|
135
|
+
end
|
136
|
+
|
122
137
|
module HasAttributesClassMethods
|
123
138
|
attr_accessor :fields
|
124
139
|
|
@@ -147,6 +162,9 @@ module Arrest
|
|
147
162
|
send :define_method, "#{attribute.name}=" do |v|
|
148
163
|
converted_v = convert(attribute, v)
|
149
164
|
Arrest::debug "setter #{self.class.name} #{attribute.name} = #{converted_v}"
|
165
|
+
|
166
|
+
attribute.dirty = true
|
167
|
+
|
150
168
|
self.attribute_values[attribute.name] = converted_v
|
151
169
|
end
|
152
170
|
# define getter for attribute value
|
@@ -6,7 +6,11 @@ module Arrest
|
|
6
6
|
attribute :type, String
|
7
7
|
|
8
8
|
def self.mk_json(value)
|
9
|
-
|
9
|
+
self.to_hash.to_json
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.to_hash
|
13
|
+
{:id => value.id, :type => value.type}
|
10
14
|
end
|
11
15
|
end
|
12
16
|
|
@@ -17,7 +21,11 @@ module Arrest
|
|
17
21
|
|
18
22
|
def from_hash(parent, value)
|
19
23
|
return nil unless value != nil
|
20
|
-
|
24
|
+
if value.is_a? Hash
|
25
|
+
@clazz.new(value)
|
26
|
+
else
|
27
|
+
@clazz.new(value.to_hash)
|
28
|
+
end
|
21
29
|
end
|
22
30
|
end
|
23
31
|
end
|
@@ -89,16 +89,13 @@ module Arrest
|
|
89
89
|
hash.delete("id")
|
90
90
|
body = JSON.generate(hash)
|
91
91
|
|
92
|
-
internal_put(rest_resource, rest_resource.resource_location, body)
|
93
|
-
end
|
94
|
-
|
95
|
-
def internal_put(rest_resource, location, body)
|
96
92
|
profiler_status_str = ""
|
97
93
|
::ActiveSupport::Notifications.instrument("http.sgdb",
|
98
94
|
:method => :delete,
|
99
95
|
:url => rest_resource.resource_location,
|
100
96
|
:status => profiler_status_str) do
|
101
97
|
headers = nil
|
98
|
+
location = rest_resource.resource_location
|
102
99
|
response = self.connection().put do |req|
|
103
100
|
req.url(location)
|
104
101
|
headers = add_headers(rest_resource.context, req.headers)
|
data/lib/arrest/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arrest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.86
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-21 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &21101800 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *21101800
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: faraday
|
27
|
-
requirement: &
|
27
|
+
requirement: &21097480 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.7.5
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *21097480
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: activemodel
|
38
|
-
requirement: &
|
38
|
+
requirement: &21096980 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '3'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *21096980
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
|
-
requirement: &
|
49
|
+
requirement: &21096520 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.0.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *21096520
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rake
|
60
|
-
requirement: &
|
60
|
+
requirement: &21096140 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *21096140
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rdoc
|
71
|
-
requirement: &
|
71
|
+
requirement: &21095680 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *21095680
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rspec
|
82
|
-
requirement: &
|
82
|
+
requirement: &21095180 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '2'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *21095180
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rr
|
93
|
-
requirement: &
|
93
|
+
requirement: &21094760 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *21094760
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: simplecov
|
104
|
-
requirement: &
|
104
|
+
requirement: &21094240 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *21094240
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: rack
|
115
|
-
requirement: &
|
115
|
+
requirement: &21093800 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,7 +120,7 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *21093800
|
124
124
|
description: Consume a rest API in a AR like fashion
|
125
125
|
email:
|
126
126
|
- axel.tetzlaff@fortytools.com
|