Module: GollumRails::Persistance

Extended by:
ActiveSupport::Concern
Included in:
Page
Defined in:
lib/gollum_rails/persistance.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#create_or_updateObject

Creates a record or updates it!

Returns a Commit id string



82
83
84
85
86
87
88
# File 'lib/gollum_rails/persistance.rb', line 82

def create_or_update
  if persisted?
    update_record
  else
    create_record
  end
end

#create_recordObject

Creates a record

Returns a Commit id



93
94
95
96
# File 'lib/gollum_rails/persistance.rb', line 93

def create_record
  wiki.write_page(canonicalized_filename, format, content, commit, path_name) 
  wiki.clear_cache
end

#delete(commit = nil) ⇒ Object

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



158
159
160
# File 'lib/gollum_rails/persistance.rb', line 158

def delete(commit=nil)
  destroy(commit)
end

#destroy(commit = nil) ⇒ Object

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



147
148
149
150
# File 'lib/gollum_rails/persistance.rb', line 147

def destroy(commit=nil)
  return false if @gollum_page.nil?
  wiki.delete_page(@gollum_page, get_right_commit(commit))
end

#persisted?Boolean

checks if entry already has been saved

Returns:

  • (Boolean)


165
166
167
168
# File 'lib/gollum_rails/persistance.rb', line 165

def persisted?
  return true if gollum_page
  return false
end

#saveObject

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



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/gollum_rails/persistance.rb', line 57

def save
  return nil unless valid?
  begin
    create_or_update
   rescue ::Gollum::DuplicatePageError => e
     #false
   end
   @gollum_page = Adapters::Gollum::Page.find_page(name, wiki)
   
   self
end

#save!Object

Save without exception handling

raises errors everytime something is wrong

Raises:

  • (StandardError)


72
73
74
75
76
77
# File 'lib/gollum_rails/persistance.rb', line 72

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(*args) ⇒ Object

Updates an existing page (or created)

args - Argument chain

Returns an instance of GollumRails::Page



113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/gollum_rails/persistance.rb', line 113

def update_attributes(*args)
  run_callbacks :update do
    return update_deprecated(*args) if args.length > 1
    #content=nil,name=nil,format=:markdown, commit=nil
    args = args.first
    @gollum_page = page.update_page(gollum_page, wiki, 
      args[:content], 
      get_right_commit(args[:commit]), 
      args[:name], 
      args[:format]||:markdown)
  end
end

#update_deprecated(content = nil, name = nil, format = :markdown, commit = nil) ⇒ Object

DEPRECATED: Updates an existing page (or created)

content - optional. If given the content of the gollum_page will be updated name - optional. If given the name of gollum_page will be updated format - optional. Updates the format. Uses markdown as default commit - optional. If given this commit will be used instead of that one, used

to initialize the instance

Returns an instance of GollumRails::Page



136
137
138
139
# File 'lib/gollum_rails/persistance.rb', line 136

def update_deprecated(content=nil,name=nil,format=:markdown, commit=nil)
  @gollum_page = page.update_page(gollum_page, wiki, content, get_right_commit(commit), name, format)
  
end

#update_recordObject

Update a record

NYI

returns a Commit id



103
104
# File 'lib/gollum_rails/persistance.rb', line 103

def update_record
end