Module: Instapusher2::Configuration
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
48
49
50
51
|
# File 'lib/instapusher2/configuration.rb', line 48
def method_missing(name, *args, &block)
self.load
@_settings[name.to_s]
end
|
Instance Attribute Details
#_settings ⇒ Object
Returns the value of attribute _settings.
8
9
10
|
# File 'lib/instapusher2/configuration.rb', line 8
def _settings
@_settings
end
|
Instance Method Details
#ask ⇒ Object
44
45
46
|
# File 'lib/instapusher2/configuration.rb', line 44
def ask
$stdin.gets.to_s.strip
end
|
#ask_for_and_write_api_key ⇒ Object
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/instapusher2/configuration.rb', line 33
def ask_for_and_write_api_key
api_key = ask_for_api_key
instapusher_config = {"api_key" => api_key}
File.open(File.join(Dir.home, ".instapusher2"), "w") do |file|
file.write instapusher_config.to_yaml
end
puts ""
puts "You are all set. Start using instapusher2."
end
|
#ask_for_api_key ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/instapusher2/configuration.rb', line 24
def ask_for_api_key
puts ""
puts "Note: Your instapusher API key is available at http://www.instapusher.com/my/api_key"
puts ""
puts "Enter your Instapusher API key:"
api_key = ask
api_key
end
|
#load(debug = false, filename = nil) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/instapusher2/configuration.rb', line 10
def load(debug = false, filename=nil)
filename ||= File.join(ENV['HOME'], '.instapusher')
unless File.exist? filename
File.new(filename, File::CREAT|File::TRUNC|File::RDWR, 0644).close
end
@_settings = YAML::load_file(filename) || {}
if debug
puts @_settings.inspect
end
end
|