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.
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_class ⇒ Object
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_name ⇒ Object
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
78 79 80 |
# File 'lib/nested_record/setup.rb', line 78 def reject?(attributes) @reject_if_proc&.call(attributes) end |
#type ⇒ Object
57 58 59 |
# File 'lib/nested_record/setup.rb', line 57 def type @type ||= NestedRecord::Type::HasMany.new(self) end |