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.
156 157 158 159 160 161 162 163 164 |
# File 'lib/belt/route_dsl.rb', line 156 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.
154 155 156 |
# File 'lib/belt/route_dsl.rb', line 154 def default_auth @default_auth end |
#default_cors ⇒ Object (readonly)
Returns the value of attribute default_cors.
154 155 156 |
# File 'lib/belt/route_dsl.rb', line 154 def default_cors @default_cors end |
#default_lambda ⇒ Object (readonly)
Returns the value of attribute default_lambda.
154 155 156 |
# File 'lib/belt/route_dsl.rb', line 154 def default_lambda @default_lambda end |
#default_tables ⇒ Object (readonly)
Returns the value of attribute default_tables.
154 155 156 |
# File 'lib/belt/route_dsl.rb', line 154 def default_tables @default_tables end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
154 155 156 |
# File 'lib/belt/route_dsl.rb', line 154 def name @name end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
154 155 156 |
# File 'lib/belt/route_dsl.rb', line 154 def routes @routes end |
Instance Method Details
#lambda(name) ⇒ Object
166 167 168 169 170 171 |
# File 'lib/belt/route_dsl.rb', line 166 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
206 207 208 209 210 211 212 213 214 215 |
# File 'lib/belt/route_dsl.rb', line 206 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
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/belt/route_dsl.rb', line 179 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 |