module GollumRails::Persistance

Public Instance Methods

create_or_update() click to toggle source

Creates a record or updates it!

Returns a Commit id string

# File lib/gollum_rails/persistance.rb, line 83
def create_or_update
  if persisted?
    update_record
  else
    create_record
  end
end
create_record() click to toggle source

Creates a record

Returns a Commit id

# File lib/gollum_rails/persistance.rb, line 94
def create_record
  wiki.write_page(canonicalized_filename, format, content, commit, path_name)
  wiki.clear_cache
rescue NoMethodError => e
  raise AttributeMissingError, "Attributes are missing. Error message: <%s>" % e.message
end
delete(commit=nil) click to toggle source

Deletes current page

commit - optional. If given this commit will be used instead of that one, used

to initialize the instance

Returns the commit id of the current action as String

# File lib/gollum_rails/persistance.rb, line 150
def delete(commit=nil)
  destroy(commit)
end
destroy(commit=nil) click to toggle source

Deletes current page

commit - optional. If given this commit will be used instead of that one, used

to initialize the instance

Returns the commit id of the current action as String

# File lib/gollum_rails/persistance.rb, line 139
def destroy(commit=nil)
  return false if @gollum_page.nil?
  wiki.delete_page(@gollum_page, get_right_commit(commit))
end
persisted?() click to toggle source

checks if entry already has been saved

# File lib/gollum_rails/persistance.rb, line 157
def persisted?
  return true if gollum_page
  return false
end
save() click to toggle source

Handles the connection betweet plain activemodel and Gollum Saves current page in GIT wiki If another page with the same name is existing, gollum_rails will detect it and returns that page instead.

Examples:

obj = GollumRails::Page.new <params>
@article = obj.save
# => Gollum::Page

@article.name
whatever name you have entered OR the name of the previous
created page

TODO:

* overriding for creation(duplicates)
* do not alias save! on save

Returns an instance of Gollum::Page or false

# File lib/gollum_rails/persistance.rb, line 58
def save
  return nil unless valid?
  begin
    create_or_update
  rescue ::Gollum::DuplicatePageError
  end
  self.gollum_page = wiki.paged(file_name, path_name, true, wiki.ref)
  _update_page_attributes
  self
end
save!() click to toggle source

Save without exception handling

raises errors everytime something is wrong

Returns an instance of GollumRails::Page

# File lib/gollum_rails/persistance.rb, line 73
def save!
  raise StandardError, "record is not valid" unless valid?
  raise StandardError, "commit must not be empty" if commit == {}
  create_or_update
  self
end
update_attributes(attributes) click to toggle source

Updates an existing page (or created)

attributes - Hash of arguments

Returns an instance of GollumRails::Page

# File lib/gollum_rails/persistance.rb, line 119
def update_attributes(attributes)
  assign_attributes(attributes)
  save
end
update_record() click to toggle source

Update a record

Updates a record based on current instance variables

returns a Commit id

# File lib/gollum_rails/persistance.rb, line 106
def update_record
  wiki.update_page(self.gollum_page,
                   self.name,
                   self.format,
                   self.content,
                   self.commit)
end