Class: SheetsDB::Collection
- Defined in:
- lib/sheets_db/collection.rb
Instance Attribute Summary
Attributes inherited from Resource
Class Method Summary collapse
Methods inherited from Resource
#==, #base_attributes, belongs_to_many, find_by_id, #hash, inherited, #initialize, register_association, set_resource_type
Constructor Details
This class inherits a constructor from SheetsDB::Resource
Class Method Details
.has_many(resource, class_name:, resource_type: :subcollections) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/sheets_db/collection.rb', line 5 def self.has_many(resource, class_name:, resource_type: :subcollections) unless [:subcollections, :spreadsheets].include?(resource_type) raise ArgumentError, "resource_type must be :subcollections or :spreadsheets" end register_association(resource, class_name: class_name, resource_type: resource_type) define_method(resource) do result = instance_variable_get(:"@#{resource}") result || instance_variable_set(:"@#{resource}", google_drive_resource.send(resource_type).map { |raw| Support.constantize(class_name).new(raw) } ) end end |