Class: Alchemy::Cell
- Inherits:
-
BaseRecord
- Object
- ActiveRecord::Base
- BaseRecord
- 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
-
#definition ⇒ Object
Returns the cell definition defined in
config/alchemy/cells.yml
. -
#element_definitions ⇒ Object
(also: #available_elements)
Returns all elements that can be placed in this cell.
- #name_for_label ⇒ Object
- #to_partial_path ⇒ Object
Methods included from Logger
Methods inherited from BaseRecord
Class Method Details
.all_definitions_for(cellnames) ⇒ Object
45 46 47 |
# File 'app/models/alchemy/cell.rb', line 45 def all_definitions_for(cellnames) definitions.select { |c| cellnames.include? c['name'] } end |
.definition_for(cellname) ⇒ Object
40 41 42 43 |
# File 'app/models/alchemy/cell.rb', line 40 def definition_for(cellname) return nil if cellname.blank? definitions.detect { |c| c['name'] == cellname } end |
.definitions ⇒ Object
36 37 38 |
# File 'app/models/alchemy/cell.rb', line 36 def definitions @definitions ||= read_yml_file end |
.definitions_for_element(element_name) ⇒ Object
49 50 51 52 |
# File 'app/models/alchemy/cell.rb', line 49 def definitions_for_element(element_name) return [] if definitions.blank? definitions.select { |d| d['elements'].include?(element_name) } end |
Instance Method Details
#definition ⇒ Object
Returns the cell definition defined in config/alchemy/cells.yml
75 76 77 78 79 80 81 82 83 |
# File 'app/models/alchemy/cell.rb', line 75 def definition definition = self.class.definition_for(name) if definition.blank? log_warning "Could not find cell definition for #{name}. Please check your cells.yml!" return {} else definition end end |
#element_definitions ⇒ Object Also known as: available_elements
Returns all elements that can be placed in this cell
86 87 88 |
# File 'app/models/alchemy/cell.rb', line 86 def element_definitions definition['elements'] || [] end |
#name_for_label ⇒ Object
91 92 93 |
# File 'app/models/alchemy/cell.rb', line 91 def name_for_label self.class.translated_label_for(name) end |
#to_partial_path ⇒ Object
69 70 71 |
# File 'app/models/alchemy/cell.rb', line 69 def to_partial_path "alchemy/cells/#{name}" end |