Class: Applb::DSL::EC2::LoadBalancer::Listeners::Listener::Rules::Rule::Result
- Inherits:
-
Object
- Object
- Applb::DSL::EC2::LoadBalancer::Listeners::Listener::Rules::Rule::Result
- Defined in:
- lib/applb/dsl/rule.rb
Constant Summary collapse
- ATTRIBUTES =
%i/priority actions conditions listener_arn rule_arn/
Instance Method Summary collapse
- #aws(aws_rule) ⇒ Object
- #create ⇒ Object
-
#initialize(context, listener) ⇒ Result
constructor
A new instance of Result.
- #modify ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(context, listener) ⇒ Result
Returns a new instance of Result.
15 16 17 18 19 |
# File 'lib/applb/dsl/rule.rb', line 15 def initialize(context, listener) @context = context @options = context. @listener = listener end |
Instance Method Details
#aws(aws_rule) ⇒ Object
21 22 23 24 |
# File 'lib/applb/dsl/rule.rb', line 21 def aws(aws_rule) @aws_rule = aws_rule self end |
#create ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/applb/dsl/rule.rb', line 30 def create Applb.logger.info("Create rule #{conditions.first[:values].first}") return if @options[:dry_run] Applb.logger.debug("create rule with option blow.") Applb.logger.debug(create_option.pretty_inspect) rule = client.create_rule(create_option).rules.first rule_arn = rule.rule_arn rule end |
#modify ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/applb/dsl/rule.rb', line 41 def modify dsl_hash = to_diff_h aws_hash = to_diff_h_aws result = nil # modify rule if dsl_hash != aws_hash Applb.logger.info("Modify rule #{@aws_rule.rule_arn}") Applb.logger.info("<diff>\n#{Applb::Utils.diff(aws_hash, dsl_hash, color: @options[:color])}") unless @options[:dry_run] result = client.modify_rule(modify_option).rules.first end end # modify rule priority if priority.to_s != @aws_rule.priority Applb.logger.info("Modify priority #{@aws_rule.priority} to #{priority}") Applb.logger.info("<diff>\n#{Applb::Utils.diff(@aws_rule.priority, priority, color: @options[:color])}") unless @options[:dry_run] rule_priority_option = { rule_priorities: [{ rule_arn: @aws_rule.rule_arn, priority: priority}] } result = client.set_rule_priorities(rule_priority_option).rules.first end end result end |
#to_h ⇒ Object
26 27 28 |
# File 'lib/applb/dsl/rule.rb', line 26 def to_h Hash[ATTRIBUTES.sort.map { |name| [name, public_send(name)] }] end |