Class: DataShift::Headers
- Inherits:
-
Object
- Object
- DataShift::Headers
- Extended by:
- Forwardable
- Defined in:
- lib/datashift/headers.rb
Overview
Acts as an array
Instance Attribute Summary collapse
-
#idx ⇒ Object
readonly
Row Index.
-
#source ⇒ Object
Returns the value of attribute source.
Class Method Summary collapse
- .klass_to_operators(klass) ⇒ Object (also: klass_to_headers)
Instance Method Summary collapse
- #add(source, presentation: nil) ⇒ Object
- #association_to_headers(model_method) ⇒ Object
-
#class_source_to_operators ⇒ Object
(also: #class_source_to_headers)
Helpers for dealing with source = class, usually an Active Record model Catalogs the supplied Klass and builds set of expected/valid method calls (operators) for Klass from sll the available method calls on class These can be used to infer an operator to call from an inbound header or provide mapping to an internal method from an external header.
-
#initialize(source, idx = 0, headers = []) ⇒ Headers
constructor
A new instance of Headers.
- #row_index ⇒ Object
- #sources ⇒ Object
Constructor Details
#initialize(source, idx = 0, headers = []) ⇒ Headers
Returns a new instance of Headers.
29 30 31 32 33 |
# File 'lib/datashift/headers.rb', line 29 def initialize(source, idx = 0, headers = []) @source = source @idx = idx @headers = headers end |
Instance Attribute Details
#idx ⇒ Object (readonly)
Row Index
23 24 25 |
# File 'lib/datashift/headers.rb', line 23 def idx @idx end |
#source ⇒ Object
Returns the value of attribute source.
20 21 22 |
# File 'lib/datashift/headers.rb', line 20 def source @source end |
Class Method Details
.klass_to_operators(klass) ⇒ Object Also known as: klass_to_headers
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/datashift/headers.rb', line 45 def klass_to_operators(klass) headers = Headers.new(klass) headers.class_source_to_headers DataShift::Transformation::Remove.new.unwanted_headers(headers) headers end |
Instance Method Details
#add(source, presentation: nil) ⇒ Object
103 104 105 |
# File 'lib/datashift/headers.rb', line 103 def add(source, presentation: nil) @headers << Header.new(source: source, presentation: presentation) end |
#association_to_headers(model_method) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/datashift/headers.rb', line 90 def association_to_headers( model_method ) configuration = DataShift::Configuration.call if(configuration.) model_method.association_columns.each do |c| add "#{model_method.operator}::#{c.name}" end else add model_method.operator end end |
#class_source_to_operators ⇒ Object Also known as: class_source_to_headers
Helpers for dealing with source = class, usually an Active Record model Catalogs the supplied Klass and builds set of expected/valid method calls (operators) for Klass from sll the available method calls on class These can be used to infer an operator to call from an inbound header or provide mapping to an internal method from an external header
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/datashift/headers.rb', line 65 def class_source_to_operators raise SourceIsNotAClass, 'Cannot parse source for headers - source must be a Class' unless source.is_a?(Class) # TODO: This collection can now be sorted collection = ModelMethods::Manager.catalog_class(source) configuration = DataShift::Configuration.call if collection collection.each do |mm| next if(DataShift::Transformation::Remove.new.association?(mm)) next unless configuration.op_type_in_scope?(mm) if(mm.association_type?) association_to_headers(mm) else add mm.operator end end end end |
#row_index ⇒ Object
111 112 113 |
# File 'lib/datashift/headers.rb', line 111 def row_index idx end |
#sources ⇒ Object
107 108 109 |
# File 'lib/datashift/headers.rb', line 107 def sources @headers.collect(&:source) end |