Class: Pello::Config

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

Constant Summary collapse

CONFIG_FILE_PATH =
"#{ENV['HOME']}/.config/pello/pello.yaml".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pello/config.rb', line 6

def initialize
  if File.exist?(CONFIG_FILE_PATH)
    config = YAML.safe_load File.open(CONFIG_FILE_PATH).read

    auth_config           = config['auth']
    @developer_public_key = auth_config['developer_public_key']
    @member_token         = auth_config['member_token']

    pello_config          = config['config']
    @username             = pello_config['username']
    @board_url            = pello_config['board_url']
    @list_name            = pello_config['list_name']
    @error                = false
  else
    @error = true
  end
rescue => e
  @error = true
  puts "Error loading config: #{e.message}"
end

Instance Attribute Details

#board_urlObject

Returns the value of attribute board_url.



4
5
6
# File 'lib/pello/config.rb', line 4

def board_url
  @board_url
end

#developer_public_keyObject

Returns the value of attribute developer_public_key.



4
5
6
# File 'lib/pello/config.rb', line 4

def developer_public_key
  @developer_public_key
end

#errorObject

Returns the value of attribute error.



4
5
6
# File 'lib/pello/config.rb', line 4

def error
  @error
end

#list_nameObject

Returns the value of attribute list_name.



4
5
6
# File 'lib/pello/config.rb', line 4

def list_name
  @list_name
end

#member_tokenObject

Returns the value of attribute member_token.



4
5
6
# File 'lib/pello/config.rb', line 4

def member_token
  @member_token
end

#usernameObject

Returns the value of attribute username.



4
5
6
# File 'lib/pello/config.rb', line 4

def username
  @username
end

Class Method Details

.write_empty_configObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pello/config.rb', line 31

def self.write_empty_config
  system "mkdir -p #{File.dirname(CONFIG_FILE_PATH)}"
  File.open(CONFIG_FILE_PATH, 'w') do |file|
    file.puts 'auth:'
    file.puts '  developer_public_key: ""'
    file.puts '  member_token: ""'
    file.puts 'config:'
    file.puts '  board_url: ""'
    file.puts '  username: ""'
    file.puts '  list_name: "In progress"'
  end
end

Instance Method Details

#valid?Boolean



27
28
29
# File 'lib/pello/config.rb', line 27

def valid?
  !error
end