Class: Workspace::WorkspaceFile
- Inherits:
-
Object
- Object
- Workspace::WorkspaceFile
show all
- Includes:
- Archive, Media, Net, Parse
- Defined in:
- lib/maglove/workspace.rb,
lib/workspace/workspace_file.rb,
lib/workspace/workspace_file/net.rb,
lib/workspace/workspace_file/media.rb,
lib/workspace/workspace_file/parse.rb,
lib/workspace/workspace_file/archive.rb
Defined Under Namespace
Modules: Archive, Media, Net, Parse
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Parse
#read_haml, #read_json, #read_yaml
Methods included from Net
#download
Methods included from Media
#audio?, #image?, #video?
Methods included from Archive
#extract
Constructor Details
#initialize(workspace, path) ⇒ WorkspaceFile
Returns a new instance of WorkspaceFile.
15
16
17
18
|
# File 'lib/workspace/workspace_file.rb', line 15
def initialize(workspace, path)
@workspace = workspace
@path = path
end
|
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
13
14
15
|
# File 'lib/workspace/workspace_file.rb', line 13
def path
@path
end
|
#workspace ⇒ Object
Returns the value of attribute workspace.
13
14
15
|
# File 'lib/workspace/workspace_file.rb', line 13
def workspace
@workspace
end
|
Instance Method Details
#absolute_path ⇒ Object
100
101
102
|
# File 'lib/workspace/workspace_file.rb', line 100
def absolute_path
File.absolute_path(to_s)
end
|
#asset(theme: workspace_theme, base: false, asset_uri: ".") ⇒ Object
28
29
30
|
# File 'lib/maglove/workspace.rb', line 28
def asset(theme: workspace_theme, base: false, asset_uri: ".")
MagLove::Asset::Theme.new(path, { theme: theme, base: base, asset_uri: asset_uri })
end
|
#basename ⇒ Object
83
84
85
|
# File 'lib/workspace/workspace_file.rb', line 83
def basename
File.basename(path, ".*")
end
|
#contents ⇒ Object
25
26
27
|
# File 'lib/workspace/workspace_file.rb', line 25
def contents
@contents ||= read
end
|
#copy(target_file) ⇒ Object
41
42
43
44
|
# File 'lib/workspace/workspace_file.rb', line 41
def copy(target_file)
target_file.dir.create unless target_file.dir.exists?
FileUtils.cp(to_s, target_file.to_s)
end
|
#delete! ⇒ Object
79
80
81
|
# File 'lib/workspace/workspace_file.rb', line 79
def delete!
FileUtils.rm_f(to_s)
end
|
#dir ⇒ Object
67
68
69
|
# File 'lib/workspace/workspace_file.rb', line 67
def dir
Workspace::WorkspaceDir.new(@workspace, File.dirname(@path))
end
|
#exists? ⇒ Boolean
59
60
61
|
# File 'lib/workspace/workspace_file.rb', line 59
def exists?
File.exist?(to_s) and !File.directory?(to_s)
end
|
#extension ⇒ Object
91
92
93
|
# File 'lib/workspace/workspace_file.rb', line 91
def extension
File.extname(to_s).gsub(/^\./, "")
end
|
#md5 ⇒ Object
71
72
73
|
# File 'lib/workspace/workspace_file.rb', line 71
def md5
Digest::MD5.hexdigest(read)
end
|
#move(target_file) ⇒ Object
46
47
48
49
|
# File 'lib/workspace/workspace_file.rb', line 46
def move(target_file)
target_file.dir.create unless target_file.dir.exists?
FileUtils.mv(to_s, target_file.to_s)
end
|
#read ⇒ Object
63
64
65
|
# File 'lib/workspace/workspace_file.rb', line 63
def read
File.open(to_s).read
end
|
#read_hamloft(options = {}) ⇒ Object
37
38
39
|
# File 'lib/maglove/workspace.rb', line 37
def read_hamloft(options = {})
Hamloft.render(read, options)
end
|
#relative_path ⇒ Object
55
56
57
|
# File 'lib/workspace/workspace_file.rb', line 55
def relative_path
@path.sub(%r{^/}, "")
end
|
#rename!(filename) ⇒ Object
95
96
97
98
|
# File 'lib/workspace/workspace_file.rb', line 95
def rename!(filename)
FileUtils.mv(to_s, dir.file(filename).to_s) if exists?
@path = dir.file(filename).path
end
|
#replace(key, value) ⇒ Object
29
30
31
32
|
# File 'lib/workspace/workspace_file.rb', line 29
def replace(key, value)
contents.gsub!(key, value)
self
end
|
#set(data) ⇒ Object
20
21
22
23
|
# File 'lib/workspace/workspace_file.rb', line 20
def set(data)
@contents = data
self
end
|
#size ⇒ Object
104
105
106
|
# File 'lib/workspace/workspace_file.rb', line 104
def size
File.size(to_s)
end
|
#slug ⇒ Object
87
88
89
|
# File 'lib/workspace/workspace_file.rb', line 87
def slug
relative_path.chomp(File.extname(self.relative_path))
end
|
#to_s ⇒ Object
51
52
53
|
# File 'lib/workspace/workspace_file.rb', line 51
def to_s
File.join(@workspace, @path)
end
|
#url ⇒ Object
75
76
77
|
# File 'lib/workspace/workspace_file.rb', line 75
def url
"file://#{absolute_path}"
end
|
#workspace_theme ⇒ Object
32
33
34
35
|
# File 'lib/maglove/workspace.rb', line 32
def workspace_theme
match = self.workspace.match(%r{/themes/([^/]+)})
match ? match[1] : nil
end
|
#write(data = nil) ⇒ Object
34
35
36
37
38
39
|
# File 'lib/workspace/workspace_file.rb', line 34
def write(data = nil)
data ||= @contents
dir.create unless dir.exists?
File.open(to_s, "wb") { |file| file << data }
self
end
|