Class: Alchemy::Cell
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Alchemy::Cell
- Includes:
- Logger
- Defined in:
- app/models/alchemy/cell.rb
Class Method Summary collapse
- .all_definitions_for(cellnames) ⇒ Object
- .definition_for(cellname) ⇒ Object
- .definitions ⇒ Object
- .definitions_for_element(element_name) ⇒ Object
- .translated_label_for(cell_name) ⇒ Object
Instance Method Summary collapse
-
#available_elements ⇒ Object
Returns all elements that can be placed in this cell.
-
#definition ⇒ Object
(also: #description)
Returns the cell definition defined in
config/alchemy/cells.yml
. - #name_for_label ⇒ Object
- #to_partial_path ⇒ Object
Methods included from Logger
Class Method Details
.all_definitions_for(cellnames) ⇒ Object
43 44 45 |
# File 'app/models/alchemy/cell.rb', line 43 def all_definitions_for(cellnames) definitions.select { |c| cellnames.include? c['name'] } end |
.definition_for(cellname) ⇒ Object
38 39 40 41 |
# File 'app/models/alchemy/cell.rb', line 38 def definition_for(cellname) return nil if cellname.blank? definitions.detect { |c| c['name'] == cellname } end |
.definitions ⇒ Object
34 35 36 |
# File 'app/models/alchemy/cell.rb', line 34 def definitions @definitions ||= read_yml_file end |
.definitions_for_element(element_name) ⇒ Object
47 48 49 50 |
# File 'app/models/alchemy/cell.rb', line 47 def definitions_for_element(element_name) return [] if definitions.blank? definitions.select { |d| d['elements'].include?(element_name) } end |
Instance Method Details
#available_elements ⇒ Object
Returns all elements that can be placed in this cell
85 86 87 |
# File 'app/models/alchemy/cell.rb', line 85 def available_elements definition['elements'] || [] end |
#definition ⇒ Object Also known as: description
Returns the cell definition defined in config/alchemy/cells.yml
73 74 75 76 77 78 79 80 81 |
# File 'app/models/alchemy/cell.rb', line 73 def definition definition = self.class.definition_for(self.name) if definition.blank? log_warning "Could not find cell definition for #{self.name}. Please check your cells.yml!" return {} else definition end end |
#name_for_label ⇒ Object
89 90 91 |
# File 'app/models/alchemy/cell.rb', line 89 def name_for_label self.class.translated_label_for(self.name) end |
#to_partial_path ⇒ Object
67 68 69 |
# File 'app/models/alchemy/cell.rb', line 67 def to_partial_path "alchemy/cells/#{name}" end |