Class: Lobstr::Config
- Inherits:
-
Object
- Object
- Lobstr::Config
- Defined in:
- lib/lobstr/config.rb
Instance Attribute Summary collapse
-
#config_file ⇒ Object
Returns the value of attribute config_file.
-
#config_path ⇒ Object
Returns the value of attribute config_path.
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize(config = 'config/lobstr.yml') ⇒ Config
constructor
A new instance of Config.
- #parse(environment = 'production') ⇒ Object
- #print ⇒ Object
- #reset ⇒ Object
- #template ⇒ Object
Constructor Details
#initialize(config = 'config/lobstr.yml') ⇒ Config
Returns a new instance of Config.
5 6 7 8 |
# File 'lib/lobstr/config.rb', line 5 def initialize(config = 'config/lobstr.yml') @config_file = config @config_path = File.dirname config end |
Instance Attribute Details
#config_file ⇒ Object
Returns the value of attribute config_file.
3 4 5 |
# File 'lib/lobstr/config.rb', line 3 def config_file @config_file end |
#config_path ⇒ Object
Returns the value of attribute config_path.
3 4 5 |
# File 'lib/lobstr/config.rb', line 3 def config_path @config_path end |
Instance Method Details
#create ⇒ Object
26 27 28 29 30 |
# File 'lib/lobstr/config.rb', line 26 def create raise Lobstr::Error::ConfigFileExists, @config_file if config_file_exists? Dir.mkdir(@config_path) unless Dir.exist?(@config_path) File.open(@config_file, 'w') {|f| f.write(template) } end |
#parse(environment = 'production') ⇒ Object
37 38 39 40 41 42 |
# File 'lib/lobstr/config.rb', line 37 def parse(environment = 'production') check_config_file config = YAML.load_file(@config_file)[environment] raise Lobstr::Error::InvalidEnvironment, environment if config.nil? config end |
#print ⇒ Object
44 45 46 47 |
# File 'lib/lobstr/config.rb', line 44 def print check_config_file File.open(@config_file, 'r').read end |
#reset ⇒ Object
32 33 34 35 |
# File 'lib/lobstr/config.rb', line 32 def reset File.delete(@config_file) if config_file_exists? create end |
#template ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/lobstr/config.rb', line 10 def template <<-TEMPLATE.gsub!(/^ /,'') lobstr: &defaults app: lobstr repos: git://github.com/xentek/lobstr.git path: ~/lobstr ssh_host: localhost ssh_user: xentek ssh_key: ~/.ssh/id_rsa branch: master environment: production production: <<: *defaults TEMPLATE end |