Module: Sumaki::Model::Fields::AccessorAdder

Defined in:
lib/sumaki/model/fields.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.add(methods_module, reflections, reflection) ⇒ Object



36
37
38
39
40
41
# File 'lib/sumaki/model/fields.rb', line 36

def add(methods_module, reflections, reflection)
  add_getter(methods_module, reflection.name)
  add_setter(methods_module, reflection.name)

  reflections[reflection.name] = reflection
end

.add_getter(methods_module, field_name) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/sumaki/model/fields.rb', line 43

def add_getter(methods_module, field_name)
  methods_module.module_eval <<~RUBY, __FILE__, __LINE__ + 1
    def #{field_name}                      # def title
      field_accessor.get(:'#{field_name}') #   field_accessor.get(:'title')
    end                                    # end
  RUBY
end

.add_setter(methods_module, field_name) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/sumaki/model/fields.rb', line 51

def add_setter(methods_module, field_name)
  methods_module.module_eval <<~RUBY, __FILE__, __LINE__ + 1
    def #{field_name}=(value)                     # def title=(value)
      field_accessor.set(:'#{field_name}', value) #   field_accessor.set(:'title', value)
    end                                           # end
  RUBY
end