Class: Belt::ApiGateway
- Inherits:
-
Object
- Object
- Belt::ApiGateway
- Defined in:
- lib/belt/route_dsl.rb
Instance Attribute Summary collapse
-
#default_auth ⇒ Object
readonly
Returns the value of attribute default_auth.
-
#default_cors ⇒ Object
readonly
Returns the value of attribute default_cors.
-
#default_lambda ⇒ Object
readonly
Returns the value of attribute default_lambda.
-
#default_tables ⇒ Object
readonly
Returns the value of attribute default_tables.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ ApiGateway
constructor
A new instance of ApiGateway.
- #lambda(name) ⇒ Object
- #resource(name, options = {}) ⇒ Object
- #resources(name, options = {}) ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ ApiGateway
Returns a new instance of ApiGateway.
148 149 150 151 152 153 154 155 156 |
# File 'lib/belt/route_dsl.rb', line 148 def initialize(name, = {}) @name = name.to_s @routes = [] @default_auth = [:auth] || :cognito @default_lambda = [:lambda] || name @default_cors = .fetch(:cors, true) @default_tables = Array([:tables] || []) @current_lambda_context = nil end |
Instance Attribute Details
#default_auth ⇒ Object (readonly)
Returns the value of attribute default_auth.
146 147 148 |
# File 'lib/belt/route_dsl.rb', line 146 def default_auth @default_auth end |
#default_cors ⇒ Object (readonly)
Returns the value of attribute default_cors.
146 147 148 |
# File 'lib/belt/route_dsl.rb', line 146 def default_cors @default_cors end |
#default_lambda ⇒ Object (readonly)
Returns the value of attribute default_lambda.
146 147 148 |
# File 'lib/belt/route_dsl.rb', line 146 def default_lambda @default_lambda end |
#default_tables ⇒ Object (readonly)
Returns the value of attribute default_tables.
146 147 148 |
# File 'lib/belt/route_dsl.rb', line 146 def default_tables @default_tables end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
146 147 148 |
# File 'lib/belt/route_dsl.rb', line 146 def name @name end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
146 147 148 |
# File 'lib/belt/route_dsl.rb', line 146 def routes @routes end |
Instance Method Details
#lambda(name) ⇒ Object
158 159 160 161 162 163 |
# File 'lib/belt/route_dsl.rb', line 158 def lambda(name, &) previous_context = @current_lambda_context @current_lambda_context = name.to_sym instance_eval(&) if block_given? @current_lambda_context = previous_context end |
#resource(name, options = {}) ⇒ Object
198 199 200 201 202 203 204 205 206 207 |
# File 'lib/belt/route_dsl.rb', line 198 def resource(name, = {}) resource_name = name.to_s actions = determine_actions(, default: %i[show update destroy]) = .merge(route_type: :resource) add_route(:get, "/#{resource_name}", ) if actions.include?(:show) add_route(:put, "/#{resource_name}", ) if actions.include?(:update) add_route(:delete, "/#{resource_name}", ) if actions.include?(:destroy) add_route(:post, "/#{resource_name}", ) if actions.include?(:create) end |
#resources(name, options = {}) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/belt/route_dsl.rb', line 171 def resources(name, = {}, &) resource_name = name.to_s singular = singularize(resource_name) param_name = [:param] || "#{singular}_id" = auto_infer_tables(resource_name, ) = .merge(route_type: :resources) actions = determine_actions() add_route(:get, "/#{resource_name}", ) if actions.include?(:index) add_route(:post, "/#{resource_name}", ) if actions.include?(:create) add_route(:get, "/#{resource_name}/{#{param_name}}", ) if actions.include?(:show) add_route(:put, "/#{resource_name}/{#{param_name}}", ) if actions.include?(:update) add_route(:delete, "/#{resource_name}/{#{param_name}}", ) if actions.include?(:destroy) return unless block_given? collection_prefix = "/#{resource_name}" member_prefix = "/#{resource_name}/{#{param_name}}" resource_tables = Array([:tables] || []) inherited_tables = (@default_tables + resource_tables).uniq inherited_auth = [:auth] || @default_auth nested_builder = NestedResourceBuilder.new(self, member_prefix, collection_prefix, inherited_tables: inherited_tables, inherited_auth: inherited_auth) nested_builder.instance_eval(&) end |