Class: Codebuild::Schedule

Inherits:
Object
  • Object
show all
Includes:
Dsl::Schedule, Evaluate, Variables
Defined in:
lib/codebuild/schedule.rb

Constant Summary

Constants included from Dsl::Schedule

Dsl::Schedule::PROPERTIES

Instance Method Summary collapse

Methods included from Variables

#load_variables, #load_variables_file

Methods included from Evaluate

#evaluate

Methods included from Dsl::Schedule

#cron, #rate, #rule_event

Constructor Details

#initialize(options = {}) ⇒ Schedule

Returns a new instance of Schedule.



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

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

Instance Method Details

#default_propertiesObject



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

def default_properties
  description = "CodeBuild #{@options[:full_project_name]}"
  name = description.gsub(" ", "-").downcase
  {
    description: description,
    # 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

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/codebuild/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/codebuild/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