Module: RocketGate::Hashable::ClassMethods

Defined in:
lib/rocketgate/hashable.rb

Instance Method Summary collapse

Instance Method Details

#hashable(mapping_hash, *mergable_items) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rocketgate/hashable.rb', line 3

def hashable(mapping_hash, *mergable_items)
  @mappings, @mergables = {}, []

  mapping_hash.each do |display_name, obj|
    if self.new.send(:is_callable?, obj)
      @mappings[display_name] = obj
    else
      raise RocketGate::ValidationError.new("Invalid attribute: #{obj}")
    end
  end

  mergable_items.each do |obj|
    if self.new.send(:is_callable?, obj)
      @mergables << obj
    else
      raise RocketGate::ValidationError.new("Invalid attribute: #{obj}")
    end
  end
end

#mappingsObject



23
24
25
# File 'lib/rocketgate/hashable.rb', line 23

def mappings
  @mappings ||= {}
end

#mergablesObject



27
28
29
# File 'lib/rocketgate/hashable.rb', line 27

def mergables
  @mergables ||= []
end