class ProntoForms::Resource
Base class for resource-related classes.
Attributes
client[R]
@return [Client] API client
data[R]
@return [Hash] Retrieve raw JSON data associated with this resource
parent[R]
@return [Resource] Parent object (applicable to child resources)
Public Class Methods
new(data, client, parent = nil)
click to toggle source
# File lib/prontoforms/resource.rb, line 29 def initialize(data, client, parent = nil) @data = data @client = client @parent = parent end
property(name, key: nil, &block)
click to toggle source
Defines a property of the resource @return [nil] @api private
# 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()
click to toggle source
The resource's identifier
# File lib/prontoforms/resource.rb, line 36 def self.resource_name name = to_s.split('::').last "#{name.downcase}s" end
Public Instance Methods
resource_name()
click to toggle source
The resource's identifier
# File lib/prontoforms/resource.rb, line 42 def resource_name self.class.resource_name end