Module: CantangoEditor::Categories

Extended by:
Categories
Included in:
Categories
Defined in:
app/models/cantango_editor/categories.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#availableObject

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_namesObject



11
12
13
# File 'app/models/cantango_editor/categories.rb', line 11

def available_names
  available.map{|c| c.name} 
end

#categories_fileObject



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_pathObject



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_fileObject



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_contentObject



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