Class: Inari::Configuration
- Includes:
- Singleton
- Defined in:
- lib/inari/configuration.rb
Overview
Loads the tasks file and defines task manager to carry out the tasks
Defined Under Namespace
Classes: Server
Instance Attribute Summary collapse
-
#default_load_path ⇒ Object
readonly
The load paths used for locating recipe files.
-
#load_paths ⇒ Object
readonly
The load paths used for locating recipe files.
-
#options ⇒ Object
readonly
The hash of global options.
-
#servers ⇒ Object
readonly
The hash of servers.
-
#taskmanager ⇒ Object
readonly
The TaskManager created for this configuration instance.
Instance Method Summary collapse
- #config(field, *args) ⇒ Object
-
#desc(text) ⇒ Object
Describe the next task to be defined.
-
#initialize ⇒ Configuration
constructor
:nodoc:.
-
#load(*args, &block) ⇒ Object
Load a configuration file or string into this configuration.
-
#logger ⇒ Object
Returns the logging object.
-
#method_missing(sym, *args, &block) ⇒ Object
:nodoc:.
- #run_tasks ⇒ Object
-
#server(which, *args) ⇒ Object
Define a new server and its associated servers.
-
#task(name, options = {}, &block) ⇒ Object
Define a new task.
Constructor Details
#initialize ⇒ Configuration
:nodoc:
20 21 22 23 24 25 26 27 |
# File 'lib/inari/configuration.rb', line 20 def initialize() #:nodoc: @servers = Hash.new { |h, k| h[k] = [] } @options = Hash.new { |h, k| h[k] = [] } @default_load_path = File.join(Config::CONFIG['prefix'], 'etc') @load_paths = ['.', @default_load_path] @now = Time.now.utc @taskmanager = TaskManager.instance end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
:nodoc:
120 121 122 123 124 125 126 |
# File 'lib/inari/configuration.rb', line 120 def method_missing(sym, *args, &block) #:nodoc: if args.length == 0 && block.nil? && @variables.has_key?(sym) self[sym] else super end end |
Instance Attribute Details
#default_load_path ⇒ Object (readonly)
The load paths used for locating recipe files.
12 13 14 |
# File 'lib/inari/configuration.rb', line 12 def default_load_path @default_load_path end |
#load_paths ⇒ Object (readonly)
The load paths used for locating recipe files.
12 13 14 |
# File 'lib/inari/configuration.rb', line 12 def load_paths @load_paths end |
#options ⇒ Object (readonly)
The hash of global options.
18 19 20 |
# File 'lib/inari/configuration.rb', line 18 def @options end |
#servers ⇒ Object (readonly)
The hash of servers.
15 16 17 |
# File 'lib/inari/configuration.rb', line 15 def servers @servers end |
#taskmanager ⇒ Object (readonly)
The TaskManager created for this configuration instance.
9 10 11 |
# File 'lib/inari/configuration.rb', line 9 def taskmanager @taskmanager end |
Instance Method Details
#config(field, *args) ⇒ Object
88 89 90 |
# File 'lib/inari/configuration.rb', line 88 def config(field, *args) @options[field] = args end |
#desc(text) ⇒ Object
Describe the next task to be defined.
93 94 95 |
# File 'lib/inari/configuration.rb', line 93 def desc(text) @next_description = text end |
#load(*args, &block) ⇒ Object
Load a configuration file or string into this configuration.
Usage:
load(:file => "settings.conf"):
Load a configuration file.
load(:string => "set :scm, :subversion"):
Load the given string as a configuration specification.
load { ... }
Load the block in the context of the configuration.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/inari/configuration.rb', line 41 def load(*args, &block) = args.last.is_a?(Hash) ? args.pop : {} args.each { |arg| load .merge(:file => arg) } return unless args.empty? if block raise 'Loading a block requires 2 parameters' unless args.empty? load(.merge(:proc => block)) elsif [:file] file = [:file] unless file[0] == ?/ load_paths.each do |path| if File.file?(File.join(path, file)) file = File.join(path, file) break end end raise ArgumentError, "Configuration file #{file} not found." if file.nil? end load :string => File.read(file), :name => [:name] || file elsif [:string] instance_eval([:string], [:name] || "<eval>") elsif [:proc] instance_eval(&[:proc]) else raise ArgumentError, "Don't know how to load #{.inspect}" end end |
#logger ⇒ Object
Returns the logging object
98 99 100 |
# File 'lib/inari/configuration.rb', line 98 def logger Inari::logger end |
#run_tasks ⇒ Object
116 117 118 |
# File 'lib/inari/configuration.rb', line 116 def run_tasks taskmanager.run_tasks end |
#server(which, *args) ⇒ Object
Define a new server and its associated servers. You must specify at least one host for each server.
Usage:
server :db, 'db1.example.com', 'db2.example.com'
server :mail, 'mail.example.com'
83 84 85 86 |
# File 'lib/inari/configuration.rb', line 83 def server(which, *args) raise ArgumentError, 'must give at least one host' if args.empty? args.each { |host| servers[which] << Server.new(host) } end |
#task(name, options = {}, &block) ⇒ Object
Define a new task. If a description is active (see #desc), it is added to the options under the :desc
key. This method ultimately delegates to TaskManager#define_task.
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/inari/configuration.rb', line 105 def task(name, ={}, &block) raise ArgumentError, 'expected a block' unless block if @next_description = .merge(:desc => @next_description) @next_description = nil end taskmanager.define_task(name, , &block) end |