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, inherited_controller: nil, inherited_lambda: nil) ⇒ NestedResourceBuilder
constructor
rubocop:disable Metrics/ParameterLists.
- #member ⇒ Object
- #resources(name, options = {}, &block) ⇒ Object
Constructor Details
#initialize(gateway, prefix, collection_prefix, inherited_tables: [], inherited_auth: nil, inherited_controller: nil, inherited_lambda: nil) ⇒ NestedResourceBuilder
rubocop:disable Metrics/ParameterLists
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/belt/route_dsl.rb', line 54 def initialize(gateway, prefix, collection_prefix, inherited_tables: [], inherited_auth: nil, # rubocop:disable Metrics/ParameterLists inherited_controller: nil, inherited_lambda: nil) @gateway = gateway @prefix = prefix @collection_prefix = collection_prefix @inherited_tables = inherited_tables @inherited_auth = inherited_auth @inherited_controller = inherited_controller @inherited_lambda = inherited_lambda end |
Instance Method Details
#collection ⇒ Object
92 93 94 95 |
# File 'lib/belt/route_dsl.rb', line 92 def collection(&) MemberCollectionBuilder.new(@gateway, @collection_prefix, @inherited_tables, @inherited_auth, @inherited_controller, @inherited_lambda).instance_eval(&) end |
#member ⇒ Object
87 88 89 90 |
# File 'lib/belt/route_dsl.rb', line 87 def member(&) MemberCollectionBuilder.new(@gateway, @prefix, @inherited_tables, @inherited_auth, @inherited_controller, @inherited_lambda).instance_eval(&) end |
#resources(name, options = {}, &block) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/belt/route_dsl.rb', line 65 def resources(name, = {}, &block) resource_name = name.to_s singular = @gateway.send(:singularize, resource_name) param_name = [:param] || "#{singular}_id" = .merge(tables: [resource_name.to_sym]) unless .key?(:tables) = () = .merge(route_type: :resources) actions = @gateway.send(:determine_actions, ) add_nested_resource_routes(resource_name, param_name, , actions) return unless block nested_member_prefix = "#{@prefix}/#{resource_name}/{#{param_name}}" nested_collection_prefix = "#{@prefix}/#{resource_name}" nested_builder = NestedResourceBuilder.new(@gateway, nested_member_prefix, nested_collection_prefix, inherited_tables: Array([:tables] || []), inherited_auth: [:auth] || @inherited_auth, inherited_controller: @inherited_controller, inherited_lambda: @inherited_lambda) nested_builder.instance_eval(&block) end |