Class: NestedRecord::Setup
- Inherits:
-
Object
- Object
- NestedRecord::Setup
- Defined in:
- lib/nested_record/setup.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#primary_key ⇒ Object
readonly
Returns the value of attribute primary_key.
-
#reject_if_proc ⇒ Object
readonly
Returns the value of attribute reject_if_proc.
Instance Method Summary collapse
- #attributes_writer_strategy ⇒ Object
-
#initialize(owner, name, **options, &block) ⇒ Setup
constructor
A new instance of Setup.
- #primary_check(type) ⇒ Object
- #record_class ⇒ Object
Constructor Details
#initialize(owner, name, **options, &block) ⇒ Setup
Returns a new instance of Setup.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/nested_record/setup.rb', line 6 def initialize(owner, name, **, &block) @options = @owner = owner @name = name setup_association_attribute setup_record_class(&block) setup_attributes_writer_opts setup_methods_extension end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/nested_record/setup.rb', line 4 def name @name end |
#primary_key ⇒ Object (readonly)
Returns the value of attribute primary_key.
4 5 6 |
# File 'lib/nested_record/setup.rb', line 4 def primary_key @primary_key end |
#reject_if_proc ⇒ Object (readonly)
Returns the value of attribute reject_if_proc.
4 5 6 |
# File 'lib/nested_record/setup.rb', line 4 def reject_if_proc @reject_if_proc end |
Instance Method Details
#attributes_writer_strategy ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/nested_record/setup.rb', line 36 def attributes_writer_strategy return unless @options.fetch(:attributes_writer) { true } case (strategy = @attributes_writer_opts.fetch(:strategy) { :upsert }) when :rewrite, :upsert return strategy else raise NestedRecord::ConfigurationError, "Unknown strategy #{strategy.inspect}" end end |
#primary_check(type) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/nested_record/setup.rb', line 47 def primary_check(type) if (pkey_attributes = primary_key) klass = record_class else klass = record_class.find_subtype(type) while !(pkey_attributes = klass.primary_key) && (klass < NestedRecord::Base) klass = klass.superclass end end # TODO: cache this NestedRecord::PrimaryKeyCheck.new(klass, pkey_attributes) if pkey_attributes end |
#record_class ⇒ Object
17 18 19 20 21 22 |
# File 'lib/nested_record/setup.rb', line 17 def record_class if @record_class.is_a? String @record_class = NestedRecord.lookup_const(@owner, @record_class) end @record_class end |