Module: Chargify::Behaviors::Metadata::ClassMethods

Defined in:
lib/chargify_api_ares/behaviors/metadata.rb

Instance Method Summary collapse

Instance Method Details

#endpoint_name=(name) ⇒ Object



41
42
43
44
# File 'lib/chargify_api_ares/behaviors/metadata.rb', line 41

def endpoint_name=(name)
  (class << self; self; end).send(:define_method, :resource)     do;  name; end
  (class << self; self; end).send(:define_method, :element_name) do;  name; end
end

#instantiate_collection(collection, prefix_options = {}) ⇒ Object



46
47
48
# File 'lib/chargify_api_ares/behaviors/metadata.rb', line 46

def instantiate_collection(collection, prefix_options = {})
  collection[self.resource].collect! { |record| instantiate_record(record, prefix_options) }
end

#instantiate_record(record, prefix_options = {}) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/chargify_api_ares/behaviors/metadata.rb', line 50

def instantiate_record(record, prefix_options = {})
  record = record.is_a?(Array) ? record.first : record
  new(record, true).tap do |resource|
    resource.prefix_options = prefix_options
    resource.current_name   = resource.name
  end
end