Module: ClosureTree::Columns
- Defined in:
- lib/closure_tree/acts_as_tree.rb
Overview
Mixed into both classes and instances to provide easy access to the column names
Instance Method Summary collapse
- #append_order(order_by) ⇒ Object
- #ct_attribute_names ⇒ Object
- #ct_class ⇒ Object
- #ct_has_type? ⇒ Boolean
- #ct_subclass? ⇒ Boolean
- #ct_table_name ⇒ Object
- #has_name? ⇒ Boolean
- #hierarchy_class_name ⇒ Object
- #hierarchy_table_name ⇒ Object
- #name_column ⇒ Object
- #name_sym ⇒ Object
- #order_is_numeric ⇒ Object
- #order_option ⇒ Object
- #parent_column_name ⇒ Object
- #parent_column_sym ⇒ Object
- #quoted_hierarchy_table_name ⇒ Object
- #quoted_parent_column_name ⇒ Object
- #quoted_table_name ⇒ Object
- #with_order_option(options) ⇒ Object
Instance Method Details
#append_order(order_by) ⇒ Object
392 393 394 |
# File 'lib/closure_tree/acts_as_tree.rb', line 392 def append_order(order_by) order_option ? "#{order_by}, #{order_option}" : order_by end |
#ct_attribute_names ⇒ Object
410 411 412 |
# File 'lib/closure_tree/acts_as_tree.rb', line 410 def ct_attribute_names @ct_attr_names ||= ct_class.new.attributes.keys - ct_class.protected_attributes.to_a end |
#ct_class ⇒ Object
402 403 404 |
# File 'lib/closure_tree/acts_as_tree.rb', line 402 def ct_class (self.is_a?(Class) ? self : self.class) end |
#ct_has_type? ⇒ Boolean
414 415 416 |
# File 'lib/closure_tree/acts_as_tree.rb', line 414 def ct_has_type? ct_attribute_names.include? 'type' end |
#ct_subclass? ⇒ Boolean
406 407 408 |
# File 'lib/closure_tree/acts_as_tree.rb', line 406 def ct_subclass? ct_class != ct_class.base_class end |
#ct_table_name ⇒ Object
418 419 420 |
# File 'lib/closure_tree/acts_as_tree.rb', line 418 def ct_table_name ct_class.table_name end |
#has_name? ⇒ Boolean
355 356 357 |
# File 'lib/closure_tree/acts_as_tree.rb', line 355 def has_name? ct_class.new.attributes.include? [:name_column] end |
#hierarchy_class_name ⇒ Object
372 373 374 |
# File 'lib/closure_tree/acts_as_tree.rb', line 372 def hierarchy_class_name hierarchy_table_name.singularize.camelize end |
#hierarchy_table_name ⇒ Object
367 368 369 370 |
# File 'lib/closure_tree/acts_as_tree.rb', line 367 def hierarchy_table_name # We need to use the table_name, not ct_class.to_s.demodulize, because they may have overridden the table name [:hierarchy_table_name] || ct_table_name.singularize + "_hierarchies" end |
#name_column ⇒ Object
359 360 361 |
# File 'lib/closure_tree/acts_as_tree.rb', line 359 def name_column [:name_column] end |
#name_sym ⇒ Object
363 364 365 |
# File 'lib/closure_tree/acts_as_tree.rb', line 363 def name_sym name_column.to_sym end |
#order_is_numeric ⇒ Object
396 397 398 399 400 |
# File 'lib/closure_tree/acts_as_tree.rb', line 396 def order_is_numeric return false unless order_option c = ct_class.columns_hash[order_option] c && c.type == :integer end |
#order_option ⇒ Object
384 385 386 |
# File 'lib/closure_tree/acts_as_tree.rb', line 384 def order_option [:order] end |
#parent_column_name ⇒ Object
347 348 349 |
# File 'lib/closure_tree/acts_as_tree.rb', line 347 def parent_column_name [:parent_column_name] end |
#parent_column_sym ⇒ Object
351 352 353 |
# File 'lib/closure_tree/acts_as_tree.rb', line 351 def parent_column_sym parent_column_name.to_sym end |
#quoted_hierarchy_table_name ⇒ Object
376 377 378 |
# File 'lib/closure_tree/acts_as_tree.rb', line 376 def quoted_hierarchy_table_name connection.quote_column_name hierarchy_table_name end |
#quoted_parent_column_name ⇒ Object
380 381 382 |
# File 'lib/closure_tree/acts_as_tree.rb', line 380 def quoted_parent_column_name connection.quote_column_name parent_column_name end |
#quoted_table_name ⇒ Object
422 423 424 |
# File 'lib/closure_tree/acts_as_tree.rb', line 422 def quoted_table_name connection.quote_column_name ct_table_name end |
#with_order_option(options) ⇒ Object
388 389 390 |
# File 'lib/closure_tree/acts_as_tree.rb', line 388 def with_order_option() order_option ? .merge(:order => order_option) : end |