Class: Cody::Schedule

Inherits:
Dsl::Base show all
Includes:
Dsl::Schedule, Evaluate, Variables
Defined in:
lib/cody/schedule.rb

Constant Summary

Constants included from Dsl::Schedule

Dsl::Schedule::PROPERTIES

Instance Attribute Summary

Attributes inherited from Dsl::Base

#full_project_name, #options, #project_name, #type

Instance Method Summary collapse

Methods included from Variables

#load_variables, #load_variables_file

Methods included from Evaluate

#lookup_cody_file

Methods included from Evaluate::Interface

#full_project_name, #project_name

Methods included from Dsl::Schedule

#cron, #rate, #rule_event

Methods inherited from Dsl::Base

#auto_camelize

Constructor Details

#initialize(options = {}) ⇒ Schedule

Returns a new instance of Schedule.



7
8
9
10
11
# File 'lib/cody/schedule.rb', line 7

def initialize(options={})
  super
  @schedule_path = options[:schedule_path] || get_schedule_path
  @iam_policy = {}
end

Instance Method Details

#default_propertiesObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/cody/schedule.rb', line 47

def default_properties
  description = "Cody #{@options[:full_project_name]}"
  name = description.gsub(" ", "-").downcase
  {
    Description: "#{description} CodeBuild project",
    # EventPattern: ,
    Name: name,
    # ScheduleExpression: ,
    State: "ENABLED",
    Targets: [{
      Arn: { "Fn::GetAtt": "CodeBuild.Arn" },
      RoleArn: { "Fn::GetAtt": "EventsRuleRole.Arn" }, # required for specific CodeBuild target.
      Id: "CodeBuildTarget",
    }]
  }
end

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cody/schedule.rb', line 13

def run
  return unless File.exist?(@schedule_path)

  old_properties = @properties.clone
  load_variables
  evaluate_file(@schedule_path)

  @properties[:ScheduleExpression] = @schedule_expression if @schedule_expression
  set_rule_event! if @rule_event_props
  return if old_properties == @properties # empty schedule.rb file

  resource = {
    EventsRule: {
      Type: "AWS::Events::Rule",
      Properties: @properties
    },
    EventsRuleRole: events_rule_role,
  }
  auto_camelize(resource)
end

#set_rule_event!Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cody/schedule.rb', line 34

def set_rule_event!
  props = @rule_event_props
  if props.key?(:Detail)
    description = props.key?(:Description) ? props.delete(:Description) : rule_description
    rule_props = { EventPattern: props, description: description }
  else # if props.key?(:EventPattern)
    props[:Description] ||= rule_description
    rule_props = props
  end

  @properties.merge!(rule_props)
end