Class: Wiki::Attachment
- Inherits:
-
Object
- Object
- Wiki::Attachment
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::AttributeMethods, ActiveModel::Conversion, ActiveModel::Dirty
- Defined in:
- app/models/wiki/attachment.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#format ⇒ Object
Returns the value of attribute format.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#wiki ⇒ Object
Returns the value of attribute wiki.
Instance Method Summary collapse
- #destroy!(user) ⇒ Object
- #filesystem_path ⇒ Object
- #gollum_file ⇒ Object
- #gollum_file=(file) ⇒ Object
-
#id ⇒ Object
Returns the value of attribute path.
-
#initialize(params = {}) ⇒ Attachment
constructor
A new instance of Attachment.
- #mime_type ⇒ Object
- #parent_path ⇒ Object
- #persisted? ⇒ Boolean
- #to_param ⇒ Object
- #to_s ⇒ Object
- #update(hash) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Attachment
Returns a new instance of Attachment.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/wiki/attachment.rb', line 41 def initialize(params={}) wiki = params[:wiki] gollum_file = params[:gollum_file] path = params[:path] if wiki @wiki = wiki end if gollum_file self.gollum_file = gollum_file elsif path safepath = path.downcase @path = safepath new_file = @wiki.find_gollum_file(safepath) if new_file self.gollum_file = new_file end end end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
13 14 15 |
# File 'app/models/wiki/attachment.rb', line 13 def content @content end |
#format ⇒ Object
Returns the value of attribute format.
13 14 15 |
# File 'app/models/wiki/attachment.rb', line 13 def format @format end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'app/models/wiki/attachment.rb', line 13 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
13 14 15 |
# File 'app/models/wiki/attachment.rb', line 13 def path @path end |
#wiki ⇒ Object
Returns the value of attribute wiki.
13 14 15 |
# File 'app/models/wiki/attachment.rb', line 13 def wiki @wiki end |
Instance Method Details
#destroy!(user) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/models/wiki/attachment.rb', line 90 def destroy!(user) = {name: user.name, email: user.email, message: "removed #{@path}"} Rails.logger.debug("removing #{@path}") committer = Gollum::Committer.new(@wiki.gollum_wiki, ) committer.delete(@path) committer.after_commit do |index, _sha| dir = File.dirname(@path) dir = '' if dir == '.' @wiki.gollum_wiki.clear_cache committer.update_working_dir(dir, parent_path, @format) end @wiki.pull_repo committer.commit @wiki.push_repo end |
#filesystem_path ⇒ Object
73 74 75 |
# File 'app/models/wiki/attachment.rb', line 73 def filesystem_path return File.join(@wiki.base_path, @path) end |
#gollum_file ⇒ Object
69 70 71 |
# File 'app/models/wiki/attachment.rb', line 69 def gollum_file @gollum_file end |
#gollum_file=(file) ⇒ Object
61 62 63 64 65 66 67 |
# File 'app/models/wiki/attachment.rb', line 61 def gollum_file=(file) @gollum_file = file @name = file.name @format = File.extname(file.name).split('.').last.to_sym # filename = ::Attachment.basename(fullname, ext) @path = file.url_path + file.name end |
#id ⇒ Object
Returns the value of attribute path.
14 15 16 |
# File 'app/models/wiki/attachment.rb', line 14 def path @path end |
#mime_type ⇒ Object
77 78 79 |
# File 'app/models/wiki/attachment.rb', line 77 def mime_type @gollum_file.mime_type end |
#parent_path ⇒ Object
85 86 87 88 |
# File 'app/models/wiki/attachment.rb', line 85 def parent_path parent_path = File.dirname(@path) (parent_path == '.') ? '' : parent_path + '/' end |
#persisted? ⇒ Boolean
110 111 112 113 |
# File 'app/models/wiki/attachment.rb', line 110 def persisted? # TODO: make this a real dirty flag true end |
#to_param ⇒ Object
81 82 83 |
# File 'app/models/wiki/attachment.rb', line 81 def to_param @path end |
#to_s ⇒ Object
26 27 28 |
# File 'app/models/wiki/attachment.rb', line 26 def to_s self.path end |
#update(hash) ⇒ Object
34 35 36 37 38 39 |
# File 'app/models/wiki/attachment.rb', line 34 def update(hash) self.name = hash[:name] self.content = hash[:content] return true end |