Class: Rhod::Profile
- Inherits:
-
Hash
- Object
- Hash
- Rhod::Profile
- Defined in:
- lib/rhod/profile.rb
Constant Summary collapse
- @@profiles =
{}
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ Profile
constructor
A new instance of Profile.
Constructor Details
#initialize(name, options = {}) ⇒ Profile
Returns a new instance of Profile.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rhod/profile.rb', line 4 def initialize(name, ={}) # When creating new profiles, copy from the global default, in case it was customized. if @@profiles[:default] default = @@profiles[:default].dup else default = {} end default.each {|k,v| self[k] = v } .each {|k,v| self[k] = v } self[:profile_name] = name # Middleware stack construction self[:middleware_stack] = Rhod::Middleware.new if self[:middleware].respond_to?(:call) self[:middleware].call(self[:middleware_stack]) elsif self[:middleware] self[:middleware].each do |klass| self[:middleware_stack].use klass end end self[:middleware_stack].build_stack # Syntax sugar: named .with_#{profile} methods on this class and the module @@profiles[name] = self self.class.__send__(:define_method, :"with_#{name}") do |*args, &block| Rhod::Command.execute(*args, @@profiles[name], &block) end Rhod.class.__send__(:define_method, :"with_#{name}") do |*args, &block| Rhod::Command.execute(*args, @@profiles[name], &block) end self end |