Class: Rigger::DSL
- Inherits:
-
Object
- Object
- Rigger::DSL
- Defined in:
- lib/rigger/dsl.rb
Instance Attribute Summary collapse
-
#servers ⇒ Object
readonly
Returns the value of attribute servers.
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
Instance Method Summary collapse
- #fetch(name, default) ⇒ Object
- #get(name) ⇒ Object
-
#initialize(server_factory = Server, task_factory = Task, file = File) ⇒ DSL
constructor
A new instance of DSL.
- #load_from_file(filename) ⇒ Object
- #locate_task(name) ⇒ Object
- #namespace(name, &block) ⇒ Object
- #server(role, host, options = {}) ⇒ Object
- #set(name, value) ⇒ Object
- #task(name, options = {}, &block) ⇒ Object
Constructor Details
#initialize(server_factory = Server, task_factory = Task, file = File) ⇒ DSL
Returns a new instance of DSL.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rigger/dsl.rb', line 8 def initialize(server_factory = Server, task_factory = Task, file = File) @server_factory = server_factory @task_factory = task_factory @file = file @tasks = {} @servers = [] @current_namespace = [] @vars = {} end |
Instance Attribute Details
#servers ⇒ Object (readonly)
Returns the value of attribute servers.
6 7 8 |
# File 'lib/rigger/dsl.rb', line 6 def servers @servers end |
#tasks ⇒ Object (readonly)
Returns the value of attribute tasks.
6 7 8 |
# File 'lib/rigger/dsl.rb', line 6 def tasks @tasks end |
Instance Method Details
#fetch(name, default) ⇒ Object
51 52 53 |
# File 'lib/rigger/dsl.rb', line 51 def fetch(name, default) @vars.fetch(name.to_s, default) end |
#get(name) ⇒ Object
47 48 49 |
# File 'lib/rigger/dsl.rb', line 47 def get(name) @vars[name.to_s] || missing_var(name) end |
#load_from_file(filename) ⇒ Object
35 36 37 |
# File 'lib/rigger/dsl.rb', line 35 def load_from_file(filename) instance_eval(@file.read(filename), filename) end |
#locate_task(name) ⇒ Object
39 40 41 |
# File 'lib/rigger/dsl.rb', line 39 def locate_task(name) @tasks[name.to_s] end |
#namespace(name, &block) ⇒ Object
20 21 22 23 24 |
# File 'lib/rigger/dsl.rb', line 20 def namespace(name, &block) @current_namespace << name yield @current_namespace.pop end |
#server(role, host, options = {}) ⇒ Object
26 27 28 |
# File 'lib/rigger/dsl.rb', line 26 def server(role, host, = {}) @servers << @server_factory.new(role, host, ) end |
#set(name, value) ⇒ Object
43 44 45 |
# File 'lib/rigger/dsl.rb', line 43 def set(name, value) @vars[name.to_s] = value end |
#task(name, options = {}, &block) ⇒ Object
30 31 32 33 |
# File 'lib/rigger/dsl.rb', line 30 def task(name, = {}, &block) full_name = (@current_namespace + [name]).join(":") @tasks[full_name] = @task_factory.new(full_name, , block) end |