Class: ApiClient::Resource::Base
Instance Attribute Summary
#default_scopes
#connection_hooks
Class Method Summary
collapse
Instance Method Summary
collapse
delegate
dsl_accessor
Methods inherited from Base
#id, #inspect, parse, subkey_class
#inherited
#build, #build_many, #build_one, extended
#always, #scope, #scope_in_thread, #scope_thread_attribute_name, #scoped
#connection
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class ApiClient::Base
Class Method Details
.inherited(subclass) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/api_client/resource/base.rb', line 15
def inherited(subclass)
super
small_name = NameResolver.resolve(subclass.name)
subclass.namespace small_name
subclass.prefix self.prefix
subclass.always do
name = small_name
pre_fix = prefix
path ["", prefix, "#{name}s"].compact.join('/')
end
end
|
.scope(options = {}) ⇒ Object
27
28
29
|
# File 'lib/api_client/resource/base.rb', line 27
def scope(options = {})
scope_in_thread || ApiClient::Resource::Scope.new(self).params(options)
end
|
Instance Method Details
#destroy ⇒ Object
41
42
43
|
# File 'lib/api_client/resource/base.rb', line 41
def destroy
get_scope.destroy(self.id)
end
|
#get_scope ⇒ Object
59
60
61
|
# File 'lib/api_client/resource/base.rb', line 59
def get_scope
original_scope || self.class
end
|
#payload ⇒ Object
45
46
47
48
49
|
# File 'lib/api_client/resource/base.rb', line 45
def payload
hash = self.to_hash
hash.delete('id') hash
end
|
#persisted? ⇒ Boolean
33
34
35
|
# File 'lib/api_client/resource/base.rb', line 33
def persisted?
!!self.id
end
|
#remote_create ⇒ Object
55
56
57
|
# File 'lib/api_client/resource/base.rb', line 55
def remote_create
get_scope.create(payload)
end
|
#remote_update ⇒ Object
51
52
53
|
# File 'lib/api_client/resource/base.rb', line 51
def remote_update
get_scope.update(self.id, payload)
end
|
#save ⇒ Object
37
38
39
|
# File 'lib/api_client/resource/base.rb', line 37
def save
self.persisted? ? remote_update : remote_create
end
|