Module: LittleMapper::DslClassMethods
- Defined in:
- lib/little_mapper/dsl_class_methods.rb
Instance Method Summary collapse
- #add_mapping(m) ⇒ Object
-
#entity(klass = nil) ⇒ Object
Getter/Setter for the Domain Entity to persist.
-
#map(field, opts = {}) ⇒ Object
Add a single mapping.
- #mapping_factory ⇒ Object
- #mapping_factory=(mf) ⇒ Object
- #mappings ⇒ Object
-
#maps(*args) ⇒ Object
Add one or more simple one-to-one mappings.
-
#persistent_entity(klass = nil) ⇒ Object
Getter/Setter for the (Currently ActiveRecord only) class to use for persistence.
Instance Method Details
#add_mapping(m) ⇒ Object
24 25 26 |
# File 'lib/little_mapper/dsl_class_methods.rb', line 24 def add_mapping(m) mappings << m end |
#entity(klass = nil) ⇒ Object
Getter/Setter for the Domain Entity to persist.
5 6 7 8 9 10 11 12 |
# File 'lib/little_mapper/dsl_class_methods.rb', line 5 def entity(klass = nil) if klass.nil? @_entity else @_entity = klass LittleMapper.register(klass, self) end end |
#map(field, opts = {}) ⇒ Object
Add a single mapping.
field - A Symbol, the name of the field to map. opts - A Hash of options to configure the mapper (default: {}):
:as - The Class of Mapper to use to map an entity
value. Can be enclosed in Array notation to
signify a one to many relationship
:to - Name of the field on the persistent entity
to which we will map (default: field)
:entity_setter - a Symbol representing the name of a function
to use when setting the value on the entity
(default: field=)
:entity_collection_adder - in a one-to-many relationship, the name of
of a method to use when adding associated objetcs
(default: to#<<)
Examples
map :metrics, :as => [Metric]
map :owner, :entity_setter => :assign_owner
67 68 69 |
# File 'lib/little_mapper/dsl_class_methods.rb', line 67 def map(field, opts = {}) add_mapping(mapping_factory.map(self, field, opts)) end |
#mapping_factory ⇒ Object
32 33 34 |
# File 'lib/little_mapper/dsl_class_methods.rb', line 32 def mapping_factory @_mapping_factory ||= LittleMapper::MappingFactory.new end |
#mapping_factory=(mf) ⇒ Object
28 29 30 |
# File 'lib/little_mapper/dsl_class_methods.rb', line 28 def mapping_factory=(mf) @_mapping_factory = mf end |
#mappings ⇒ Object
20 21 22 |
# File 'lib/little_mapper/dsl_class_methods.rb', line 20 def mappings @_mappings ||= [] end |
#maps(*args) ⇒ Object
Add one or more simple one-to-one mappings.
args - one or more Symbols. The names of the fields to map.
Examples
maps :first_name, :last_name
43 44 45 |
# File 'lib/little_mapper/dsl_class_methods.rb', line 43 def maps(*args) args.each {|f| map(f)} end |
#persistent_entity(klass = nil) ⇒ Object
Getter/Setter for the (Currently ActiveRecord only) class to use for persistence.
16 17 18 |
# File 'lib/little_mapper/dsl_class_methods.rb', line 16 def persistent_entity(klass = nil) klass.nil? ? @_persistent_entity : @_persistent_entity = klass end |