Class: ActiveAdmin::Cms::Recipe

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActiveAdmin::Cms::Recipes::SectionHelper::SectionContainer
Defined in:
lib/active_admin/cms/recipe.rb,
lib/active_admin/cms/recipe/section.rb,
lib/active_admin/cms/recipe/ingredient.rb

Defined Under Namespace

Classes: Ingredient, Section

Instance Attribute Summary

Attributes included from ActiveAdmin::Cms::Recipes::SectionHelper::SectionContainer

#parent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActiveAdmin::Cms::Recipes::SectionHelper::SectionContainer

#add_fields_to, #ingredient, #ingredients, #method_missing, #section, #section_id, #section_key, #sections

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveAdmin::Cms::Recipes::SectionHelper::SectionContainer

Class Method Details

.define(&definition_block) ⇒ Object



9
10
11
12
13
# File 'lib/active_admin/cms/recipe.rb', line 9

def self.define(&definition_block)
  after_initialize do
    define &definition_block
  end
end

Instance Method Details

#admin_fieldset_titleObject



19
20
21
# File 'lib/active_admin/cms/recipe.rb', line 19

def admin_fieldset_title
  'Content'
end

#contains_content_key?(content_key) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/active_admin/cms/recipe.rb', line 23

def contains_content_key? content_key
  !!ingredient_for(content_key)
end

#define(&block) ⇒ Object



15
16
17
# File 'lib/active_admin/cms/recipe.rb', line 15

def define(&block)
  self.instance_eval &block
end

#ingredient_for(content_key) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/active_admin/cms/recipe.rb', line 27

def ingredient_for content_key
  section_keys = content_key.split ':'
  current_section = self
  section_keys.each do |section_id|
    #debugger
    if section_id == section_keys.last
      return current_section.ingredients[section_id.to_sym]
    else
      if current_section.sections[section_id.to_sym]
        current_section = current_section.sections[section_id.to_sym]
      else
        return nil
      end
    end
  end
end