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.



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

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

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



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

def model
  @model
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#locate(*args) ⇒ Object



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

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

#locate!(*args) ⇒ Object



60
61
62
# File 'lib/active_permalink/querying.rb', line 60

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

#scope(value, locale: nil) ⇒ Object



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

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