Class: APIGatewayDSL::Template
- Inherits:
-
Object
- Object
- APIGatewayDSL::Template
- Defined in:
- lib/api_gateway_dsl/template.rb,
lib/api_gateway_dsl/template/collection.rb
Defined Under Namespace
Classes: Collection
Instance Attribute Summary collapse
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(context, **options) ⇒ Template
constructor
A new instance of Template.
- #parameter ⇒ Object
- #schema_value ⇒ Object
Constructor Details
#initialize(context, **options) ⇒ Template
Returns a new instance of Template.
11 12 13 14 15 16 17 18 19 |
# File 'lib/api_gateway_dsl/template.rb', line 11 def initialize(context, **) @context = context @schema = [:schema] || @context.default_body_file @velocity = [:velocity] || @context.default_body_file @description = [:description].try(:strip_heredoc) @content_type = [:content_type] || 'application/json' end |
Instance Attribute Details
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
4 5 6 |
# File 'lib/api_gateway_dsl/template.rb', line 4 def content_type @content_type end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
4 5 6 |
# File 'lib/api_gateway_dsl/template.rb', line 4 def description @description end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
4 5 6 |
# File 'lib/api_gateway_dsl/template.rb', line 4 def schema @schema end |
Class Method Details
.new_if_schema_present(context, **options) ⇒ Object
6 7 8 9 |
# File 'lib/api_gateway_dsl/template.rb', line 6 def self.new_if_schema_present(context, **) template = new(context, **) template.schema_value ? template : nil end |
Instance Method Details
#as_json ⇒ Object
21 22 23 |
# File 'lib/api_gateway_dsl/template.rb', line 21 def as_json current_dir.join("#{@velocity}.vtl").read end |
#parameter ⇒ Object
35 36 37 |
# File 'lib/api_gateway_dsl/template.rb', line 35 def parameter Parameter::Body.new(self) end |
#schema_value ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/api_gateway_dsl/template.rb', line 25 def schema_value return unless current_dir if (file = current_dir.join("#{@schema}.json")).exist? JSON.parse(file.read) elsif (file = current_dir.join("#{@schema}.yml")).exist? YAML.safe_load(file.read) end end |