Class: ApplicationSeeds::Attributes

Inherits:
ActiveSupport::HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/application_seeds/attributes.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Attributes

Returns a new instance of Attributes.



6
7
8
# File 'lib/application_seeds/attributes.rb', line 6

def initialize(attributes)
  super(attributes.with_indifferent_access)
end

Instance Method Details

#map_attributes(mapping) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/application_seeds/attributes.rb', line 20

def map_attributes(mapping)
  mapping = mapping.with_indifferent_access
  mapped  = inject({}) do |hash, (k, v)|
    mapped_key = mapping.fetch(k) { k }
    hash.merge!(mapped_key => v)
  end
  Attributes.new(mapped)
end

#reject_attributes(*attribute_names) ⇒ Object



15
16
17
18
# File 'lib/application_seeds/attributes.rb', line 15

def reject_attributes(*attribute_names)
  attribute_names.map!(&:to_s)
  Attributes.new(reject { |k, v| attribute_names.include?(k) })
end

#select_attributes(*attribute_names) ⇒ Object



10
11
12
13
# File 'lib/application_seeds/attributes.rb', line 10

def select_attributes(*attribute_names)
  attribute_names.map!(&:to_s)
  Attributes.new(select { |k, v| attribute_names.include?(k) })
end