Class: ROM::Mapping::Definition
- Inherits:
-
Object
- Object
- ROM::Mapping::Definition
- Includes:
- Adamantium::Flat
- Defined in:
- lib/rom/mapping/definition.rb
Overview
Mapping definition DSL
Class Method Summary collapse
-
.build(header, &block) ⇒ Object
private
Build new mapping definition.
Instance Method Summary collapse
- #header ⇒ Object private
-
#initialize(header, &block) ⇒ undefined
constructor
private
Initialize a new Definition instance.
-
#map(*args) ⇒ Definition
Configure attribute mappings.
-
#mapper(mapper = Undefined) ⇒ Object
Get or set mapper.
-
#model(model = Undefined) ⇒ Class
Get or set model for the mapper.
Constructor Details
#initialize(header, &block) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a new Definition instance
27 28 29 30 31 32 33 34 35 |
# File 'lib/rom/mapping/definition.rb', line 27 def initialize(header, &block) @header = header @mapping = {} @attributes = Set.new instance_eval(&block) build_mapper unless mapper end |
Class Method Details
.build(header, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Build new mapping definition
18 19 20 |
# File 'lib/rom/mapping/definition.rb', line 18 def self.build(header, &block) new(header, &block) end |
Instance Method Details
#header ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 |
# File 'lib/rom/mapping/definition.rb', line 38 def header @header.project(attributes + Set[*mapping.keys]) end |
#map(*args) ⇒ Definition
Configure attribute mappings
105 106 107 108 109 110 111 112 113 |
# File 'lib/rom/mapping/definition.rb', line 105 def map(*args) = args.last if .kind_of?(Hash) mapping.update(args.first => [:to]) else @attributes += Set[*args] end end |