Class: ActiveMerge::SimpleService::Links

Inherits:
Object
  • Object
show all
Defined in:
lib/active_merge/simple_service.rb

Overview

Initializes a hash, whose keys are instances linked to given one, and their values are names of methods for linking to another object.

Class Method Summary collapse

Class Method Details

.hashObject



56
57
58
59
60
61
62
# File 'lib/active_merge/simple_service.rb', line 56

def hash
  @hash = {}
  refs.each do |name, foreign_key|
    @item.send(name).each{ |item| @hash[item] = "#{ foreign_key }=" }
  end
  @hash
end

.new(item) ⇒ Object



44
45
46
47
# File 'lib/active_merge/simple_service.rb', line 44

def new(item)
  @item = item
  return hash
end

.refsObject

Returns a hash whose keys are “has_many” associations’ names and their values are corresponding foreign keys



51
52
53
54
# File 'lib/active_merge/simple_service.rb', line 51

def refs
  @item.class.reflect_on_all_associations(:has_many).
    inject({}){ |hash, item| hash.merge(item.name => item.foreign_key) }
end