Class: CloudFormation::EventGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/svrless/generators/cloud_formation/event_generator.rb

Overview

Responsible for generating a hash which will eventually look like this: Create:

Type: Api
Properties:
  Method: post
  Path: "/posts"

Input: klass: Class, action: :show Input: klass: Post, action: :update

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass:, action:) ⇒ EventGenerator

Returns a new instance of EventGenerator.



18
19
20
21
# File 'lib/svrless/generators/cloud_formation/event_generator.rb', line 18

def initialize(klass:, action:)
  @klass = klass
  @action = action
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



16
17
18
# File 'lib/svrless/generators/cloud_formation/event_generator.rb', line 16

def action
  @action
end

#klassObject

Returns the value of attribute klass.



16
17
18
# File 'lib/svrless/generators/cloud_formation/event_generator.rb', line 16

def klass
  @klass
end

Instance Method Details

#api_pathObject



48
49
50
51
52
# File 'lib/svrless/generators/cloud_formation/event_generator.rb', line 48

def api_path
  return "/#{restify_klass_name}" if @action == :create

  "/#{restify_klass_name}/{id}"
end

#hash_representationObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/svrless/generators/cloud_formation/event_generator.rb', line 23

def hash_representation
  {
    "#{@action}": {
      type: "Api",
      properties: {
        method: http_method,
        path: api_path
      }
    }
  }
end

#http_methodObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/svrless/generators/cloud_formation/event_generator.rb', line 35

def http_method
  case @action
  when :create
    "post"
  when :show
    "get"
  when :update
    "put"
  else
    "delete"
  end
end

#restify_klass_nameObject



54
55
56
# File 'lib/svrless/generators/cloud_formation/event_generator.rb', line 54

def restify_klass_name
  @klass.to_s.underscore.pluralize.dasherize
end