Class: ActsAsRecursiveTree::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_recursive_tree/config.rb

Overview

Stores the configuration of one Model class

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dependentObject (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_columnObject (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_keyObject (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_columnObject (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+.

Returns:

  • (TrueClass|FalseClass)


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_keySymbol

Returns the primary key for the model class.

Returns:

  • (Symbol)


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