Class: Foreplay::Engine
- Inherits:
-
Object
- Object
- Foreplay::Engine
- Includes:
- Foreplay
- Defined in:
- lib/foreplay/engine.rb
Defined Under Namespace
Classes: Remote, Role, Server, Step
Constant Summary collapse
- DEFAULTS_KEY =
'defaults'- CONFIG_FILE =
"#{Dir.getwd}/config/foreplay.yml"
Constants included from Foreplay
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
Instance Method Summary collapse
- #check ⇒ Object
- #deploy ⇒ Object
- #execute ⇒ Object
-
#initialize(e, f) ⇒ Engine
constructor
A new instance of Engine.
-
#supermerge(hash, other_hash) ⇒ Object
Returns a new hash with
hashandother_hashmerged recursively, including arrays.
Methods included from Foreplay
Constructor Details
#initialize(e, f) ⇒ Engine
Returns a new instance of Engine.
11 12 13 14 |
# File 'lib/foreplay/engine.rb', line 11 def initialize(e, f) @environment = e @filters = f end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
6 7 8 |
# File 'lib/foreplay/engine.rb', line 6 def environment @environment end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
6 7 8 |
# File 'lib/foreplay/engine.rb', line 6 def filters @filters end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
6 7 8 |
# File 'lib/foreplay/engine.rb', line 6 def mode @mode end |
Instance Method Details
#check ⇒ Object
21 22 23 24 |
# File 'lib/foreplay/engine.rb', line 21 def check @mode = :check execute end |
#deploy ⇒ Object
16 17 18 19 |
# File 'lib/foreplay/engine.rb', line 16 def deploy @mode = :deploy execute end |
#execute ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/foreplay/engine.rb', line 26 def execute # Explain what we're going to do puts "#{mode.capitalize}ing #{environment.dup.yellow} environment, "\ "#{explanatory_text(filters, 'role')}, #{explanatory_text(filters, 'server')}" threads = [] roles.each do |role, additional_instructions| next if role == DEFAULTS_KEY # 'defaults' is not a role next if filters.key?('role') && filters['role'] != role threads.concat Foreplay::Engine::Role.new( environment, mode, build_instructions(role, additional_instructions) ).threads end threads.each(&:join) puts mode == :deploy ? 'Finished deployment' : 'Deployment configuration check was successful' end |
#supermerge(hash, other_hash) ⇒ Object
Returns a new hash with hash and other_hash merged recursively, including arrays.
h1 = { x: { y: [4,5,6] }, z: [7,8,9] }
h2 = { x: { y: [7,8,9] }, z: 'xyz' }
h1.supermerge(h2)
#=> {:x=>{:y=>[4, 5, 6, 7, 8, 9]}, :z=>[7, 8, 9, "xyz"]}
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/foreplay/engine.rb', line 55 def supermerge(hash, other_hash) fail 'supermerge only works if you pass two hashes. '\ "You passed a #{hash.class} and a #{other_hash.class}." unless hash.is_a?(Hash) && other_hash.is_a?(Hash) new_hash = hash.deep_dup.with_indifferent_access other_hash.each_pair do |k, v| tv = new_hash[k] if tv.is_a?(Hash) && v.is_a?(Hash) new_hash[k] = supermerge(tv, v) elsif tv.is_a?(Array) || v.is_a?(Array) new_hash[k] = Array.wrap(tv) + Array.wrap(v) else new_hash[k] = v end end new_hash end |