Module: AssociationMethods

Defined in:
lib/interview/association_methods.rb

Instance Method Summary collapse

Instance Method Details

#define_readersObject

todo: überarbeiten



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

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



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

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