Class: Dslimple::Applier
- Inherits:
-
Object
- Object
- Dslimple::Applier
- Defined in:
- lib/dslimple/applier.rb
Constant Summary collapse
- OPERATION_COLORS =
{ addition: :green, modification: :yellow, deletion: :red }.freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#shell ⇒ Object
readonly
Returns the value of attribute shell.
Instance Method Summary collapse
- #apply(queries) ⇒ Object
- #execute ⇒ Object
- #fetch_zones ⇒ Object
-
#initialize(client, shell, options = {}) ⇒ Applier
constructor
A new instance of Applier.
- #show_plan(queries) ⇒ Object
- #show_query(query) ⇒ Object
Constructor Details
#initialize(client, shell, options = {}) ⇒ Applier
Returns a new instance of Applier.
13 14 15 16 17 |
# File 'lib/dslimple/applier.rb', line 13 def initialize(client, shell, = {}) @client = client @shell = shell = end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
11 12 13 |
# File 'lib/dslimple/applier.rb', line 11 def client @client end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/dslimple/applier.rb', line 11 def end |
#shell ⇒ Object (readonly)
Returns the value of attribute shell.
11 12 13 |
# File 'lib/dslimple/applier.rb', line 11 def shell @shell end |
Instance Method Details
#apply(queries) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/dslimple/applier.rb', line 56 def apply(queries) shell.say('Apply', :bold) queries.each do |query| show_query(query) query.execute(client, client.account_id) end end |
#execute ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/dslimple/applier.rb', line 19 def execute dsl = Dslimple::DSL.new([:file], ) dsl.execute expected_zones = dsl.transform expected_zones.select! { |zone| [:only].include?(zone.name) } unless [:only].empty? @buildler = Dslimple::QueryBuilder.new(fetch_zones, expected_zones, ) @buildler.execute queries = @buildler.filtered_queries() if queries.empty? shell.say('No Changes', :bold) return end show_plan(queries) return if [:dry_run] || !([:yes] || shell.yes?("Apply #{queries.size} changes. OK?(y/n) >")) apply(queries) end |
#fetch_zones ⇒ Object
43 44 45 46 47 |
# File 'lib/dslimple/applier.rb', line 43 def fetch_zones zones = client.all_zones(with_records: true) zones.select! { |zone| [:only].include?(zone.name) } if [:only].any? zones end |
#show_plan(queries) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/dslimple/applier.rb', line 49 def show_plan(queries) shell.say('Changes', :bold) queries.each do |query| show_query(query) end end |
#show_query(query) ⇒ Object
64 65 66 |
# File 'lib/dslimple/applier.rb', line 64 def show_query(query) shell.say("#{shell.set_color(query.operation.to_s[0..2], OPERATION_COLORS[query.operation])} #{query}") end |