Class: LMK::Config

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes, file = nil) ⇒ Config

Returns a new instance of Config.



15
16
17
18
19
20
21
# File 'lib/lmk/config.rb', line 15

def initialize(attributes, file = nil) 
  (attributes || {}).each do |k, v|
    setter = "#{k}=".to_sym
    send(setter, v) if respond_to?(setter)
  end
  @file = file
end

Instance Attribute Details

#account_sidObject

Returns the value of attribute account_sid.



50
51
52
# File 'lib/lmk/config.rb', line 50

def 
  @account_sid
end

#auth_tokenObject

Returns the value of attribute auth_token.



50
51
52
# File 'lib/lmk/config.rb', line 50

def auth_token
  @auth_token
end

#fromObject

Returns the value of attribute from.



50
51
52
# File 'lib/lmk/config.rb', line 50

def from
  @from
end

#phone_numberObject

Returns the value of attribute phone_number.



50
51
52
# File 'lib/lmk/config.rb', line 50

def phone_number
  @phone_number
end

Class Method Details

.default_pathObject



6
7
8
# File 'lib/lmk/config.rb', line 6

def self.default_path
  "#{ENV['HOME']}/.lmkrc"
end

.from_file(path = default_path) ⇒ Object



10
11
12
13
# File 'lib/lmk/config.rb', line 10

def self.from_file(path = default_path)
  attrs = ::YAML.load_file(path) if File.exists?(path)
  new(attrs, path)
end

Instance Method Details

#debugObject



35
36
37
38
39
40
41
42
# File 'lib/lmk/config.rb', line 35

def debug
  <<-RESULT
LMK Configuration #{valid? ? 'valid' : 'invalid'} 
#{'Config file missing, create ' + @file  + ' with required values.' if @file && !File.exists?(@file) }
missing values: #{valid? ? 'none' : missing_values }
#{raw}
  RESULT
end

#missing_valuesObject



31
32
33
# File 'lib/lmk/config.rb', line 31

def missing_values
  required_attributes.select { |method| send(method).nil? }
end

#rawObject



44
45
46
47
48
# File 'lib/lmk/config.rb', line 44

def raw
  instance_variables.map do |ivar|
    "#{ivar.to_s.gsub("@", "")}: #{instance_variable_get ivar}"
  end.join "\n"
end

#required_attributesObject



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

def required_attributes
  [:auth_token, :from, :phone_number, :account_sid]
end

#valid?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/lmk/config.rb', line 23

def valid? 
  required_attributes.map { |attr| send(attr) }.all?
end