Class: Kodiak::ConfigReader
- Inherits:
-
Object
- Object
- Kodiak::ConfigReader
- Defined in:
- lib/kodiak/config_reader.rb
Instance Attribute Summary collapse
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#files ⇒ Object
Returns the value of attribute files.
-
#input ⇒ Object
Returns the value of attribute input.
-
#options ⇒ Object
Returns the value of attribute options.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #check_and_set_globals ⇒ Object
- #find_and_add_files ⇒ Object
- #ftp ⇒ Object
- #ftp? ⇒ Boolean
- #get_config ⇒ Object
-
#initialize(options) ⇒ ConfigReader
constructor
A new instance of ConfigReader.
Constructor Details
#initialize(options) ⇒ ConfigReader
Returns a new instance of ConfigReader.
8 9 10 11 12 13 14 15 |
# File 'lib/kodiak/config_reader.rb', line 8 def initialize() @options = @environment = @options[:environment] @input = get_config @files = [] check_and_set_globals find_and_add_files end |
Instance Attribute Details
#environment ⇒ Object
Returns the value of attribute environment.
6 7 8 |
# File 'lib/kodiak/config_reader.rb', line 6 def environment @environment end |
#files ⇒ Object
Returns the value of attribute files.
6 7 8 |
# File 'lib/kodiak/config_reader.rb', line 6 def files @files end |
#input ⇒ Object
Returns the value of attribute input.
6 7 8 |
# File 'lib/kodiak/config_reader.rb', line 6 def input @input end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/kodiak/config_reader.rb', line 6 def @options end |
#user ⇒ Object
Returns the value of attribute user.
6 7 8 |
# File 'lib/kodiak/config_reader.rb', line 6 def user @user end |
Instance Method Details
#check_and_set_globals ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/kodiak/config_reader.rb', line 86 def check_and_set_globals if File.exists? "#{ENV['HOME']}/#{Kodiak::GLOBAL_CONFIG}" begin user = YAML.load(File.open("#{ENV['HOME']}/#{Kodiak::GLOBAL_CONFIG}")) if user.class == Hash && ! user.empty? Kodiak.user = user @user = user else Kodiak::Notification.new "Kodiak has not been globally configured or the configuration is broken\n", "failure" puts "To configure, use:" puts 'kodiak configure --user.name "Firstname Lastname" --user.email "[email protected]"' exit end rescue ArgumentError => e puts "Could not parse YAML: #{e.}\n" exit end else Kodiak::Notification.new "Kodiak has not been globally configured or the configuration is broken\n", "failure" puts "To configure, use:" puts 'kodiak configure --user.name "Firstname Lastname" --user.email "[email protected]"' exit end end |
#find_and_add_files ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/kodiak/config_reader.rb', line 18 def find_and_add_files if @input[@environment] @input[@environment]['files'].each do |source, destination| Dir.glob(source).each do |file| input = { :source => file, :destination => destination } @files.push input end end else puts "Environment '#{environment}' is not defined in kodiak.yaml" puts "Environments defined:" @input.each do |name, environment| puts "- #{name}" end exit end end |
#ftp ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/kodiak/config_reader.rb', line 42 def ftp environment = @input[@environment] # supply a default path of root if ! environment['path'] environment['path'] = "" end credentials = {} items = ['server','username','password','path'] #check that they provided all the creds we need items.each do |item| if ! environment[item] puts "Missing FTP credential: #{item}" exit else credentials[item] = environment[item] end end return credentials end |
#ftp? ⇒ Boolean
37 38 39 |
# File 'lib/kodiak/config_reader.rb', line 37 def ftp? @input[@environment]['ftp'] || false end |
#get_config ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/kodiak/config_reader.rb', line 65 def get_config if File.exists?(Kodiak::CONFIG_FILENAME) begin config = YAML.load(File.open(Kodiak::CONFIG_FILENAME)) if config.class == Hash && ! config.empty? return config else Kodiak::Notification.new "Kodiak configuration exists but has not been defined yet. Configure it in #{Kodiak::CONFIG_FILENAME}\n", "failure" system("open #{Kodiak::CONFIG_FILENAME}") exit(0) end rescue ArgumentError => e Kodiak::Notification.new "Could not parse YAML: #{e.}\n", "failure" exit end else Kodiak::Notification.new "Could not find a Kodiak configuration file in this directory. Use 'kodiak generate' to create one.\n", "failure" exit end end |