Module: Prim::ClassMethods
- Includes:
- Helpers
- Defined in:
- lib/prim.rb
Instance Method Summary collapse
-
#has_primary(name, options = {}) ⇒ Object
TODO: allow multiple singular names in one call.
Methods included from Helpers
Instance Method Details
#has_primary(name, options = {}) ⇒ Object
TODO: allow multiple singular names in one call.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/prim.rb', line 19 def has_primary name, = {} singular_name = name.to_sym association_name = plural_sym(singular_name) self.prim_relationships = self.prim_relationships.try(:dup) || Hash.new self.prim_relationships[ singular_name ] = Prim::Relationship.new(association_name, self, ) # Store this configuration for global access. Prim.configured_primaries << self.prim_relationships[ singular_name ] define_method "primary_#{ singular_name }" do prim_collection_for(singular_name).primary end define_method "primary_#{ singular_name }=" do |instance| prim_collection_for(singular_name).primary = instance end end |