Class: ActsAsRecursiveTree::Config
- Inherits:
-
Object
- Object
- ActsAsRecursiveTree::Config
- Defined in:
- lib/acts_as_recursive_tree/config.rb
Overview
Stores the configuration of one Model class
Instance Attribute Summary collapse
-
#dependent ⇒ Object
readonly
Returns the value of attribute dependent.
-
#depth_column ⇒ Object
readonly
Returns the value of attribute depth_column.
-
#parent_key ⇒ Object
readonly
Returns the value of attribute parent_key.
-
#parent_type_column ⇒ Object
readonly
Returns the value of attribute parent_type_column.
Instance Method Summary collapse
-
#cycle_detection? ⇒ TrueClass|FalseClass
Checks if SQL cycle detection can be used.
-
#initialize(model_class:, parent_key:, parent_type_column:, depth_column: :recursive_depth, dependent: nil) ⇒ Config
constructor
A new instance of Config.
-
#primary_key ⇒ Symbol
Returns the primary key for the model class.
Constructor Details
#initialize(model_class:, parent_key:, parent_type_column:, depth_column: :recursive_depth, dependent: nil) ⇒ Config
Returns a new instance of Config.
10 11 12 13 14 15 16 |
# File 'lib/acts_as_recursive_tree/config.rb', line 10 def initialize(model_class:, parent_key:, parent_type_column:, depth_column: :recursive_depth, dependent: nil) @model_class = model_class @parent_key = parent_key @parent_type_column = parent_type_column @depth_column = depth_column @dependent = dependent end |
Instance Attribute Details
#dependent ⇒ Object (readonly)
Returns the value of attribute dependent.
8 9 10 |
# File 'lib/acts_as_recursive_tree/config.rb', line 8 def dependent @dependent end |
#depth_column ⇒ Object (readonly)
Returns the value of attribute depth_column.
8 9 10 |
# File 'lib/acts_as_recursive_tree/config.rb', line 8 def depth_column @depth_column end |
#parent_key ⇒ Object (readonly)
Returns the value of attribute parent_key.
8 9 10 |
# File 'lib/acts_as_recursive_tree/config.rb', line 8 def parent_key @parent_key end |
#parent_type_column ⇒ Object (readonly)
Returns the value of attribute parent_type_column.
8 9 10 |
# File 'lib/acts_as_recursive_tree/config.rb', line 8 def parent_type_column @parent_type_column end |
Instance Method Details
#cycle_detection? ⇒ TrueClass|FalseClass
Checks if SQL cycle detection can be used. This is currently supported only on PostgreSQL 14+.
28 29 30 31 32 33 |
# File 'lib/acts_as_recursive_tree/config.rb', line 28 def cycle_detection? return @cycle_detection if defined?(@cycle_detection) @cycle_detection = @model_class.connection.adapter_name == 'PostgreSQL' && @model_class.connection.database_version >= 140_000 end |
#primary_key ⇒ Symbol
Returns the primary key for the model class.
21 22 23 |
# File 'lib/acts_as_recursive_tree/config.rb', line 21 def primary_key @primary_key ||= @model_class.primary_key.to_sym end |