Class: Cms::Category

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
DefaultAccessible
Includes:
Cms::Concerns::IgnoresPublishing
Defined in:
app/models/cms/category.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DefaultAccessible

non_permitted_params, permitted_params

Methods included from Cms::Concerns::IgnoresPublishing

included

Class Method Details

.columns_for_indexObject



50
51
52
53
54
# File 'app/models/cms/category.rb', line 50

def self.columns_for_index
  [{:label => "Name", :method => :name, :order => "#{Category.table_name}.name"},
   {:label => "Type", :method => :category_type_name, :order => "#{CategoryType.table_name}.name"},
   {:label => "Updated On", :method => :updated_on_string, :order => "#{Category.table_name}.updated_at"}]
end

.named(name) ⇒ Object



16
17
18
# File 'app/models/cms/category.rb', line 16

def named(name)
  where(["#{table_name}.name = ?", name])
end

.of_type(type_name) ⇒ Object



20
21
22
23
24
25
# File 'app/models/cms/category.rb', line 20

def of_type(type_name)
  where(["#{CategoryType.table_name}.name = ?", type_name])
  .order("#{Category.table_name}.name")
  .includes(:category_type)
  .references(:category_type)
end

Instance Method Details

#ancestorsObject



30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/cms/category.rb', line 30

def ancestors
  fn = lambda do |cat, parents|
    if cat.parent_id
      p = self.class.find(cat.parent)
      fn.call(p, (parents << p))
    else
      parents.reverse
    end
  end
  fn.call(self, [])
end

#category_type_nameObject



46
47
48
# File 'app/models/cms/category.rb', line 46

def category_type_name
  category_type ? category_type.name : nil
end

#path(sep = " > ") ⇒ Object



42
43
44
# File 'app/models/cms/category.rb', line 42

def path(sep=" > ")
  (ancestors.map(&:name) + [name]).join(sep)
end