Class: Dataset::Record::Heirarchy
- Inherits:
-
Object
- Object
- Dataset::Record::Heirarchy
- Defined in:
- lib/dataset/record/heirarchy.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#base_class ⇒ Object
readonly
Returns the value of attribute base_class.
-
#class_name ⇒ Object
readonly
Returns the value of attribute class_name.
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Instance Method Summary collapse
- #finder_name(klass) ⇒ Object
- #id_cache_key ⇒ Object
- #id_finder_name(klass) ⇒ Object
- #id_finder_names ⇒ Object
-
#initialize(base_class) ⇒ Heirarchy
constructor
A new instance of Heirarchy.
- #model_finder_name(klass) ⇒ Object
- #model_finder_names ⇒ Object
- #timestamp_columns ⇒ Object
- #to_s ⇒ Object
- #update(record_class) ⇒ Object
Constructor Details
#initialize(base_class) ⇒ Heirarchy
Returns a new instance of Heirarchy.
9 10 11 12 13 14 |
# File 'lib/dataset/record/heirarchy.rb', line 9 def initialize(base_class) @base_class = base_class @class_name = base_class.name @table_name = base_class.table_name @columns = base_class.columns end |
Instance Attribute Details
#base_class ⇒ Object (readonly)
Returns the value of attribute base_class.
5 6 7 |
# File 'lib/dataset/record/heirarchy.rb', line 5 def base_class @base_class end |
#class_name ⇒ Object (readonly)
Returns the value of attribute class_name.
5 6 7 |
# File 'lib/dataset/record/heirarchy.rb', line 5 def class_name @class_name end |
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
5 6 7 |
# File 'lib/dataset/record/heirarchy.rb', line 5 def columns @columns end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
5 6 7 |
# File 'lib/dataset/record/heirarchy.rb', line 5 def table_name @table_name end |
Instance Method Details
#finder_name(klass) ⇒ Object
42 43 44 |
# File 'lib/dataset/record/heirarchy.rb', line 42 def finder_name(klass) klass.name.underscore.gsub('/', '_').sub(/^(\w)_/, '\1').gsub(/_(\w)_/, '_\1') end |
#id_cache_key ⇒ Object
16 17 18 |
# File 'lib/dataset/record/heirarchy.rb', line 16 def id_cache_key @id_cache_key ||= table_name end |
#id_finder_name(klass) ⇒ Object
46 47 48 |
# File 'lib/dataset/record/heirarchy.rb', line 46 def id_finder_name(klass) "#{finder_name(klass)}_id".to_sym end |
#id_finder_names ⇒ Object
20 21 22 |
# File 'lib/dataset/record/heirarchy.rb', line 20 def id_finder_names @id_finder_names ||= [id_finder_name(base_class)] end |
#model_finder_name(klass) ⇒ Object
50 51 52 |
# File 'lib/dataset/record/heirarchy.rb', line 50 def model_finder_name(klass) finder_name(klass).pluralize.to_sym end |
#model_finder_names ⇒ Object
24 25 26 |
# File 'lib/dataset/record/heirarchy.rb', line 24 def model_finder_names @model_finder_names ||= [model_finder_name(base_class)] end |
#timestamp_columns ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/dataset/record/heirarchy.rb', line 54 def @timestamp_columns ||= begin = %w(created_at created_on updated_at updated_on) columns.select do |column| .include?(column.name) end end end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/dataset/record/heirarchy.rb', line 28 def to_s "#<Heirarchy: #{table_name}>" end |
#update(record_class) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/dataset/record/heirarchy.rb', line 32 def update(record_class) record_class.ancestors.each do |c| finder_name = model_finder_name(c) unless model_finder_names.include?(finder_name) model_finder_names << finder_name id_finder_names << id_finder_name(c) end end end |