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.
192 193 194 195 196 197 198 199 200 |
# File 'lib/belt/route_dsl.rb', line 192 def initialize(name, = {}) @name = name.to_s @routes = [] @default_auth = [:auth] || :none @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.
190 191 192 |
# File 'lib/belt/route_dsl.rb', line 190 def default_auth @default_auth end |
#default_cors ⇒ Object (readonly)
Returns the value of attribute default_cors.
190 191 192 |
# File 'lib/belt/route_dsl.rb', line 190 def default_cors @default_cors end |
#default_lambda ⇒ Object (readonly)
Returns the value of attribute default_lambda.
190 191 192 |
# File 'lib/belt/route_dsl.rb', line 190 def default_lambda @default_lambda end |
#default_tables ⇒ Object (readonly)
Returns the value of attribute default_tables.
190 191 192 |
# File 'lib/belt/route_dsl.rb', line 190 def default_tables @default_tables end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
190 191 192 |
# File 'lib/belt/route_dsl.rb', line 190 def name @name end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
190 191 192 |
# File 'lib/belt/route_dsl.rb', line 190 def routes @routes end |
Instance Method Details
#lambda(name) ⇒ Object
202 203 204 205 206 207 |
# File 'lib/belt/route_dsl.rb', line 202 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
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/belt/route_dsl.rb', line 240 def resource(name, = {}) resource_name = name.to_s actions = determine_actions(, default: %i[show update destroy]) = .merge(route_type: :resource) if actions.include?(:show) add_route(:get, "/#{resource_name}", resolve_request_model_for(, :show)) end if actions.include?(:update) add_route(:put, "/#{resource_name}", resolve_request_model_for(, :update)) end if actions.include?(:destroy) add_route(:delete, "/#{resource_name}", resolve_request_model_for(, :destroy)) end return unless actions.include?(:create) add_route(:post, "/#{resource_name}", resolve_request_model_for(, :create)) end |
#resources(name, options = {}) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/belt/route_dsl.rb', line 215 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_resource_routes(resource_name, param_name, , actions) 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 inherited_lambda = [:lambda] nested_builder = NestedResourceBuilder.new(self, member_prefix, collection_prefix, inherited_tables: inherited_tables, inherited_auth: inherited_auth, inherited_lambda: inherited_lambda) nested_builder.instance_eval(&) end |