arrest 0.0.74 → 0.0.75

Sign up to get free protection for your applications and to get access to all the features.
@@ -237,6 +237,8 @@ module Arrest
237
237
  @child_collections = {}
238
238
  @views = {}
239
239
  @belongs_tos = {}
240
+ @ids_collections = {}
241
+ @has_many_collections = {}
240
242
  hash = internal_reload
241
243
  self.attributes= hash
242
244
  end
@@ -19,7 +19,7 @@ module Arrest
19
19
  @views ||= {}
20
20
  @views[method_name] ||= begin
21
21
 
22
- r = self.class.source().get_one(self.context, "#{self.resource_path}/#{id}/#{method_name}")
22
+ r = self.class.source().get(self.context, "#{self.resource_path}/#{id}/#{method_name}")
23
23
  r = self.class.body_root(r)
24
24
 
25
25
  Arrest::Source.mod.const_get(clazz).new(self.context, r)
@@ -20,7 +20,7 @@ module Arrest
20
20
  def collection
21
21
  unless @collection
22
22
 
23
- r = @parent.class.source().get_one(@parent.context, "#{@url}")
23
+ r = @parent.class.source().get(@parent.context, "#{@url}")
24
24
  @collection = @parent.class.body_root(r)
25
25
 
26
26
  end
@@ -25,11 +25,11 @@ module Arrest
25
25
  hds
26
26
  end
27
27
 
28
- def get_one(context, sub, filter={})
28
+ def get(context, sub, filter={})
29
29
  sub = fix_url_encode(sub)
30
30
  profiler_status_str = ""
31
31
  ::ActiveSupport::Notifications.instrument("http.sgdb",
32
- :method => :get, :url => sub, :status => profiler_status_str) do
32
+ :method => :get, :url => sub, :status => profiler_status_str) do
33
33
  headers = nil
34
34
  response = self.connection().get do |req|
35
35
  req.url(sub, filter)
@@ -48,31 +48,6 @@ module Arrest
48
48
  end
49
49
  end
50
50
 
51
- # FIXME (bk, at) : seems to be identical to get_one - prepare to refactor
52
- def get_many(context, sub, filter={})
53
- sub = fix_url_encode(sub)
54
- profiler_status_str = ""
55
- ::ActiveSupport::Notifications.instrument("http.sgdb",
56
- :method => :get, :url => sub, :status => profiler_status_str) do
57
- headers = nil
58
- response = self.connection().get do |req|
59
- req.url(sub, filter)
60
- headers = add_headers(context, req.headers)
61
- end
62
- rql = RequestLog.new(:get, "#{sub}#{hash_to_query filter}", nil, headers)
63
- rsl = ResponseLog.new(response.env[:status], response.body)
64
- Arrest::Source.call_logger.log(rql, rsl)
65
- if response.env[:status] == 401
66
- raise Errors::PermissionDeniedError.new(response.body)
67
- elsif response.env[:status] != 200
68
- raise Errors::DocumentNotFoundError
69
- end
70
- profiler_status_str << response.env[:status].to_s
71
- response.body
72
- end
73
- end
74
-
75
-
76
51
  def delete_all(context, resource_path)
77
52
  headers = nil
78
53
  response = self.connection().delete do |req|
@@ -107,13 +82,6 @@ module Arrest
107
82
  end
108
83
  end
109
84
 
110
- def put_sub_resource(rest_resource, sub_url, ids)
111
- location = "#{rest_resource.resource_location}/#{sub_url}"
112
- body = ids.to_json
113
-
114
- internal_put(rest_resource, location, body)
115
- end
116
-
117
85
  def put(context, rest_resource)
118
86
  raise "To change an object it must have an id" unless rest_resource.respond_to?(:id) && rest_resource.id != nil
119
87
  hash = rest_resource.to_jhash
@@ -125,9 +93,6 @@ module Arrest
125
93
  internal_put(rest_resource, rest_resource.resource_location, body)
126
94
  end
127
95
 
128
-
129
-
130
-
131
96
  def internal_put(rest_resource, location, body)
132
97
  profiler_status_str = ""
133
98
  ::ActiveSupport::Notifications.instrument("http.sgdb",
@@ -114,7 +114,7 @@ module Arrest
114
114
  wrap id_list, id_list.length
115
115
  end
116
116
 
117
- def get_many(context,sub, filters = {})
117
+ def get(context,sub, filters = {})
118
118
  Arrest::debug sub + (hash_to_query filters)
119
119
  # filters are ignored by mem impl so far
120
120
 
@@ -130,7 +130,7 @@ module Arrest
130
130
  wrap collection_json(objects), id_list.length
131
131
  end
132
132
 
133
- def get_one(context, sub, filters = {})
133
+ def get(context, sub, filters = {})
134
134
  Arrest::debug sub + (hash_to_query filters)
135
135
  # filters are ignored by mem impl so far
136
136
  idx = sub.rindex '/'
@@ -252,35 +252,6 @@ module Arrest
252
252
  end
253
253
  end
254
254
 
255
- def put_sub_resource(rest_resource, sub_url, ids)
256
- =begin
257
- matcher = /^.+\/([^\/]+)\/([^\/]+)_ids$/.match(resource_path)
258
- return [] unless matcher
259
- object_id = matcher[1]
260
- relation = matcher[2] + 's'
261
- location = "#{rest_resource.resource_location}/#{sub_url}"
262
- body = ids.to_json
263
-
264
- @@edge_matrix[object_id] ||= []
265
-
266
- alread_included = @@edge_matrix[object_id].find_all do |e|
267
- e.name.to_s == sub_url && ids.include?(e.id)
268
- end
269
-
270
- @@edge_matrix[object_id].delete_if do |e|
271
- e.name.to_s == sub_url && !ids.include?(e.id)
272
- end
273
-
274
- need_to_create = ids - alread_included
275
- need_to_create.each do |id|
276
- @@edge_matrix[object_id] << Edge.new(foreign_key, url_part, id, true)
277
- end
278
-
279
-
280
- =end
281
- true
282
- end
283
-
284
255
  def put(context, rest_resource)
285
256
  raise "To change an object it must have an id" unless rest_resource.respond_to?(:id) && rest_resource.id != nil
286
257
  old = @@all_objects[rest_resource.id]
@@ -23,7 +23,7 @@ module Arrest
23
23
  def all_for(parent)
24
24
  raise "Parent has no id yet" unless parent.id
25
25
  begin
26
- body_root(source().get_many(parent.context, self.resource_path_for(parent))).map do |h|
26
+ body_root(source().get(parent.context, self.resource_path_for(parent))).map do |h|
27
27
  self.build(parent, h)
28
28
  end
29
29
  rescue Arrest::Errors::DocumentNotFoundError
@@ -36,7 +36,7 @@ module Arrest
36
36
  end
37
37
 
38
38
  def find_for(context, parent, id)
39
- r = source().get_one(context, "#{self.resource_path_for(parent)}/#{id}")
39
+ r = source().get(context, "#{self.resource_path_for(parent)}/#{id}")
40
40
  body = body_root(r)
41
41
  self.build(parent, body)
42
42
  end
@@ -62,7 +62,7 @@ module Arrest
62
62
  else
63
63
  send :define_singleton_method, name do |parent|
64
64
  raise "Parent has no id yet" unless parent.id
65
- body_root(source().get_many(parent.context, self.scoped_path_for(parent, name))).map do |h|
65
+ body_root(source().get(parent.context, self.scoped_path_for(parent, name))).map do |h|
66
66
  self.build(parent, h)
67
67
  end
68
68
  end
@@ -11,7 +11,7 @@ module Arrest
11
11
  # in a hash combined with metadata
12
12
  def by_url(context, url)
13
13
  begin
14
- response = source().get_many(context, url)
14
+ response = source().get(context, url)
15
15
  parsed_hash = JSON.parse(response)
16
16
  result_count = parsed_hash['result_count']
17
17
  body = body_root(response)
@@ -48,7 +48,7 @@ module Arrest
48
48
  end
49
49
 
50
50
  full_resource_path = "#{self.resource_path}/#{id}"
51
- r = source().get_one(context, full_resource_path)
51
+ r = source().get(context, full_resource_path)
52
52
  body = body_root(r)
53
53
  if body == nil || body.empty?
54
54
  Arrest::logger.info "DocumentNotFoundError for #{full_resource_path}"
@@ -105,7 +105,7 @@ module Arrest
105
105
  def stub(context, stub_id)
106
106
  n = self.new(context)
107
107
  n.initialize_has_attributes({:id => stub_id}) do
108
- r = n.class.source().get_one(@context, "#{self.resource_path}/#{stub_id}")
108
+ r = n.class.source().get(@context, "#{self.resource_path}/#{stub_id}")
109
109
  body = n.class.body_root(r)
110
110
  n.init_from_hash(body, true)
111
111
  end
@@ -4,7 +4,7 @@ module Arrest
4
4
  class SingleResource < RootResource
5
5
  class << self
6
6
  def load(context)
7
- r = source().get_one(context, "#{self.resource_path}")
7
+ r = source().get(context, "#{self.resource_path}")
8
8
  body = body_root(r)
9
9
  if body == nil || body.empty?
10
10
  Arrest::logger.info "DocumentNotFoundError for #{self.resource_path}"
@@ -1,3 +1,3 @@
1
1
  module Arrest
2
- VERSION = "0.0.74"
2
+ VERSION = "0.0.75"
3
3
  end
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.74
4
+ version: 0.0.75
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-07-24 00:00:00.000000000Z
12
+ date: 2012-07-25 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &21738300 !ruby/object:Gem::Requirement
16
+ requirement: &24274620 !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: *21738300
24
+ version_requirements: *24274620
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: faraday
27
- requirement: &21737800 !ruby/object:Gem::Requirement
27
+ requirement: &24274120 !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: *21737800
35
+ version_requirements: *24274120
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activemodel
38
- requirement: &21737280 !ruby/object:Gem::Requirement
38
+ requirement: &24273620 !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: *21737280
46
+ version_requirements: *24273620
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &21736800 !ruby/object:Gem::Requirement
49
+ requirement: &24273160 !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: *21736800
57
+ version_requirements: *24273160
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &21735740 !ruby/object:Gem::Requirement
60
+ requirement: &24272780 !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: *21735740
68
+ version_requirements: *24272780
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rdoc
71
- requirement: &21735160 !ruby/object:Gem::Requirement
71
+ requirement: &24272320 !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: *21735160
79
+ version_requirements: *24272320
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &21734420 !ruby/object:Gem::Requirement
82
+ requirement: &24271820 !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: *21734420
90
+ version_requirements: *24271820
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rr
93
- requirement: &21733840 !ruby/object:Gem::Requirement
93
+ requirement: &24271400 !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: *21733840
101
+ version_requirements: *24271400
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: simplecov
104
- requirement: &21733380 !ruby/object:Gem::Requirement
104
+ requirement: &24270940 !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: *21733380
112
+ version_requirements: *24270940
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: rack
115
- requirement: &21732900 !ruby/object:Gem::Requirement
115
+ requirement: &24270520 !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: *21732900
123
+ version_requirements: *24270520
124
124
  description: Consume a rest API in a AR like fashion
125
125
  email:
126
126
  - axel.tetzlaff@fortytools.com