Class: Slack::Emogen::Config
- Inherits:
-
Object
- Object
- Slack::Emogen::Config
- Defined in:
- lib/slack/emogen/config.rb
Instance Attribute Summary collapse
-
#login ⇒ Object
readonly
Returns the value of attribute login.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(opts) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(opts) ⇒ Config
Returns a new instance of Config.
60 61 62 63 64 65 |
# File 'lib/slack/emogen/config.rb', line 60 def initialize(opts) _opts = opts.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo} @url = _opts.fetch(:url) @login = _opts.fetch(:login) @password = _opts.fetch(:password) end |
Instance Attribute Details
#login ⇒ Object (readonly)
Returns the value of attribute login.
58 59 60 |
# File 'lib/slack/emogen/config.rb', line 58 def login @login end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
58 59 60 |
# File 'lib/slack/emogen/config.rb', line 58 def password @password end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
58 59 60 |
# File 'lib/slack/emogen/config.rb', line 58 def url @url end |
Class Method Details
.build_message ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/slack/emogen/config.rb', line 18 def puts <<-EOS enter your slack url ex) https://example.slack.com/ EOS url = STDIN.gets.chop puts <<-EOS enter your slack login mail address ex) [email protected] EOS login = STDIN.gets.chop puts <<-EOS enter your slack password ex) doraemon EOS password = STDIN.gets.chop [url, login, password] end |
.find_or_create! ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/slack/emogen/config.rb', line 6 def find_or_create! @@yml_path = File.join($root_path, "config.yml") opts = if File.exist?(@@yml_path) YAML::load_file @@yml_path else url, login, password = setup(url, login, password) end new(opts) end |
.setup(url, login, password) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/slack/emogen/config.rb', line 45 def setup(url, login, password) File.open(@@yml_path, "w") do |f| content = <<-EOS url: '#{url}' login: '#{login}' password: '#{password}' EOS f.write(content) end {url: url, login: login, password: password} end |