Class: ActivePermalink::Querying::PermalinkLocator

Inherits:
Object
  • Object
show all
Defined in:
lib/active_permalink/querying.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, options) ⇒ PermalinkLocator

Returns a new instance of PermalinkLocator.



42
43
44
45
# File 'lib/active_permalink/querying.rb', line 42

def initialize(model, options)
  @model   = model
  @options = options
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



40
41
42
# File 'lib/active_permalink/querying.rb', line 40

def model
  @model
end

#optionsObject (readonly)

Returns the value of attribute options.



40
41
42
# File 'lib/active_permalink/querying.rb', line 40

def options
  @options
end

Instance Method Details

#locate(*args) ⇒ Object



52
53
54
# File 'lib/active_permalink/querying.rb', line 52

def locate(*args)
  find_record(:find_by, *args)
end

#locate!(*args) ⇒ Object



56
57
58
# File 'lib/active_permalink/querying.rb', line 56

def locate!(*args)
  find_record(:find_by!, *args)
end

#scope(value, locale: nil) ⇒ Object



47
48
49
50
# File 'lib/active_permalink/querying.rb', line 47

def scope(value, locale: nil)
  params = localize(slug: value, locale: locale)
  model.joins(:permalinks).where(permalinks: params)
end