Sha256: 06a44efac50ecc0e822122892dee1e634609cdfa0a5d5cb228d424165fd9fb21
Contents?: true
Size: 973 Bytes
Versions: 18
Compression:
Stored size: 973 Bytes
Contents
module Superstore module BelongsTo class Builder def self.build(model, name, options) new(model, name, options).build end attr_reader :model, :name, :options def initialize(model, name, options) @model, @name, @options = model, name, options end def build define_writer define_reader reflection = Superstore::BelongsTo::Reflection.new(model, name, options) model.belongs_to_reflections = model.belongs_to_reflections.merge(name => reflection) end def mixin model.generated_belongs_to_methods end def define_writer name = self.name mixin.redefine_method("#{name}=") do |records| belongs_to_association(name).writer(records) end end def define_reader name = self.name mixin.redefine_method(name) do belongs_to_association(name).reader end end end end end
Version data entries
18 entries across 18 versions & 1 rubygems