Class: Tweetwine::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/tweetwine/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.read(args = [], default_config = {}, &cmd_option_parser) ⇒ Object



8
9
10
# File 'lib/tweetwine/config.rb', line 8

def self.read(args = [], default_config = {}, &cmd_option_parser)
  new parse_options(args, default_config, &cmd_option_parser)
end

Instance Method Details

#[](key) ⇒ Object



12
13
14
# File 'lib/tweetwine/config.rb', line 12

def [](key)
  @options[key]
end

#[]=(key, value) ⇒ Object



16
17
18
# File 'lib/tweetwine/config.rb', line 16

def []=(key, value)
  @options[key] = value
end

#keysObject



20
21
22
# File 'lib/tweetwine/config.rb', line 20

def keys
  @options.keys
end

#saveObject



24
25
26
27
28
29
30
31
32
# File 'lib/tweetwine/config.rb', line 24

def save
  raise "No config file specified" unless @file
  to_file = @options.reject { |key, _| @excludes.include? key }
  should_set_file_access_to_user_only = !File.exist?(@file)
  File.open(@file, 'w') do |io|
    io.chmod(0600) if should_set_file_access_to_user_only
    YAML.dump(Support.stringify_hash_keys(to_file), io)
  end
end