Class: Slack::Emogen::Config

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#loginObject (readonly)

Returns the value of attribute login.



58
59
60
# File 'lib/slack/emogen/config.rb', line 58

def 
  @login
end

#passwordObject (readonly)

Returns the value of attribute password.



58
59
60
# File 'lib/slack/emogen/config.rb', line 58

def password
  @password
end

#urlObject (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_messageObject



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 build_message
  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

   = STDIN.gets.chop

  puts <<-EOS
  enter your slack password
  ex) doraemon
  EOS

  password = STDIN.gets.chop

  [url, , 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, , password = build_message
      setup(url, , 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, , password)
  File.open(@@yml_path, "w") do |f|
    content = <<-EOS
      url: '#{url}'
      login: '#{}'
      password: '#{password}'
    EOS
    f.write(content)
  end
  {url: url, login: , password: password}
end