Class: RemoteResource::Base
- Inherits:
-
Object
- Object
- RemoteResource::Base
- Extended by:
- ActiveSupport::DescendantsTracker, BaseClassMethods, Dsl
- Includes:
- Attributes, Rescue
- Defined in:
- lib/remote_resource/base.rb
Overview
the base class for defining an api.
Instance Attribute Summary collapse
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Attributes included from Dsl
Instance Method Summary collapse
- #client ⇒ Object
-
#initialize(**args) ⇒ Base
constructor
A new instance of Base.
- #resource(name = :default, resource_client = nil) ⇒ Object
Methods included from BaseClassMethods
ensure_loaded, find_descendant, symbol_name, underscore
Methods included from Dsl
Methods included from Rescue
Methods included from Attributes
#create_attributes, #get_attribute
Methods included from Notifications
#instrument, #instrument_attribute
Constructor Details
#initialize(**args) ⇒ Base
Returns a new instance of Base.
16 17 18 19 20 |
# File 'lib/remote_resource/base.rb', line 16 def initialize(**args) @scope = args create_attributes(self) AttributeMethodAttacher.new(self.class).attach_to(self.singleton_class) end |
Instance Attribute Details
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
14 15 16 |
# File 'lib/remote_resource/base.rb', line 14 def scope @scope end |
Instance Method Details
#client ⇒ Object
22 23 24 |
# File 'lib/remote_resource/base.rb', line 22 def client self.class.client_proc.call(@scope) end |
#resource(name = :default, resource_client = nil) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/remote_resource/base.rb', line 26 def resource(name = :default, resource_client = nil) if (attr_resource = self.class.resources[name]) attr_resource.call(resource_client || client, @scope) else msg = "there is no resource named `#{name}` on #{self.class.name}." fail ArgumentError, msg end end |