Class: Mycommands::CommandModel

Inherits:
Model
  • Object
show all
Defined in:
lib/mycommands/models/command.rb

Instance Method Summary collapse

Instance Method Details

#command(category, index) ⇒ Object



7
8
9
# File 'lib/mycommands/models/command.rb', line 7

def command category, index
  commands(category)[index.to_i]
end

#commands(category) ⇒ Object



3
4
5
# File 'lib/mycommands/models/command.rb', line 3

def commands category
  all_commands.select {|c| c.category == category}
end

#sort_yaml_file!Object



11
12
13
14
15
16
# File 'lib/mycommands/models/command.rb', line 11

def sort_yaml_file!
  command_hash = all_commands.inject({}) {|command_hash, c| command_hash.merge!(c.to_hash) }
  file = File.open(default_or_user_yml('commands.yml'), 'w')
  file.write(command_hash.to_yaml(line_width: -1))
  file.path
end