Module: ClosureTree::SupportAttributes

Included in:
Support
Defined in:
lib/closure_tree/support_attributes.rb

Instance Method Summary collapse

Instance Method Details

#attribute_namesObject



9
10
11
# File 'lib/closure_tree/support_attributes.rb', line 9

def attribute_names
  @attribute_names ||= model_class.new.attributes.keys - model_class.protected_attributes.to_a
end

#base_classObject

This is the “topmost” class. This will only potentially not be ct_class if you are using STI.



5
6
7
# File 'lib/closure_tree/support_attributes.rb', line 5

def base_class
  options[:base_class]
end

#connectionObject



13
14
15
# File 'lib/closure_tree/support_attributes.rb', line 13

def connection
  model_class.connection
end

#hierarchy_class_nameObject



25
26
27
# File 'lib/closure_tree/support_attributes.rb', line 25

def hierarchy_class_name
  options[:hierarchy_class_name] || model_class.to_s + "Hierarchy"
end

#name_columnObject



37
38
39
# File 'lib/closure_tree/support_attributes.rb', line 37

def name_column
  options[:name_column]
end

#name_symObject



41
42
43
# File 'lib/closure_tree/support_attributes.rb', line 41

def name_sym
  name_column.to_sym
end

#order_columnObject



72
73
74
75
76
77
78
79
80
81
# File 'lib/closure_tree/support_attributes.rb', line 72

def order_column
  o = options[:order]
  if o.nil?
    nil
  elsif o.is_a?(String)
    o.split(' ', 2).first
  else
    o.to_s
  end
end

#order_column_symObject



87
88
89
90
# File 'lib/closure_tree/support_attributes.rb', line 87

def order_column_sym
  require_order_column
  order_column.to_sym
end

#parent_column_nameObject



29
30
31
# File 'lib/closure_tree/support_attributes.rb', line 29

def parent_column_name
  options[:parent_column_name]
end

#parent_column_symObject



33
34
35
# File 'lib/closure_tree/support_attributes.rb', line 33

def parent_column_sym
  parent_column_name.to_sym
end

#quoted_hierarchy_table_nameObject



56
57
58
# File 'lib/closure_tree/support_attributes.rb', line 56

def quoted_hierarchy_table_name
  connection.quote_table_name hierarchy_table_name
end

#quoted_id_column_nameObject



60
61
62
# File 'lib/closure_tree/support_attributes.rb', line 60

def quoted_id_column_name
  connection.quote_column_name model_class.primary_key
end

#quoted_name_columnObject



68
69
70
# File 'lib/closure_tree/support_attributes.rb', line 68

def quoted_name_column
  connection.quote_column_name name_column
end

#quoted_order_column(include_table_name = true) ⇒ Object



92
93
94
95
96
# File 'lib/closure_tree/support_attributes.rb', line 92

def quoted_order_column(include_table_name = true)
  require_order_column
  prefix = include_table_name ? "#{quoted_table_name}." : ""
  "#{prefix}#{connection.quote_column_name(order_column)}"
end

#quoted_parent_column_nameObject



64
65
66
# File 'lib/closure_tree/support_attributes.rb', line 64

def quoted_parent_column_name
  connection.quote_column_name parent_column_name
end

#quoted_table_nameObject



21
22
23
# File 'lib/closure_tree/support_attributes.rb', line 21

def quoted_table_name
  connection.quote_table_name(table_name)
end

#require_order_columnObject



83
84
85
# File 'lib/closure_tree/support_attributes.rb', line 83

def require_order_column
  raise ":order value, '#{options[:order]}', isn't a column" if order_column.nil?
end

#short_hierarchy_class_nameString

Returns the constant name of the hierarchy_class

Examples:

Namespace::Model.hierarchy_class_name # => "Namespace::ModelHierarchy"
Namespace::Model.short_hierarchy_class_name # => "ModelHierarchy"

Returns:

  • (String)

    the constant name



52
53
54
# File 'lib/closure_tree/support_attributes.rb', line 52

def short_hierarchy_class_name
  hierarchy_class_name.split('::').last
end

#table_nameObject



17
18
19
# File 'lib/closure_tree/support_attributes.rb', line 17

def table_name
  model_class.table_name
end