Class: Vocab::Settings
- Inherits:
-
Object
- Object
- Vocab::Settings
- Defined in:
- lib/vocab/settings.rb
Class Method Summary collapse
Instance Method Summary collapse
- #config_file ⇒ Object
-
#initialize(root) ⇒ Settings
constructor
A new instance of Settings.
- #last_translation ⇒ Object
- #update_translation ⇒ Object
- #write_settings ⇒ Object
Constructor Details
#initialize(root) ⇒ 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
.create ⇒ Object
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_file ⇒ Object
8 9 10 |
# File 'lib/vocab/settings.rb', line 8 def config_file Pathname.new( "#{@root}/.vocab" ) end |
#last_translation ⇒ Object
12 13 14 |
# File 'lib/vocab/settings.rb', line 12 def last_translation return @local_config[ 'last_translation' ] end |
#update_translation ⇒ Object
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_settings ⇒ Object
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 |