arrest 0.0.78 → 0.0.79
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/arrest.rb +0 -2
- data/lib/arrest/abstract_resource.rb +0 -19
- data/lib/arrest/root_resource.rb +1 -1
- data/lib/arrest/version.rb +1 -1
- data/test/models.rb +4 -4
- metadata +22 -24
- data/lib/arrest/helper/child_collection.rb +0 -45
- data/lib/arrest/rest_child.rb +0 -97
data/lib/arrest.rb
CHANGED
@@ -23,7 +23,6 @@ require "arrest/attributes/polymorphic_attribute"
|
|
23
23
|
require "arrest/attributes/converter"
|
24
24
|
require "arrest/handler"
|
25
25
|
require "arrest/helper/filter"
|
26
|
-
require "arrest/helper/child_collection"
|
27
26
|
require "arrest/helper/ordered_collection"
|
28
27
|
require "arrest/helper/has_many_collection"
|
29
28
|
require "arrest/helper/ids_collection"
|
@@ -34,5 +33,4 @@ require "arrest/abstract_resource"
|
|
34
33
|
require "arrest/nested_resource"
|
35
34
|
require "arrest/root_resource"
|
36
35
|
require "arrest/single_resource"
|
37
|
-
require "arrest/rest_child"
|
38
36
|
|
@@ -72,25 +72,6 @@ module Arrest
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
def children(*args)
|
76
|
-
method_name, options = args
|
77
|
-
method_name = method_name.to_sym
|
78
|
-
|
79
|
-
clazz_name = method_name.to_s
|
80
|
-
if options
|
81
|
-
clazz = options[:class_name]
|
82
|
-
if clazz
|
83
|
-
clazz_name = clazz.to_s
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
send :define_method, method_name do
|
88
|
-
@child_collections ||= {}
|
89
|
-
@child_collections[method_name] ||= ChildCollection.new(self, (StringUtils.classify(StringUtils.singular clazz_name)))
|
90
|
-
@child_collections[method_name]
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
75
|
def parent(*args)
|
95
76
|
method_name = args[0].to_s.to_sym
|
96
77
|
class_eval "def #{method_name}; self.parent; end"
|
data/lib/arrest/root_resource.rb
CHANGED
data/lib/arrest/version.rb
CHANGED
data/test/models.rb
CHANGED
@@ -14,12 +14,12 @@ class Zoo < Arrest::RootResource
|
|
14
14
|
belongs_to :zoo_owner
|
15
15
|
end
|
16
16
|
|
17
|
-
class Animal < Arrest::
|
17
|
+
class Animal < Arrest::RootResource
|
18
18
|
attribute :kind, String
|
19
19
|
attribute :age, Integer
|
20
20
|
attribute :male, Boolean
|
21
21
|
|
22
|
-
|
22
|
+
belongs_to :zoo
|
23
23
|
|
24
24
|
scope :server_males_only
|
25
25
|
scope(:males_only){|a| a.male}
|
@@ -93,11 +93,11 @@ class ParentFilter < Arrest::RootResource
|
|
93
93
|
children :child_filters
|
94
94
|
end
|
95
95
|
|
96
|
-
class ChildFilter < Arrest::
|
96
|
+
class ChildFilter < Arrest::RootResource
|
97
97
|
attribute :id, String
|
98
98
|
attribute :bfield, String
|
99
99
|
|
100
|
-
|
100
|
+
belongs_to :parent_filter
|
101
101
|
|
102
102
|
filter(:child_nnn) {|s| bfield == s}
|
103
103
|
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.
|
4
|
+
version: 0.0.79
|
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-
|
12
|
+
date: 2012-08-02 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &19211900 !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: *19211900
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: faraday
|
27
|
-
requirement: &
|
27
|
+
requirement: &19211400 !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: *19211400
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: activemodel
|
38
|
-
requirement: &
|
38
|
+
requirement: &19210900 !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: *19210900
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
|
-
requirement: &
|
49
|
+
requirement: &19210440 !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: *19210440
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rake
|
60
|
-
requirement: &
|
60
|
+
requirement: &19210060 !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: *19210060
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rdoc
|
71
|
-
requirement: &
|
71
|
+
requirement: &19209600 !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: *19209600
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rspec
|
82
|
-
requirement: &
|
82
|
+
requirement: &19209100 !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: *19209100
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rr
|
93
|
-
requirement: &
|
93
|
+
requirement: &19208680 !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: *19208680
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: simplecov
|
104
|
-
requirement: &
|
104
|
+
requirement: &19208220 !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: *19208220
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: rack
|
115
|
-
requirement: &
|
115
|
+
requirement: &19207800 !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: *19207800
|
124
124
|
description: Consume a rest API in a AR like fashion
|
125
125
|
email:
|
126
126
|
- axel.tetzlaff@fortytools.com
|
@@ -146,7 +146,6 @@ files:
|
|
146
146
|
- lib/arrest/attributes/polymorphic_attribute.rb
|
147
147
|
- lib/arrest/exceptions.rb
|
148
148
|
- lib/arrest/handler.rb
|
149
|
-
- lib/arrest/helper/child_collection.rb
|
150
149
|
- lib/arrest/helper/filter.rb
|
151
150
|
- lib/arrest/helper/has_many.rb
|
152
151
|
- lib/arrest/helper/has_many_collection.rb
|
@@ -155,7 +154,6 @@ files:
|
|
155
154
|
- lib/arrest/helper/logger.rb
|
156
155
|
- lib/arrest/helper/ordered_collection.rb
|
157
156
|
- lib/arrest/nested_resource.rb
|
158
|
-
- lib/arrest/rest_child.rb
|
159
157
|
- lib/arrest/root_resource.rb
|
160
158
|
- lib/arrest/single_resource.rb
|
161
159
|
- lib/arrest/transport/http_source.rb
|
@@ -1,45 +0,0 @@
|
|
1
|
-
module Arrest
|
2
|
-
class ChildCollection #< BasicObject
|
3
|
-
def initialize parent, clazz_name
|
4
|
-
@parent = parent
|
5
|
-
@clazz_name = clazz_name
|
6
|
-
@children = nil
|
7
|
-
end
|
8
|
-
|
9
|
-
def build attributes = {}
|
10
|
-
resolved_class.new(@parent.context, @parent, attributes)
|
11
|
-
end
|
12
|
-
|
13
|
-
def method_missing(*args, &block)
|
14
|
-
if resolved_class.respond_to?(args[0])
|
15
|
-
sub_args = [@parent]
|
16
|
-
sub_args += args.drop(1)
|
17
|
-
resolved_class.send(args[0], *sub_args)
|
18
|
-
else
|
19
|
-
children.send(*args, &block)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def inspect
|
24
|
-
children.inspect
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
|
30
|
-
def children
|
31
|
-
if @children == nil
|
32
|
-
@children = resolved_class.all_for(@parent)
|
33
|
-
end
|
34
|
-
@children
|
35
|
-
end
|
36
|
-
|
37
|
-
def resolved_class
|
38
|
-
if @clazz == nil
|
39
|
-
@clazz = Source.mod.const_get(@clazz_name)
|
40
|
-
end
|
41
|
-
@clazz
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
data/lib/arrest/rest_child.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
module Arrest
|
2
|
-
class RestChild < AbstractResource
|
3
|
-
attr_accessor :parent
|
4
|
-
def initialize context, parent, h
|
5
|
-
super(context,h)
|
6
|
-
@parent = parent
|
7
|
-
end
|
8
|
-
|
9
|
-
class << self
|
10
|
-
# class method to generate path to a child resource of aonther resource
|
11
|
-
def resource_path_for parent
|
12
|
-
"#{parent.resource_location}/#{self.resource_name}"
|
13
|
-
end
|
14
|
-
|
15
|
-
def scoped_path_for parent, scope_name
|
16
|
-
(resource_path_for parent) + '/' + scope_name.to_s
|
17
|
-
end
|
18
|
-
|
19
|
-
def build(parent, hash)
|
20
|
-
self.new(parent.context, parent, hash)
|
21
|
-
end
|
22
|
-
|
23
|
-
def all_for(parent)
|
24
|
-
raise "Parent has no id yet" unless parent.id
|
25
|
-
begin
|
26
|
-
body_root(source().get(parent.context, self.resource_path_for(parent))).map do |h|
|
27
|
-
self.build(parent, h)
|
28
|
-
end
|
29
|
-
rescue Arrest::Errors::DocumentNotFoundError
|
30
|
-
[]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def find(context, id)
|
35
|
-
raise "find cannot be executed for child resources - use find_for with a parent"
|
36
|
-
end
|
37
|
-
|
38
|
-
def find_for(context, parent, id)
|
39
|
-
r = source().get(context, "#{self.resource_path_for(parent)}/#{id}")
|
40
|
-
body = body_root(r)
|
41
|
-
self.build(parent, body)
|
42
|
-
end
|
43
|
-
|
44
|
-
def filter name, &aproc
|
45
|
-
if aproc != nil
|
46
|
-
send :define_singleton_method, name do |*args|
|
47
|
-
self.all_for(args[0]).select do |instance|
|
48
|
-
instance.instance_exec(*(args.drop(1)), &aproc)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
else
|
52
|
-
raise "You must specify a block for a filter"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def scope(name, &block)
|
57
|
-
super name
|
58
|
-
if block_given?
|
59
|
-
send :define_singleton_method, name do |parent|
|
60
|
-
self.all_for(parent).select &block
|
61
|
-
end
|
62
|
-
else
|
63
|
-
send :define_singleton_method, name do |parent|
|
64
|
-
raise "Parent has no id yet" unless parent.id
|
65
|
-
body_root(source().get(parent.context, self.scoped_path_for(parent, name))).map do |h|
|
66
|
-
self.build(parent, h)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# instance method to generate path to a child resource of another resource
|
75
|
-
def resource_path
|
76
|
-
self.class.resource_path_for @parent
|
77
|
-
end
|
78
|
-
|
79
|
-
# unique url for one instance of this class
|
80
|
-
def resource_location
|
81
|
-
"#{self.class.resource_path}/#{self.id.to_s}"
|
82
|
-
end
|
83
|
-
|
84
|
-
def unstub
|
85
|
-
return unless @stub
|
86
|
-
raise "stubbing for child resource isnt supported yet"
|
87
|
-
end
|
88
|
-
|
89
|
-
protected
|
90
|
-
def internal_reload
|
91
|
-
@parent.reload
|
92
|
-
self.class.find_for(self.context, self.parent, self.id).to_hash
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
|