Module: ClosureTree::SupportAttributes
- Included in:
- Support
- Defined in:
- lib/closure_tree/support_attributes.rb
Instance Method Summary collapse
- #attribute_names ⇒ Object
-
#base_class ⇒ Object
This is the “topmost” class.
- #connection ⇒ Object
- #hierarchy_class_name ⇒ Object
- #name_column ⇒ Object
- #name_sym ⇒ Object
- #order_column ⇒ Object
- #order_column_sym ⇒ Object
- #parent_column_name ⇒ Object
- #parent_column_sym ⇒ Object
- #quoted_hierarchy_table_name ⇒ Object
- #quoted_id_column_name ⇒ Object
- #quoted_name_column ⇒ Object
- #quoted_order_column(include_table_name = true) ⇒ Object
- #quoted_parent_column_name ⇒ Object
- #quoted_table_name ⇒ Object
- #require_order_column ⇒ Object
-
#short_hierarchy_class_name ⇒ String
Returns the constant name of the hierarchy_class.
- #table_name ⇒ Object
Instance Method Details
#attribute_names ⇒ Object
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_class ⇒ Object
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 [:base_class] end |
#connection ⇒ Object
13 14 15 |
# File 'lib/closure_tree/support_attributes.rb', line 13 def connection model_class.connection end |
#hierarchy_class_name ⇒ Object
25 26 27 |
# File 'lib/closure_tree/support_attributes.rb', line 25 def hierarchy_class_name [:hierarchy_class_name] || model_class.to_s + "Hierarchy" end |
#name_column ⇒ Object
37 38 39 |
# File 'lib/closure_tree/support_attributes.rb', line 37 def name_column [:name_column] end |
#name_sym ⇒ Object
41 42 43 |
# File 'lib/closure_tree/support_attributes.rb', line 41 def name_sym name_column.to_sym end |
#order_column ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/closure_tree/support_attributes.rb', line 72 def order_column o = [:order] if o.nil? nil elsif o.is_a?(String) o.split(' ', 2).first else o.to_s end end |
#order_column_sym ⇒ Object
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_name ⇒ Object
29 30 31 |
# File 'lib/closure_tree/support_attributes.rb', line 29 def parent_column_name [:parent_column_name] end |
#parent_column_sym ⇒ Object
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_name ⇒ Object
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_name ⇒ Object
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_column ⇒ Object
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_name ⇒ Object
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_name ⇒ Object
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_column ⇒ Object
83 84 85 |
# File 'lib/closure_tree/support_attributes.rb', line 83 def require_order_column raise ":order value, '#{[:order]}', isn't a column" if order_column.nil? end |
#short_hierarchy_class_name ⇒ String
Returns the constant name of the hierarchy_class
52 53 54 |
# File 'lib/closure_tree/support_attributes.rb', line 52 def short_hierarchy_class_name hierarchy_class_name.split('::').last end |
#table_name ⇒ Object
17 18 19 |
# File 'lib/closure_tree/support_attributes.rb', line 17 def table_name model_class.table_name end |