Class: NestedRecord::Setup::HasMany

Inherits:
NestedRecord::Setup show all
Defined in:
lib/nested_record/setup.rb

Instance Method Summary collapse

Methods inherited from NestedRecord::Setup

#record_class

Constructor Details

#initializeHasMany

Returns a new instance of HasMany.



50
51
52
53
54
55
# File 'lib/nested_record/setup.rb', line 50

def initialize(*)
  super
  if (attributes_writer_opts = @options[:attributes_writer]).is_a? Hash
    @reject_if_proc = attributes_writer_opts[:reject_if]
  end
end

Instance Method Details

#collection_classObject



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/nested_record/setup.rb', line 65

def collection_class
  return @owner.const_get(collection_class_name, false) if @owner.const_defined?(collection_class_name, false)
  extension = @extension
  collection_superclass = record_class.collection_class
  @owner.const_set(
    collection_class_name,
    Class.new(collection_superclass) do
      @record_class = collection_superclass.record_class
      include Module.new(&extension) if extension
    end
  )
end

#collection_class_nameObject



61
62
63
# File 'lib/nested_record/setup.rb', line 61

def collection_class_name
  @collection_class_name ||= :"NestedRecord_Many#{@name.to_s.camelize}"
end

#reject?(attributes) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/nested_record/setup.rb', line 78

def reject?(attributes)
  @reject_if_proc&.call(attributes)
end

#typeObject



57
58
59
# File 'lib/nested_record/setup.rb', line 57

def type
  @type ||= NestedRecord::Type::HasMany.new(self)
end