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

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_namesObject



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_classObject



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

Returns:

  • (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

Returns:

  • (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_nameObject



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

Returns:

  • (Boolean)


355
356
357
# File 'lib/closure_tree/acts_as_tree.rb', line 355

def has_name?
  ct_class.new.attributes.include? closure_tree_options[:name_column]
end

#hierarchy_class_nameObject



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_nameObject



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
  closure_tree_options[:hierarchy_table_name] || ct_table_name.singularize + "_hierarchies"
end

#name_columnObject



359
360
361
# File 'lib/closure_tree/acts_as_tree.rb', line 359

def name_column
  closure_tree_options[:name_column]
end

#name_symObject



363
364
365
# File 'lib/closure_tree/acts_as_tree.rb', line 363

def name_sym
  name_column.to_sym
end

#order_is_numericObject



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_optionObject



384
385
386
# File 'lib/closure_tree/acts_as_tree.rb', line 384

def order_option
  closure_tree_options[:order]
end

#parent_column_nameObject



347
348
349
# File 'lib/closure_tree/acts_as_tree.rb', line 347

def parent_column_name
  closure_tree_options[:parent_column_name]
end

#parent_column_symObject



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_nameObject



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_nameObject



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_nameObject



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(options)
  order_option ? options.merge(:order => order_option) : options
end