Class: NestedRecord::Setup::HasMany
- Inherits:
-
NestedRecord::Setup
- Object
- NestedRecord::Setup
- NestedRecord::Setup::HasMany
- Defined in:
- lib/nested_record/setup.rb
Instance Method Summary collapse
- #collection_class ⇒ Object
- #collection_class_name ⇒ Object
-
#initialize ⇒ HasMany
constructor
A new instance of HasMany.
- #reject?(attributes) ⇒ Boolean
- #type ⇒ Object
Methods inherited from NestedRecord::Setup
Constructor Details
#initialize ⇒ HasMany
Returns a new instance of HasMany.
45 46 47 48 49 50 |
# File 'lib/nested_record/setup.rb', line 45 def initialize(*) super if (attributes_writer_opts = [:attributes_writer]).is_a? Hash @reject_if_proc = attributes_writer_opts[:reject_if] end end |
Instance Method Details
#collection_class ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/nested_record/setup.rb', line 60 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_name ⇒ Object
56 57 58 |
# File 'lib/nested_record/setup.rb', line 56 def collection_class_name @collection_class_name ||= :"NestedRecord_Many#{@name.to_s.camelize}" end |
#reject?(attributes) ⇒ Boolean
73 74 75 |
# File 'lib/nested_record/setup.rb', line 73 def reject?(attributes) @reject_if_proc&.call(attributes) end |
#type ⇒ Object
52 53 54 |
# File 'lib/nested_record/setup.rb', line 52 def type @type ||= NestedRecord::Type::HasMany.new(self) end |