Module: GollumRails::Persistance
Defined Under Namespace
Modules: ClassMethods Classes: AttributeMissingError
Instance Method Summary collapse
-
#create_or_update ⇒ Object
Creates a record or updates it!.
-
#create_record ⇒ Object
Creates a record.
-
#delete(commit = nil) ⇒ Object
Deletes current page.
-
#destroy(commit = nil) ⇒ Object
Deletes current page.
-
#persisted? ⇒ Boolean
checks if entry already has been saved.
-
#save ⇒ Object
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.
-
#save! ⇒ Object
Save without exception handling raises errors everytime something is wrong.
-
#seperate_path(path) ⇒ Object
:nodoc:.
-
#update_attributes(attributes) ⇒ Object
Updates an existing page (or created).
-
#update_record ⇒ Object
Update a record.
Instance Method Details
#create_or_update ⇒ Object
Creates a record or updates it!
Returns a Commit id string
83 84 85 86 87 88 89 |
# File 'lib/gollum_rails/persistance.rb', line 83 def create_or_update if persisted? update_record else create_record end end |
#create_record ⇒ Object
Creates a record
Returns a Commit id
94 95 96 97 98 99 |
# 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. 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
150 151 152 |
# File 'lib/gollum_rails/persistance.rb', line 150 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
139 140 141 142 |
# 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? ⇒ Boolean
checks if entry already has been saved
157 158 159 160 |
# File 'lib/gollum_rails/persistance.rb', line 157 def persisted? return true if gollum_page return false end |
#save ⇒ Object
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
58 59 60 61 62 63 64 65 66 67 |
# 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! ⇒ Object
Save without exception handling
raises errors everytime something is wrong
Returns an instance of GollumRails::Page
73 74 75 76 77 78 |
# 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 |
#seperate_path(path) ⇒ Object
:nodoc:
124 125 126 127 128 129 130 131 |
# File 'lib/gollum_rails/persistance.rb', line 124 def seperate_path(path) #:nodoc: path = File.split(name) if path.first == '/' || path.first == '.' folder = nil else folder = path.first end end |
#update_attributes(attributes) ⇒ Object
Updates an existing page (or created)
attributes - Hash of arguments
Returns an instance of GollumRails::Page
119 120 121 122 |
# File 'lib/gollum_rails/persistance.rb', line 119 def update_attributes(attributes) assign_attributes(attributes) save end |
#update_record ⇒ Object
Update a record
Updates a record based on current instance variables
returns a Commit id
106 107 108 109 110 111 112 |
# 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 |