Class: Belt::NestedResourceBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/belt/route_dsl.rb

Instance Method Summary collapse

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

#collectionObject



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

#memberObject



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, options = {}, &block)
  resource_name = name.to_s
  singular = @gateway.send(:singularize, resource_name)
  param_name = options[:param] || "#{singular}_id"
  options = options.merge(tables: [resource_name.to_sym]) unless options.key?(:tables)
  options = merge_inherited_options(options)
  resource_options = options.merge(route_type: :resources)
  actions = @gateway.send(:determine_actions, options)

  add_nested_resource_routes(resource_name, param_name, resource_options, 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(options[:tables] || []),
                                             inherited_auth: options[:auth] || @inherited_auth,
                                             inherited_controller: @inherited_controller,
                                             inherited_lambda: @inherited_lambda)
  nested_builder.instance_eval(&block)
end