Class: CloudFormation::EventGenerator
- Inherits:
-
Object
- Object
- CloudFormation::EventGenerator
- 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
-
#action ⇒ Object
Returns the value of attribute action.
-
#klass ⇒ Object
Returns the value of attribute klass.
Instance Method Summary collapse
- #api_path ⇒ Object
- #hash_representation ⇒ Object
- #http_method ⇒ Object
-
#initialize(klass:, action:) ⇒ EventGenerator
constructor
A new instance of EventGenerator.
- #restify_klass_name ⇒ Object
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
#action ⇒ Object
Returns the value of attribute action.
16 17 18 |
# File 'lib/svrless/generators/cloud_formation/event_generator.rb', line 16 def action @action end |
#klass ⇒ Object
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_path ⇒ Object
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_representation ⇒ Object
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_method ⇒ Object
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_name ⇒ Object
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 |