Class: Datamappify::Data::Mapper::Attribute
- Inherits:
-
Object
- Object
- Datamappify::Data::Mapper::Attribute
- Defined in:
- lib/datamappify/data/mapper/attribute.rb
Overview
Represents an entity attribute and its associated data source
Instance Attribute Summary collapse
-
#key ⇒ Symbol
readonly
Same as name, but in symbol.
- #name ⇒ String readonly
- #provider_name ⇒ String readonly
- #source_attribute_name ⇒ String readonly
- #source_class_name ⇒ String readonly
- #value ⇒ any
Instance Method Summary collapse
-
#initialize(name, source) ⇒ Attribute
constructor
A new instance of Attribute.
-
#parse_source(source) ⇒ Array<String>
private
An array with provider name, source class name and source attribute name.
- #primary_key? ⇒ Boolean
- #source_class ⇒ Class
Constructor Details
#initialize(name, source) ⇒ Attribute
Returns a new instance of Attribute.
32 33 34 35 36 37 |
# File 'lib/datamappify/data/mapper/attribute.rb', line 32 def initialize(name, source) @key = name @name = name.to_s @provider_name, @source_class_name, @source_attribute_name = parse_source(source) end |
Instance Attribute Details
#key ⇒ Symbol (readonly)
Same as name, but in symbol
9 10 11 |
# File 'lib/datamappify/data/mapper/attribute.rb', line 9 def key @key end |
#name ⇒ String (readonly)
12 13 14 |
# File 'lib/datamappify/data/mapper/attribute.rb', line 12 def name @name end |
#provider_name ⇒ String (readonly)
15 16 17 |
# File 'lib/datamappify/data/mapper/attribute.rb', line 15 def provider_name @provider_name end |
#source_attribute_name ⇒ String (readonly)
21 22 23 |
# File 'lib/datamappify/data/mapper/attribute.rb', line 21 def source_attribute_name @source_attribute_name end |
#source_class_name ⇒ String (readonly)
18 19 20 |
# File 'lib/datamappify/data/mapper/attribute.rb', line 18 def source_class_name @source_class_name end |
#value ⇒ any
24 25 26 |
# File 'lib/datamappify/data/mapper/attribute.rb', line 24 def value @value end |
Instance Method Details
#parse_source(source) ⇒ Array<String> (private)
Returns an array with provider name, source class name and source attribute name.
53 54 55 56 57 |
# File 'lib/datamappify/data/mapper/attribute.rb', line 53 def parse_source(source) provider_name, source_class_and_attribute = source.split('::') [provider_name, *source_class_and_attribute.split('#')] end |
#primary_key? ⇒ Boolean
45 46 47 |
# File 'lib/datamappify/data/mapper/attribute.rb', line 45 def primary_key? source_attribute_name == 'id' end |
#source_class ⇒ Class
40 41 42 |
# File 'lib/datamappify/data/mapper/attribute.rb', line 40 def source_class @source_class ||= Record.find_or_build(provider_name, source_class_name) end |