Module: ActionDispatch::Routing::Mapper::Resources

Defined in:
lib/active_scaffold/extensions/routing_mapper.rb

Instance Method Summary collapse

Instance Method Details

#as_association_routesObject



110
111
112
113
114
# File 'lib/active_scaffold/extensions/routing_mapper.rb', line 110

def as_association_routes
  define_active_scaffold_association_concern unless @concerns[:active_scaffold_association]
  ActiveSupport::Deprecation.warn 'Use concerns: :active_scaffold_association in resources instead of as_association_routes, or concerns :active_scaffold_association in resources block if want to restrict routes with only or except options.'
  concerns :active_scaffold_association, parent_options
end

#as_nested_resources(*resources) ⇒ Object



116
117
118
119
120
121
122
# File 'lib/active_scaffold/extensions/routing_mapper.rb', line 116

def as_nested_resources(*resources)
  options = resources.extract_options!
  nested_options = options.merge(parent_scaffold: parent_scaffold)
  resources.each do |resource|
    resources(resource, nested_options.merge(association: resource)) { yield if block_given? }
  end
end

#as_routes(opts = {association: true}) ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/active_scaffold/extensions/routing_mapper.rb', line 101

def as_routes(opts = {association: true})
  define_active_scaffold_concern unless @concerns[:active_scaffold]
  if opts[:association] && !@concerns[:active_scaffold_association]
    define_active_scaffold_association_concern
  end
  ActiveSupport::Deprecation.warn 'Use concerns: :active_scaffold in resources instead of as_routes, or concerns :active_scaffold in resources block if want to disable association routes or restrict routes with only or except options.'
  concerns :active_scaffold, parent_options.merge(association: opts[:association])
end

#as_scoped_routes(*scopes) ⇒ Object



124
125
126
127
128
129
130
# File 'lib/active_scaffold/extensions/routing_mapper.rb', line 124

def as_scoped_routes(*scopes)
  options = scopes.extract_options!
  scoped_options = options.merge(parent_scaffold: parent_scaffold, association: parent_resource.plural)
  scopes.each do |scope|
    resources(scope, scoped_options.merge(named_scope: scope)) { yield if block_given? }
  end
end

#define_active_scaffold_association_concernObject



96
97
98
99
# File 'lib/active_scaffold/extensions/routing_mapper.rb', line 96

def define_active_scaffold_association_concern
  ActiveSupport::Deprecation.warn 'Add concern :active_scaffold_association, ActiveScaffold::Routing::Association.new to your routes file.'
  concern :active_scaffold_association, ActiveScaffold::Routing::Association.new
end

#define_active_scaffold_concernObject



91
92
93
94
# File 'lib/active_scaffold/extensions/routing_mapper.rb', line 91

def define_active_scaffold_concern
  ActiveSupport::Deprecation.warn 'Add concern :active_scaffold, ActiveScaffold::Routing::Basic.new(association: true) to your routes file.'
  concern :active_scaffold, ActiveScaffold::Routing::Basic.new(association: true)
end

#parent_optionsObject



80
81
82
83
84
85
86
87
88
89
# File 'lib/active_scaffold/extensions/routing_mapper.rb', line 80

def parent_options
  opts = parent_resource.instance_variable_get(:@options)
  if Rails.version >= '5.0.0'
    opts.merge(
      only: parent_resource.instance_variable_get(:@only),
      except: parent_resource.instance_variable_get(:@except)
    )
  end
  opts
end

#parent_scaffoldObject



132
133
134
# File 'lib/active_scaffold/extensions/routing_mapper.rb', line 132

def parent_scaffold
  merge_module_scope(@scope[:module], parent_resource.plural)
end