Class: ProntoForms::Resource
- Inherits:
-
Object
- Object
- ProntoForms::Resource
- Defined in:
- lib/prontoforms/resource.rb
Overview
Base class for resource-related classes.
Direct Known Subclasses
Document, Form, FormIteration, FormSpace, FormSubmission, ResourceList, User
Instance Attribute Summary collapse
-
#client ⇒ Client
readonly
API client.
-
#data ⇒ Hash
readonly
Retrieve raw JSON data associated with this resource.
-
#parent ⇒ Resource
readonly
Parent object (applicable to child resources).
Class Method Summary collapse
-
.property(name, key: nil, &block) ⇒ nil
private
Defines a property of the resource.
-
.resource_name ⇒ Object
The resource’s identifier.
Instance Method Summary collapse
-
#initialize(data, client, parent = nil) ⇒ Resource
constructor
A new instance of Resource.
-
#resource_name ⇒ Object
The resource’s identifier.
Constructor Details
#initialize(data, client, parent = nil) ⇒ Resource
Returns a new instance of Resource.
29 30 31 32 33 |
# File 'lib/prontoforms/resource.rb', line 29 def initialize(data, client, parent = nil) @data = data @client = client @parent = parent end |
Instance Attribute Details
#client ⇒ Client (readonly)
Returns API client.
11 12 13 |
# File 'lib/prontoforms/resource.rb', line 11 def client @client end |
#data ⇒ Hash (readonly)
Returns Retrieve raw JSON data associated with this resource.
9 10 11 |
# File 'lib/prontoforms/resource.rb', line 9 def data @data end |
#parent ⇒ Resource (readonly)
Returns Parent object (applicable to child resources).
13 14 15 |
# File 'lib/prontoforms/resource.rb', line 13 def parent @parent end |
Class Method Details
.property(name, key: nil, &block) ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Defines a property of the resource
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/prontoforms/resource.rb', line 18 def self.property(name, key: nil, &block) define_method(name) do if block_given? instance_eval(&block) elsif !key.nil? key = [key] unless key.is_a?(Array) key.inject(data) { |obj, k| obj.fetch(k) } end end end |
.resource_name ⇒ Object
The resource’s identifier
36 37 38 39 |
# File 'lib/prontoforms/resource.rb', line 36 def self.resource_name name = to_s.split('::').last "#{name.downcase}s" end |
Instance Method Details
#resource_name ⇒ Object
The resource’s identifier
42 43 44 |
# File 'lib/prontoforms/resource.rb', line 42 def resource_name self.class.resource_name end |