Module: CantangoEditor::Categories
- Extended by:
- Categories
- Included in:
- Categories
- Defined in:
- app/models/cantango_editor/categories.rb
Instance Attribute Summary collapse
-
#available ⇒ Object
Returns the value of attribute available.
Instance Method Summary collapse
- #available_except(existing_targets = []) ⇒ Object
- #available_names ⇒ Object
- #categories_file ⇒ Object
- #categories_file_path ⇒ Object
- #create_empty_categories_file ⇒ Object
- #validate_content(content) ⇒ Object
- #yml_file_content ⇒ Object
Instance Attribute Details
#available ⇒ Object
Returns the value of attribute available.
5 6 7 |
# File 'app/models/cantango_editor/categories.rb', line 5 def available @available end |
Instance Method Details
#available_except(existing_targets = []) ⇒ Object
7 8 9 |
# File 'app/models/cantango_editor/categories.rb', line 7 def available_except existing_targets = [] available.select{|c| (available_names - existing_targets).include? c.name} end |
#available_names ⇒ Object
11 12 13 |
# File 'app/models/cantango_editor/categories.rb', line 11 def available_names available.map{|c| c.name} end |
#categories_file ⇒ Object
33 34 35 36 37 |
# File 'app/models/cantango_editor/categories.rb', line 33 def categories_file create_empty_categories_file if !File.file? categories_file_path categories_file_path end |
#categories_file_path ⇒ Object
47 48 49 |
# File 'app/models/cantango_editor/categories.rb', line 47 def categories_file_path File.join Rails.root + "config/" + "categories.yml" end |
#create_empty_categories_file ⇒ Object
39 40 41 42 43 44 45 |
# File 'app/models/cantango_editor/categories.rb', line 39 def create_empty_categories_file File.open(categories_file_path, 'w') do |file| YAML.dump({}, file) end categories_file_path end |
#validate_content(content) ⇒ Object
30 31 |
# File 'app/models/cantango_editor/categories.rb', line 30 def validate_content content end |
#yml_file_content ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'app/models/cantango_editor/categories.rb', line 21 def yml_file_content yml_content = YAML.load_file(categories_file) validate_content yml_content yml_content || {} rescue => e raise e end |