Class: Vocab::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/vocab/settings.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Settings

Returns a new instance of Settings.



3
4
5
6
# File 'lib/vocab/settings.rb', line 3

def initialize( root )
  @root   = root
  @local_config = File.exist?( config_file ) ? YAML.load_file( config_file ) : {}
end

Class Method Details

.createObject



28
29
30
31
32
33
# File 'lib/vocab/settings.rb', line 28

def self.create
  Vocab.ui.say( "Writing new .vocab file.  Check this file into your project repo" )
  settings = Vocab::Settings.new( Dir.pwd )
  settings.update_translation
  settings.write_settings
end

Instance Method Details

#config_fileObject



8
9
10
# File 'lib/vocab/settings.rb', line 8

def config_file
  Pathname.new( "#{@root}/.vocab" )
end

#last_translationObject



12
13
14
# File 'lib/vocab/settings.rb', line 12

def last_translation
  return @local_config[ 'last_translation' ]
end

#update_translationObject



16
17
18
19
20
21
# File 'lib/vocab/settings.rb', line 16

def update_translation
  current_sha = `git rev-parse HEAD`.strip
  @local_config[ 'last_translation' ] = current_sha
  write_settings
  return current_sha
end

#write_settingsObject



23
24
25
26
# File 'lib/vocab/settings.rb', line 23

def write_settings
  File.open( config_file, 'w' ) { |f| f.write( @local_config.to_yaml ) }
  `git add #{config_file}`
end