Class: Bcli::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



4
5
6
7
8
9
10
# File 'lib/bcli/config.rb', line 4

def initialize
  @file_path = File.expand_path("~/.bcli.yml")
  @creds = read_from_file
  if token_expired?
    puts Bcli::Command.new.pastel.red "Token expired. Please re-authenticate."
  end
end

Instance Attribute Details

#credsObject (readonly)

Returns the value of attribute creds.



2
3
4
# File 'lib/bcli/config.rb', line 2

def creds
  @creds
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



2
3
4
# File 'lib/bcli/config.rb', line 2

def file_path
  @file_path
end

Instance Method Details

#creds_present?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/bcli/config.rb', line 21

def creds_present?
  creds[:email] && creds[:password]
end

#read_from_fileObject



12
13
14
15
# File 'lib/bcli/config.rb', line 12

def read_from_file
  return {} unless File.exist?(file_path)
  YAML.load_file(file_path)
end

#token_expired?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/bcli/config.rb', line 17

def token_expired?
  creds[:issued_at] && (Time.now.to_i - creds[:issued_at]) > (3600 * 24)
end