Module: GollumRails::Finders::ClassMethods

Defined in:
lib/gollum_rails/finders.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

Catch-all method


89
90
91
92
93
94
# 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

Instance Method Details

#all(options = {}) ⇒ Object Also known as: find_all

Gets all pages in the wiki

Returns an Array with GollumRails::Page s


59
60
61
62
63
64
65
# 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

#find(name, version = nil, folder_reset = false, exact = true) ⇒ Object

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


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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_or_initialize_by_name(name, commit = {}) ⇒ Object

Find an existing page or create it

name - The name commit - Hash

Returns self


12
13
14
15
16
17
18
19
# 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 = {}) ⇒ Object

Gets the last item from `all` method call

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

Returns a single GollumRails::Page


72
73
74
# File 'lib/gollum_rails/finders.rb', line 72

def first(options={})
  all(options).first
end

#last(options = {}) ⇒ Object

Gets the first item from `all` method call

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

Returns a single GollumRails::Page


81
82
83
# File 'lib/gollum_rails/finders.rb', line 81

def last(options={})
  all(options).last
end

#search(string) ⇒ Object

Searches the wiki for files CONTENT!

string - Searchstring

Returns an Array


52
53
54
# File 'lib/gollum_rails/finders.rb', line 52

def search(string)
  wiki.search(string)
end