Class: Belt::NestedResourceBuilder
- Inherits:
-
Object
- Object
- Belt::NestedResourceBuilder
- Defined in:
- lib/belt/route_dsl.rb
Instance Method Summary collapse
- #collection ⇒ Object
-
#initialize(gateway, prefix, collection_prefix, inherited_tables: [], inherited_auth: nil) ⇒ NestedResourceBuilder
constructor
A new instance of NestedResourceBuilder.
- #member ⇒ Object
- #resources(name, options = {}) ⇒ Object
Constructor Details
#initialize(gateway, prefix, collection_prefix, inherited_tables: [], inherited_auth: nil) ⇒ NestedResourceBuilder
Returns a new instance of NestedResourceBuilder.
52 53 54 55 56 57 58 |
# File 'lib/belt/route_dsl.rb', line 52 def initialize(gateway, prefix, collection_prefix, inherited_tables: [], inherited_auth: nil) @gateway = gateway @prefix = prefix @collection_prefix = collection_prefix @inherited_tables = inherited_tables @inherited_auth = inherited_auth end |
Instance Method Details
#collection ⇒ Object
89 90 91 92 |
# File 'lib/belt/route_dsl.rb', line 89 def collection(&) MemberCollectionBuilder.new(@gateway, @collection_prefix, @inherited_tables, @inherited_auth).instance_eval(&) end |
#member ⇒ Object
85 86 87 |
# File 'lib/belt/route_dsl.rb', line 85 def member(&) MemberCollectionBuilder.new(@gateway, @prefix, @inherited_tables, @inherited_auth).instance_eval(&) end |
#resources(name, options = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/belt/route_dsl.rb', line 60 def resources(name, = {}) resource_name = name.to_s singular = @gateway.send(:singularize, resource_name) param_name = [:param] || "#{singular}_id" = () = @gateway.send(:auto_infer_tables, resource_name, ) = .merge(route_type: :resources) actions = @gateway.send(:determine_actions, ) @gateway.send(:add_route, :get, "#{@prefix}/#{resource_name}", ) if actions.include?(:index) @gateway.send(:add_route, :post, "#{@prefix}/#{resource_name}", ) if actions.include?(:create) if actions.include?(:show) @gateway.send(:add_route, :get, "#{@prefix}/#{resource_name}/{#{param_name}}", ) end if actions.include?(:update) @gateway.send(:add_route, :put, "#{@prefix}/#{resource_name}/{#{param_name}}", ) end return unless actions.include?(:destroy) @gateway.send(:add_route, :delete, "#{@prefix}/#{resource_name}/{#{param_name}}", ) end |