Class: Cody::Schedule
- Inherits:
-
Object
- Object
- Cody::Schedule
- Includes:
- Dsl::Schedule, Evaluate, Variables
- Defined in:
- lib/cody/schedule.rb
Constant Summary
Constants included from Dsl::Schedule
Instance Method Summary collapse
- #default_properties ⇒ Object
-
#initialize(options = {}) ⇒ Schedule
constructor
A new instance of Schedule.
- #run ⇒ Object
- #set_rule_event! ⇒ Object
Methods included from Variables
#load_variables, #load_variables_file
Methods included from Evaluate
Methods included from Evaluate::Interface
#full_project_name, #project_name
Methods included from Dsl::Schedule
Constructor Details
#initialize(options = {}) ⇒ Schedule
Returns a new instance of Schedule.
7 8 9 10 11 12 |
# File 'lib/cody/schedule.rb', line 7 def initialize(={}) @options = @schedule_path = [:schedule_path] || get_schedule_path @properties = default_properties @iam_policy = {} end |
Instance Method Details
#default_properties ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/cody/schedule.rb', line 48 def default_properties description = "Cody #{@options[:full_project_name]}" name = description.gsub(" ", "-").downcase { description: "#{description} CodeBuild project", # event_pattern: , name: name, # schedule_expression: , state: "ENABLED", targets: [{ arn: { "Fn::GetAtt": "CodeBuild.Arn" }, role_arn: { "Fn::GetAtt": "EventsRuleRole.Arn" }, # required for specific CodeBuild target. id: "CodeBuildTarget", }] } end |
#run ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cody/schedule.rb', line 14 def run return unless File.exist?(@schedule_path) old_properties = @properties.clone load_variables evaluate(@schedule_path) @properties[:schedule_expression] = @schedule_expression if @schedule_expression set_rule_event! if @rule_event_props return if old_properties == @properties # empty schedule.rb file resource = { events_rule: { type: "AWS::Events::Rule", properties: @properties }, events_rule_role: events_rule_role, } CfnCamelizer.transform(resource) end |
#set_rule_event! ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cody/schedule.rb', line 35 def set_rule_event! props = @rule_event_props if props.key?(:detail) description = props.key?(:description) ? props.delete(:description) : rule_description rule_props = { event_pattern: props, description: description } else # if props.key?(:event_pattern) props[:description] ||= rule_description rule_props = props end @properties.merge!(rule_props) end |