Class: LMK::Config
- Inherits:
-
Object
- Object
- LMK::Config
- Defined in:
- lib/lmk/config.rb
Instance Attribute Summary collapse
-
#account_sid ⇒ Object
Returns the value of attribute account_sid.
-
#auth_token ⇒ Object
Returns the value of attribute auth_token.
-
#from ⇒ Object
Returns the value of attribute from.
-
#phone_number ⇒ Object
Returns the value of attribute phone_number.
Class Method Summary collapse
Instance Method Summary collapse
- #debug ⇒ Object
-
#initialize(attributes, file = nil) ⇒ Config
constructor
A new instance of Config.
- #missing_values ⇒ Object
- #raw ⇒ Object
- #required_attributes ⇒ Object
- #valid? ⇒ Boolean
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_sid ⇒ Object
Returns the value of attribute account_sid.
50 51 52 |
# File 'lib/lmk/config.rb', line 50 def account_sid @account_sid end |
#auth_token ⇒ Object
Returns the value of attribute auth_token.
50 51 52 |
# File 'lib/lmk/config.rb', line 50 def auth_token @auth_token end |
#from ⇒ Object
Returns the value of attribute from.
50 51 52 |
# File 'lib/lmk/config.rb', line 50 def from @from end |
#phone_number ⇒ Object
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_path ⇒ Object
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
#debug ⇒ Object
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_values ⇒ Object
31 32 33 |
# File 'lib/lmk/config.rb', line 31 def missing_values required_attributes.select { |method| send(method).nil? } end |
#raw ⇒ Object
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_attributes ⇒ Object
27 28 29 |
# File 'lib/lmk/config.rb', line 27 def required_attributes [:auth_token, :from, :phone_number, :account_sid] end |
#valid? ⇒ Boolean
23 24 25 |
# File 'lib/lmk/config.rb', line 23 def valid? required_attributes.map { |attr| send(attr) }.all? end |