Class: Trooper::Configuration
- Inherits:
-
Hash
- Object
- Hash
- Trooper::Configuration
- Defined in:
- lib/trooper/configuration.rb
Constant Summary
Constants included from Trooper::Config::Defaults
Trooper::Config::Defaults::FILE_NAME
Constants included from Trooper::Config::Action
Trooper::Config::Action::DEFAULT_ACTIONS
Class Method Summary collapse
-
.init ⇒ Object
Public: Copies the template troopfile to current dir.
Instance Method Summary collapse
-
#import(name) ⇒ Object
Public: Will allow user in import another troopfile.
-
#initialize(options = {}) ⇒ Configuration
constructor
Public: initialize a new configuration object, will parse the given troopfile.
-
#loaded? ⇒ Boolean
Public: Check to see if troopfile is loaded.
-
#runner(strategy_name) ⇒ Object
Public: Finds a Strategy and returns a runner for that strategy.
-
#set(hash) ⇒ Object
Public: Set variables that will be available to all actions.
-
#to_s ⇒ Object
Public: Terminal Friendly version of the configuration.
Methods included from Trooper::Config::Defaults
Methods included from Trooper::Config::Action
#action, #load_default_actions!
Methods included from Trooper::Config::Strategy
Methods included from Trooper::Config::Environment
#env, #hosts, #load_environment!, #path, #repository, #ruby_bin_path, #user
Constructor Details
#initialize(options = {}) ⇒ Configuration
Public: initialize a new configuration object, will parse the given troopfile
options - Default options to combine with troopfile
Examples
Configuration.new({:my_override => 'settings'}) # => <Configuration>
Returns a configuration object.
46 47 48 49 50 51 |
# File 'lib/trooper/configuration.rb', line 46 def initialize( = {}) @loaded = false load_defaults! load_troopfile! end |
Class Method Details
.init ⇒ Object
Public: Copies the template troopfile to current dir
Examples
Configuration.init # => nil
Returns nil.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/trooper/configuration.rb', line 25 def self.init gem_dir = File.dirname(__FILE__) if RUBY_VERSION == /1.8/ require 'ftools' File.copy("#{gem_dir}/template/troopfile.rb", "./Troopfile") else require 'fileutils' ::FileUtils.copy("#{gem_dir}/template/troopfile.rb", "./Troopfile") end end |
Instance Method Details
#import(name) ⇒ Object
Public: Will allow user in import another troopfile.
Examples
@config.import('filename') # => nil
Returns nil.
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/trooper/configuration.rb', line 109 def import(name) extname = File.extname(name).empty? ? ".rb" : nil filename = File.join(troopfile_dir, "#{name}#{extname}") if File.exists?(filename) eval File.open(filename).read nil else raise Trooper::NoConfigurationFileError, "No Import Configuration file (#{self[:file_name]}) can be found!" end end |
#loaded? ⇒ Boolean
Public: Check to see if troopfile is loaded.
Examples
@config.loaded? # => true
Returns boolean.
98 99 100 |
# File 'lib/trooper/configuration.rb', line 98 def loaded? @loaded end |
#runner(strategy_name) ⇒ Object
Public: Finds a Strategy and returns a runner for that strategy.
strategy_name - The name of the strategy as a symbol.
Examples
@config.runner(:my_strategy_name) # => <Runner>
Returns a runner.
73 74 75 76 |
# File 'lib/trooper/configuration.rb', line 73 def runner(strategy_name) strategy = Arsenal.strategies[strategy_name] Runner.new(strategy, self) end |
#set(hash) ⇒ Object
Public: Set variables that will be available to all actions.
hash - A key value hash to merge with config
Examples
@config.set(:my_variable => 'sdsd') # => available as method in an action
Returns self.
87 88 89 |
# File 'lib/trooper/configuration.rb', line 87 def set(hash) config.merge! hash end |
#to_s ⇒ Object
Public: Terminal Friendly version of the configuration.
Examples
@configuration.to_s # => '...'
Returns a String.
60 61 62 |
# File 'lib/trooper/configuration.rb', line 60 def to_s config.map {|k,v| "#{k}: #{v}" }.join("\n") end |