Class: Rusky::Setting

Inherits:
Object
  • Object
show all
Defined in:
lib/rusky/setting.rb

Constant Summary collapse

FILENAME =
'.rusky'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cwd) ⇒ Setting

Returns a new instance of Setting.



11
12
13
14
15
# File 'lib/rusky/setting.rb', line 11

def initialize(cwd)
  @cwd = cwd
  @filename = File.join(@cwd, FILENAME)
  @yaml = exists? ? YAML.load_file(filename) : Hash.new([])
end

Instance Attribute Details

#cwdObject (readonly)

Returns the value of attribute cwd.



7
8
9
# File 'lib/rusky/setting.rb', line 7

def cwd
  @cwd
end

#filenameObject (readonly)

Returns the value of attribute filename.



7
8
9
# File 'lib/rusky/setting.rb', line 7

def filename
  @filename
end

Instance Method Details

#commands_for(hook_name) ⇒ Object



33
34
35
# File 'lib/rusky/setting.rb', line 33

def commands_for(hook_name)
  @yaml[hook_name]
end

#createObject



17
18
19
20
21
22
23
# File 'lib/rusky/setting.rb', line 17

def create
  if !exists?
    puts "rusky > creating .rusky file..."
    File.write(filename, '')
  end
  self
end

#deleteObject



25
26
27
28
29
30
31
# File 'lib/rusky/setting.rb', line 25

def delete
  if exists?
    puts "rusky > deleting .rusky file..."
    File.delete(filename)
  end
  self
end