Class: ROM::Mapper::Header
- Inherits:
-
Object
- Object
- ROM::Mapper::Header
- Includes:
- Adamantium, Enumerable, Morpher::NodeHelpers
- Defined in:
- lib/rom/mapper/header.rb
Overview
Mapper header wrapping axiom header and providing mapping information
Class Method Summary collapse
-
.build(input) ⇒ Object
private
Build a header.
Instance Method Summary collapse
-
#[](name) ⇒ Attribute
Return attribute with the given name.
-
#attribute_names ⇒ Object
private
Return attribute names.
-
#each(&block) ⇒ Object
private
Iterate over attributes.
-
#group(other) ⇒ Object
TODO: this should receive a hash with header objects already.
- #join(other) ⇒ Object private
-
#keys ⇒ Array<Attribute>
Return all key attributes.
-
#mapping ⇒ Object
private
Return attribute mapping.
- #project(names) ⇒ Object private
- #rename(names) ⇒ Object private
- #to_ast ⇒ Object
-
#wrap(other) ⇒ Object
TODO: this should receive a hash with header objects already.
Class Method Details
.build(input) ⇒ 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 a header
17 18 19 20 21 22 23 |
# File 'lib/rom/mapper/header.rb', line 17 def self.build(input) if input.is_a?(self) input else new(input.map { |args| Attribute.build(*args) }) end end |
Instance Method Details
#[](name) ⇒ Attribute
Return attribute with the given name
53 54 55 |
# File 'lib/rom/mapper/header.rb', line 53 def [](name) detect { |attribute| attribute.name == name } || raise(KeyError) end |
#attribute_names ⇒ 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.
Return attribute names
60 61 62 |
# File 'lib/rom/mapper/header.rb', line 60 def attribute_names map(&:name) end |
#each(&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.
Iterate over attributes
67 68 69 70 71 |
# File 'lib/rom/mapper/header.rb', line 67 def each(&block) return to_enum unless block_given? attributes.each(&block) self end |
#group(other) ⇒ Object
TODO: this should receive a hash with header objects already
80 81 82 83 |
# File 'lib/rom/mapper/header.rb', line 80 def group(other) new_attributes = other.map { |name, mapper| mapper.attribute(Attribute::EmbeddedCollection, name) } self.class.new((attributes + new_attributes).uniq) end |
#join(other) ⇒ 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.
86 87 88 |
# File 'lib/rom/mapper/header.rb', line 86 def join(other) self.class.new((attributes + other.attributes).uniq) end |
#keys ⇒ Array<Attribute>
Return all key attributes
38 39 40 |
# File 'lib/rom/mapper/header.rb', line 38 def keys select(&:key?) end |
#mapping ⇒ 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.
Return attribute mapping
28 29 30 |
# File 'lib/rom/mapper/header.rb', line 28 def mapping each_with_object({}) { |attribute, hash| hash.update(attribute.mapping) } end |
#project(names) ⇒ 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.
91 92 93 |
# File 'lib/rom/mapper/header.rb', line 91 def project(names) self.class.new(select { |attribute| names.include?(attribute.tuple_key) }) end |
#rename(names) ⇒ 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.
96 97 98 |
# File 'lib/rom/mapper/header.rb', line 96 def rename(names) self.class.new(map { |attribute| names[attribute.name] ? attribute.rename(names[attribute.name]) : attribute }) end |
#to_ast ⇒ Object
43 44 45 |
# File 'lib/rom/mapper/header.rb', line 43 def to_ast s(:hash_transform, *map(&:to_ast)) end |
#wrap(other) ⇒ Object
TODO: this should receive a hash with header objects already
74 75 76 77 |
# File 'lib/rom/mapper/header.rb', line 74 def wrap(other) new_attributes = other.map { |name, mapper| mapper.attribute(Attribute::EmbeddedValue, name) } self.class.new((attributes + new_attributes).uniq) end |