Class: BitbucketMigration::Configuration
- Inherits:
-
Object
- Object
- BitbucketMigration::Configuration
- Defined in:
- lib/bitbucket_migration/configuration.rb
Constant Summary collapse
- DEFAULT_CONFIG =
'config.yml'
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#team ⇒ Object
readonly
Returns the value of attribute team.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(configfile) ⇒ Configuration
constructor
A new instance of Configuration.
-
#read(configfile = nil) ⇒ Object
Read configuration file.
-
#valid?(yml) ⇒ Boolean
Check if configuration file has required keys and values.
Constructor Details
#initialize(configfile) ⇒ Configuration
Returns a new instance of Configuration.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/bitbucket_migration/configuration.rb', line 9 def initialize(configfile) config = read(configfile) if(valid?(config)) @file = configfile @username =config['username'] @password =config['password'] @team =config['team'] end end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
7 8 9 |
# File 'lib/bitbucket_migration/configuration.rb', line 7 def file @file end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
7 8 9 |
# File 'lib/bitbucket_migration/configuration.rb', line 7 def password @password end |
#team ⇒ Object (readonly)
Returns the value of attribute team.
7 8 9 |
# File 'lib/bitbucket_migration/configuration.rb', line 7 def team @team end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
7 8 9 |
# File 'lib/bitbucket_migration/configuration.rb', line 7 def username @username end |
Instance Method Details
#read(configfile = nil) ⇒ Object
Read configuration file
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bitbucket_migration/configuration.rb', line 21 def read(configfile=nil) file = configfile ? configfile : DEFAULT_CONFIG begin conf = YAML::load_file(file) return conf rescue puts "[Error] " + $!.to_s exit end end |
#valid?(yml) ⇒ Boolean
Check if configuration file has required keys and values
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bitbucket_migration/configuration.rb', line 33 def valid?(yml) expected = ['username','password','team'] # check if required keys present valid_keys = expected.all? { |e| yml.keys.include?(e) } # check if values exists and not nil valid_values = yml.all? { |k,v| v.nil? || v.empty? || v.size == 0 } return valid_keys || valid_values ? true : false end |