Class: Refinery::Pages::Finder

Inherits:
Object
  • Object
show all
Defined in:
pages/lib/refinery/pages/finder.rb

Direct Known Subclasses

FinderBySlug, FinderByTitle

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conditions) ⇒ Finder

Returns a new instance of Finder



24
25
26
# File 'pages/lib/refinery/pages/finder.rb', line 24

def initialize(conditions)
  @conditions = conditions
end

Class Method Details

.by_path(path) ⇒ Object



4
5
6
# File 'pages/lib/refinery/pages/finder.rb', line 4

def self.by_path(path)
  FinderByPath.new(path).find
end

.by_path_or_id(path, id) ⇒ Object



8
9
10
# File 'pages/lib/refinery/pages/finder.rb', line 8

def self.by_path_or_id(path, id)
  FinderByPathOrId.new(path, id).find
end

.by_slug(slug, conditions = {}) ⇒ Object



16
17
18
# File 'pages/lib/refinery/pages/finder.rb', line 16

def self.by_slug(slug, conditions = {})
  FinderBySlug.new(slug, conditions).find
end

.by_title(title) ⇒ Object



12
13
14
# File 'pages/lib/refinery/pages/finder.rb', line 12

def self.by_title(title)
  FinderByTitle.new(title).find
end

.with_globalize(conditions = {}) ⇒ Object



20
21
22
# File 'pages/lib/refinery/pages/finder.rb', line 20

def self.with_globalize(conditions = {})
  Finder.new(conditions).find
end

Instance Method Details

#findObject



28
29
30
# File 'pages/lib/refinery/pages/finder.rb', line 28

def find
  with_globalize
end

#with_globalizeObject



32
33
34
35
36
37
38
39
40
41
# File 'pages/lib/refinery/pages/finder.rb', line 32

def with_globalize
  globalized_conditions = {:locale => ::Globalize.locale.to_s}.merge(conditions)
  translations_conditions = translations_conditions(globalized_conditions)

  # A join implies readonly which we don't really want.
  Page.where(globalized_conditions).
       joins(:translations).
       where(translations_conditions).
       readonly(false)
end