Class: Strobe::CLI::Settings
- Inherits:
-
Object
- Object
- Strobe::CLI::Settings
- Defined in:
- lib/strobe/cli/settings.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, val) ⇒ Object
- #authenticate! ⇒ Object
- #connect! ⇒ Object
- #connection ⇒ Object
- #delete ⇒ Object
-
#initialize(filename = self.class.global_config_file) ⇒ Settings
constructor
A new instance of Settings.
Constructor Details
#initialize(filename = self.class.global_config_file) ⇒ Settings
Returns a new instance of Settings.
19 20 21 22 23 24 25 26 27 |
# File 'lib/strobe/cli/settings.rb', line 19 def initialize(filename = self.class.global_config_file) @filename = filename if @filename.exist? @hash = YAML.load(@filename) || {} else @hash = {} end end |
Class Method Details
.application(root) ⇒ Object
15 16 17 |
# File 'lib/strobe/cli/settings.rb', line 15 def self.application(root) new application_config_file(root) end |
Instance Method Details
#[](k) ⇒ Object
29 30 31 |
# File 'lib/strobe/cli/settings.rb', line 29 def [](k) ENV[key(k)] || @hash[key(k)] end |
#[]=(k, val) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/strobe/cli/settings.rb', line 33 def []=(k, val) @hash[key(k)] = val # Persist the setting FileUtils.mkdir_p(@filename.dirname) File.open(@filename, "wb") do |file| file.puts @hash.to_yaml end val end |
#authenticate! ⇒ Object
56 57 58 59 60 |
# File 'lib/strobe/cli/settings.rb', line 56 def authenticate! if token = self[:token] connection.authenticate_with_token(token) end end |
#connect! ⇒ Object
51 52 53 54 |
# File 'lib/strobe/cli/settings.rb', line 51 def connect! Strobe.connection = connection authenticate! end |
#connection ⇒ Object
45 46 47 48 49 |
# File 'lib/strobe/cli/settings.rb', line 45 def connection return @connection if @connection host = self[:url] || "http://api.strobeapp.com/" @connection = Connection.new(host) end |
#delete ⇒ Object
62 63 64 |
# File 'lib/strobe/cli/settings.rb', line 62 def delete FileUtils.rm_f(@filename) end |