Module: AssociationMethods

Included in:
ActiveRecord::Associations::Builder::CollectionAssociation
Defined in:
lib/interview/association_methods.rb

Instance Method Summary collapse

Instance Method Details

#define_readersObject



3
4
5
6
7
8
9
10
# File 'lib/interview/association_methods.rb', line 3

def define_readers
  super
  mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
    def #{name}_human_ids_string
      return self.#{name}.human_ids.join(', ')
    end
  CODE
end

#define_writersObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/interview/association_methods.rb', line 12

def define_writers
  super
  mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
    def #{name}_human_ids_string=(string)
      human_ids = string.split /, */
      #{name} = human_ids.map { |human_id| self.#{name}.klass.find_by_human_id(human_id) }
      self.#{name} = #{name}
    end
  CODE
end