Class: Gorillib::Model::SimpleCollectionField
- Defined in:
- lib/gorillib/model/field.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#item_type ⇒ Class
The item_type field field :item_type, Class, default: Whatever, doc: "Factory for collection items".
Attributes inherited from Field
#_extra_attributes, #doc, #model, #name, #type
Instance Method Summary collapse
-
#initialize(model, name, type, options = {}) ⇒ SimpleCollectionField
constructor
field :collection_attrs, Hash, default: Hash.new, doc: "Extra attributes to pass to the collection on creation -- eg.
- #inscribe_methods(model) ⇒ Object
Methods inherited from Field
#==, #inspect, #inspect_compact, receive, #to_hash, #to_s, #visibility
Methods included from Gorillib::Model
#==, #as_json, #attribute_set?, #attribute_values, #attributes, #compact_attributes, #handle_extra_attributes, #inspect, #inspect_compact, #read_attribute, #read_unset_attribute, #receive!, #to_inspectable, #to_json, #to_s, #to_tsv, #to_wire, #unset_attribute, #update_attributes, #write_attribute
Methods included from Concern
#append_features, extended, #included
Constructor Details
#initialize(model, name, type, options = {}) ⇒ SimpleCollectionField
field :collection_attrs, Hash, default: Hash.new, doc: "Extra attributes to pass to the collection on creation -- eg. key_method"
136 137 138 139 140 141 142 143 |
# File 'lib/gorillib/model/field.rb', line 136 def initialize(model, name, type, ={}) super collection_type = self.type item_type = self.item_type key_method = [:key_method] if [:key_method] raise "Please supply an item type for #{self.inspect} -- eg 'collection #{name.inspect}, of: FooClass'" unless item_type self.default ||= ->{ collection_type.new(item_type: item_type, belongs_to: self, key_method: key_method) } end |
Instance Attribute Details
Instance Method Details
#inscribe_methods(model) ⇒ Object
145 146 147 148 |
# File 'lib/gorillib/model/field.rb', line 145 def inscribe_methods(model) super model.__send__(:define_collection_receiver, self) end |