Module: FriendlyId::Scoped::Configuration

Defined in:
lib/friendly_id/scoped.rb

Overview

This module adds the :scope configuration option to FriendlyId::Configuration.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#scopeObject

Gets the scope value.

When setting this value, the argument should be a symbol referencing a belongs_to relation, or a column.

Returns:

  • Symbol The scope value


156
157
158
# File 'lib/friendly_id/scoped.rb', line 156

def scope
  @scope
end

Instance Method Details

#reflection_foreign_key(scope) ⇒ Object (private)


172
173
174
175
# File 'lib/friendly_id/scoped.rb', line 172

def reflection_foreign_key(scope)
  reflection = model_class.reflections[scope] || model_class.reflections[scope.to_s]
  reflection.try(:foreign_key)
end

#scope_columnsObject

Gets the scope columns.

Checks to see if the :scope option passed to Base#friendly_id refers to a relation, and if so, returns the realtion's foreign key. Otherwise it assumes the option value was the name of column and returns it cast to a String.

Returns:

  • String The scope column


166
167
168
# File 'lib/friendly_id/scoped.rb', line 166

def scope_columns
  [@scope].flatten.map { |s| (reflection_foreign_key(s) or s).to_s }
end