arusarka-dynamic-active-resource 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/README +26 -24
  2. metadata +1 -1
data/README CHANGED
@@ -74,13 +74,13 @@ end
74
74
  To do the same thing, here's how you do it using this library
75
75
 
76
76
  class Person < DynamicActiveResource::Base
77
- module ClassMethods
77
+ module DynamicClassSingletonMethods
78
78
  def count
79
79
  find(:all).size
80
80
  end
81
81
  end
82
82
 
83
- module InstanceMethods
83
+ module DynamicClassInstanceMethods
84
84
  def occupation
85
85
  return job if job
86
86
  'Unemployed'
@@ -88,24 +88,26 @@ class Person < DynamicActiveResource::Base
88
88
  end
89
89
  end
90
90
 
91
- The instance methods will be available as instance methods in the objects created, class methods
92
- will be available as class methods in the class of the object. Also active resource associations
93
- are sometimes paginated. So even if you use find(:all), you get only the first few results. To
94
- overcome this, include in your ClassMethods module a method called find_without_pagination. In that
95
- method route it to acitve resource find with proper parameters. An example of the method implementation
96
- is
97
-
98
- def find_without_pagination(*args)
99
- scope = args.slice!(0)
100
- options = args.slice!(0) || {}
101
- options[:params] ||= {}
102
- options[:params].merge!({:page => 'all'})
103
- # call ActiveResource::Base::find with proper options
104
- find(scope, options)
91
+ The DynamicClassInstanceMethods will be available as instance methods in the objects created,
92
+ DynamicClassSingletonMethods will be available as class methods in the class of the object. Also
93
+ active resource associations are sometimes paginated. So even if you use find(:all), you get
94
+ only the first few results. To overcome this, include in your DynamicClassSingletonMethods module
95
+ a method called find_without_pagination. In that method route it to acitve resource find with
96
+ proper parameters. An example of the method implementation is
97
+
98
+ module DynamicClassSingletonMethods
99
+ def find_without_pagination(*args)
100
+ scope = args.slice!(0)
101
+ options = args.slice!(0) || {}
102
+ options[:params] ||= {}
103
+ options[:params].merge!({:page => 'all'})
104
+ # call ActiveResource::Base::find with proper options
105
+ find(scope, options)
106
+ end
105
107
  end
106
108
 
107
- The class level find method will automatically pick up this method if defined as a ClassMethod method
108
- else it will pass it to find.
109
+ The class level find method will automatically pick up this method if defined as a method in the
110
+ DynamicClassSingeletonMethod module else it will pass it to find.
109
111
 
110
112
  ASSOCIATIONS
111
113
  ------------
@@ -121,13 +123,13 @@ Taking the example from above the way it should be done
121
123
  class Person < DynamicActiveResource::Base
122
124
  has_many :cars
123
125
 
124
- module ClassMethods
126
+ module DynamicClassSingletonMethods
125
127
  def count
126
128
  find(:all).size
127
129
  end
128
130
  end
129
131
 
130
- module InstanceMethods
132
+ module DynamicClassInstanceMethods
131
133
  def occupation
132
134
  return job if job
133
135
  'Unemployed'
@@ -141,7 +143,7 @@ end
141
143
 
142
144
  Next a car class has to be initialized
143
145
 
144
- class Car < DynARBase (alias for DynamicActiveResource::Base)
146
+ class Car < DynARBase (alias for DynamicActiveResource::Base, inbuilt in the gem)
145
147
  end
146
148
 
147
149
  set resource options only at the top level( Person in this case)
@@ -161,7 +163,7 @@ person = Person.find('asur').cars it will hit the url http://localhost:8080/peop
161
163
  You would notice that its getting the cars for the person with name 'asur'. It does so because
162
164
  in the Person class a method called resource_identifier has been defined which says that the id
163
165
  is actually name instead of the database id. If the id attribute in the xml is set appropriately
164
- (to name in this case) then you do not need to define the method.
166
+ (to 'name' in this case) then you do not need to define the method.
165
167
 
166
168
  2) belongs_to
167
169
  -------------
@@ -171,13 +173,13 @@ Again, referring to the example above
171
173
  class Person < DynamicActiveResource::Base
172
174
  has_many :cars
173
175
 
174
- module ClassMethods
176
+ module DynamicClassSingletonMethods
175
177
  def count
176
178
  find(:all).size
177
179
  end
178
180
  end
179
181
 
180
- module InstanceMethods
182
+ module DynamicClassInstanceMethods
181
183
  def occupation
182
184
  return job if job
183
185
  'Unemployed'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arusarka-dynamic-active-resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - asur