Class: Arrest::HasManyCollection

Inherits:
OrderedCollection show all
Defined in:
lib/arrest/helper/has_many_collection.rb

Instance Method Summary collapse

Methods inherited from OrderedCollection

#current_page, #current_page_count, #first_page?, #inspect, #last_page?, #limit, #limit_value, #method_missing, #num_pages, #offset, #offset_value, #order_by, #page, #per, #start_at, #total_count

Constructor Details

#initialize(parent, context, class_or_class_name, base_url, query_params = {}) ⇒ HasManyCollection

Returns a new instance of HasManyCollection.



4
5
6
7
8
# File 'lib/arrest/helper/has_many_collection.rb', line 4

def initialize(parent, context, class_or_class_name, base_url, query_params = {})
  super(context, class_or_class_name, base_url, query_params)
  @parent = parent
  @foreign_key_name = (StringUtils.underscore(@parent.class.name).gsub(/^.*\//, '') + '_id').to_sym
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Arrest::OrderedCollection

Instance Method Details

#build(attributes = {}) ⇒ Object



10
11
12
# File 'lib/arrest/helper/has_many_collection.rb', line 10

def build(attributes = {})
  resolved_class.new(@context, {@foreign_key_name => @parent.id}.merge!(attributes))
end