Module: Schema::ArrayHeaders::ClassMethods

Defined in:
lib/schema/array_headers.rb

Overview

adds methods to the class

Instance Method Summary collapse

Instance Method Details

#get_field_names(mapped_headers, header_prefix = nil, mapped = true) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/schema/array_headers.rb', line 28

def get_field_names(mapped_headers, header_prefix = nil, mapped = true)
  fields = []
  schema.each do |field_name, field_options|
    next if field_options[:alias_of]

    if field_options[:association]
      fields += get_model_field_names(field_name, field_options, mapped_headers, header_prefix, mapped)
    else
      next if skip_field?(field_name, mapped_headers, mapped)

      fields << generate_field_name(field_name, field_options, header_prefix)
    end
  end
  fields
end

#get_mapped_field_names(mapped_headers, header_prefix = nil) ⇒ Object



24
25
26
# File 'lib/schema/array_headers.rb', line 24

def get_mapped_field_names(mapped_headers, header_prefix = nil)
  get_field_names(mapped_headers, header_prefix, true)
end

#get_unmapped_field_names(mapped_headers, header_prefix = nil) ⇒ Object



20
21
22
# File 'lib/schema/array_headers.rb', line 20

def get_unmapped_field_names(mapped_headers, header_prefix = nil)
  get_field_names(mapped_headers, header_prefix, false)
end

#map_headers_to_attributes(headers, header_prefix = nil) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/schema/array_headers.rb', line 12

def map_headers_to_attributes(headers, header_prefix = nil)
  mapped_headers = {}
  map_headers_to_fields(headers, mapped_headers, header_prefix)
  map_headers_to_has_one_associations(headers, mapped_headers, header_prefix)
  map_headers_to_has_many_associations(headers, mapped_headers)
  mapped_headers
end