class NestedRecord::Methods

Public Class Methods

new(setup) click to toggle source
# File lib/nested_record/methods.rb, line 2
def initialize(setup)
  @setup = setup
end

Public Instance Methods

attributes_writer_method_name() click to toggle source
# File lib/nested_record/methods.rb, line 41
def attributes_writer_method_name
  :"#{@setup.name}_attributes="
end
define(name) click to toggle source
# File lib/nested_record/methods.rb, line 6
  def define(name)
    method_name = public_send("#{name}_method_name")
    method_body = (bodym = public_method("#{name}_method_body")).call
    case method_body
    when Proc
      define_method(method_name, &method_body)
    when String
      location = bodym.source_location
      location[1] += 1
      module_eval <<~RUBY, *location
        def #{method_name}
          #{method_body}
        end
      RUBY
    else
      fail
    end
  end
define_attributes_writer_method() click to toggle source
# File lib/nested_record/methods.rb, line 45
def define_attributes_writer_method
  case @setup.attributes_writer_strategy
  when :rewrite
    alias_method attributes_writer_method_name, rewrite_attributes_method_name
  when :upsert
    alias_method attributes_writer_method_name, upsert_attributes_method_name
  end
end
reader_method_name() click to toggle source
# File lib/nested_record/methods.rb, line 25
def reader_method_name
  @setup.name
end
rewrite_attributes_method_name() click to toggle source
# File lib/nested_record/methods.rb, line 37
def rewrite_attributes_method_name
  :"rewrite_#{@setup.name}_attributes"
end
upsert_attributes_method_name() click to toggle source
# File lib/nested_record/methods.rb, line 33
def upsert_attributes_method_name
  :"upsert_#{@setup.name}_attributes"
end
writer_method_name() click to toggle source
# File lib/nested_record/methods.rb, line 29
def writer_method_name
  :"#{@setup.name}="
end