module GollumRails::Finders::ClassMethods

Public Instance Methods

all(options={}) click to toggle source

Gets all pages in the wiki

Returns an Array with GollumRails::Page s

# File lib/gollum_rails/finders.rb, line 59
def all(options={})
  set_folder(options)
  pages = wiki.pages
  pages.map do |page|
    self.new(gollum_page: page)
  end
end
Also aliased as: find_all
find(name, version=nil, folder_reset=false, exact=true) click to toggle source

Finds a page based on the name and specified version

name - the name of the page version - optional - The pages version folder_reset - optional - resets the folder to / before performing the search exact - optional - perform an exact match

Return an instance of Gollum::Page

# File lib/gollum_rails/finders.rb, line 29
def find(name, version=nil, folder_reset=false, exact=true)
  name = name[:name] if name.kind_of?(Hash) && name.has_key?(:name)
  Page.reset_folder if folder_reset
  wiki.clear_cache
  path = File.split(name)
  if path.first == '/' || path.first == '.'
    folder = nil
  else
    folder = path.first
  end
  page = wiki.paged(path.last, folder, exact, version)
  if page
    new(gollum_page: page)
  else
    nil
  end
end
find_all(options={})

Aliasing this for ActiveRecord behavior

Alias for: all
find_or_initialize_by_name(name, commit={}) click to toggle source

Find an existing page or create it

name - The name commit - Hash

Returns self

# File lib/gollum_rails/finders.rb, line 12
def find_or_initialize_by_name(name, commit={})
  result = find(name)
  if result
    result
  else
    new(:format => :markdown, :name => name, :content => ".", :commit => commit)
  end
end
first(options={}) click to toggle source

Gets the last item from `all` method call

options - optional - some options e.g. :folder

Returns a single GollumRails::Page

# File lib/gollum_rails/finders.rb, line 72
def first(options={})
  all(options).first
end
last(options={}) click to toggle source

Gets the first item from `all` method call

options - optional - some options e.g. :folder

Returns a single GollumRails::Page

# File lib/gollum_rails/finders.rb, line 81
def last(options={})
  all(options).last
end
method_missing(name, *args) click to toggle source

Catch-all method

Calls superclass method
# File lib/gollum_rails/finders.rb, line 89
def method_missing(name, *args)
  if name =~ /^find_by_(name)$/
    self.find(args.first)
  else super
  end
end