Class: Foreplay::Engine
- Inherits:
-
Object
- Object
- Foreplay::Engine
- Includes:
- Foreplay
- Defined in:
- lib/foreplay/engine.rb
Defined Under Namespace
Classes: Remote, Role, Secrets, Server, Step
Constant Summary collapse
- DEFAULT_CONFIG_FILE =
"#{Dir.getwd}/config/foreplay.yml"
- DEFAULTS_KEY =
'defaults'
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
hash
andother_hash
merged recursively, including arrays.
Methods included from Foreplay
Constructor Details
#initialize(e, f) ⇒ Engine
Returns a new instance of Engine.
12 13 14 15 |
# File 'lib/foreplay/engine.rb', line 12 def initialize(e, f) @environment = e @filters = f end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
7 8 9 |
# File 'lib/foreplay/engine.rb', line 7 def environment @environment end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
7 8 9 |
# File 'lib/foreplay/engine.rb', line 7 def filters @filters end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
7 8 9 |
# File 'lib/foreplay/engine.rb', line 7 def mode @mode end |
Instance Method Details
#check ⇒ Object
22 23 24 25 |
# File 'lib/foreplay/engine.rb', line 22 def check @mode = :check execute end |
#deploy ⇒ Object
17 18 19 20 |
# File 'lib/foreplay/engine.rb', line 17 def deploy @mode = :deploy execute end |
#execute ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/foreplay/engine.rb', line 27 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"]}
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/foreplay/engine.rb', line 56 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 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 |