Sha256: 1ec59c4e0d47aae508963bdbd70764cb3b31c6d39fcdd89019d3014749a56e29
Contents?: true
Size: 1.22 KB
Versions: 33
Compression:
Stored size: 1.22 KB
Contents
module ActiveFedora::Associations::Builder class Association #:nodoc: class_attribute :valid_options self.valid_options = [:class_name, :property] # Set by subclasses class_attribute :macro attr_reader :model, :name, :options, :reflection, :mixin def self.build(model, name, options) new(model, name, options).build end def initialize(model, name, options) @model, @name, @options = model, name, options @mixin = Module.new @model.__send__(:include, @mixin) end def build validate_options reflection = model.create_reflection(self.class.macro, name, options, model) define_accessors reflection end private def validate_options options.assert_valid_keys(self.class.valid_options) end def define_accessors define_readers define_writers end def define_readers name = self.name mixin.send(:define_method, name) do |*params| association(name).reader(*params) end end def define_writers name = self.name mixin.send(:define_method, "#{name}=") do |value| association(name).writer(value) end end end end
Version data entries
33 entries across 33 versions & 1 rubygems