Class: Trackman::Assets::Asset
Constant Summary
Components::Conventions::Asset
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
error_page, error_path, maintenance_page, maintenance_path
add_content_behavior, asset_pipeline_enabled?, create, rails_defined?, retrieve_parent
ship
diff, old_diff
Constructor Details
#initialize(attributes = {}) ⇒ Asset
Returns a new instance of Asset.
8
9
10
11
12
13
|
# File 'lib/trackman/assets/asset.rb', line 8
def initialize attributes = {}
@assets = []
self.path = attributes[:path]
self.virtual_path = attributes[:virtual_path]
end
|
Instance Attribute Details
#assets ⇒ Object
Returns the value of attribute assets.
16
17
18
|
# File 'lib/trackman/assets/asset.rb', line 16
def assets
@assets
end
|
#path ⇒ Object
Returns the value of attribute path.
16
17
18
|
# File 'lib/trackman/assets/asset.rb', line 16
def path
@path
end
|
#virtual_path ⇒ Object
Returns the value of attribute virtual_path.
15
16
17
|
# File 'lib/trackman/assets/asset.rb', line 15
def virtual_path
@virtual_path
end
|
Class Method Details
.all ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/trackman/assets/asset.rb', line 58
def self.all
return [] unless maintenance_path.exist?
assets = [maintenance_page] + maintenance_page.assets
assets = assets + [error_page] + error_page.assets if error_path.exist?
assets.uniq{|a| a.path.realpath }.sort
end
|
.autosync ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/trackman/assets/asset.rb', line 77
def self.autosync
autosync = ENV['TRACKMAN_AUTOSYNC'] || true
autosync = autosync !~ /(0|false|FALSE)/ unless autosync.is_a? TrueClass
if Object.const_defined?(:Rails)
autosync = autosync && !(Rails.env.development? || Rails.env.test?)
end
begin
return sync if autosync
rescue Exception => ex
begin
Trackman::Utility::Debugger.log_exception ex
rescue Exception => ex2
puts ex2
ensure
return false
end
end
autosync
end
|
.sync ⇒ Object
67
68
69
70
71
72
73
74
75
|
# File 'lib/trackman/assets/asset.rb', line 67
def self.sync
local = Asset.all
remote = RemoteAsset.all
diff_result = diff(local, remote)
ship diff_result
true
end
|
Instance Method Details
#<=>(another) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/trackman/assets/asset.rb', line 31
def <=>(another)
result = 0
if self.path.extname == '.html' && another.path.extname == '.html'
result = self.path.to_s <=> another.path.to_s
elsif @path.extname == '.html' || another.path.extname == '.html'
result += 1 if self.path.extname == '.html'
result -= 1 if another.path.extname == '.html'
elsif is_child_of(another)
result += -1
elsif another.is_child_of(self)
result += 1
else
result = self.path.to_s <=> another.path.to_s
end
result
end
|
#==(other) ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/trackman/assets/asset.rb', line 22
def ==(other)
return false if other.nil?
other_path = other.path.is_a?(Pathname) ? other.path : Pathname.new(other.path)
path_equal = other_path.to_s == path.to_s || path.cleanpath == other_path.cleanpath
vp_equal = virtual_path.to_s == other.virtual_path.to_s
path_equal && vp_equal
end
|
#is_child_of(parent) ⇒ Object
50
51
52
|
# File 'lib/trackman/assets/asset.rb', line 50
def is_child_of(parent)
parent.assets.include? self
end
|
#to_remote(id = nil) ⇒ Object
18
19
20
|
# File 'lib/trackman/assets/asset.rb', line 18
def to_remote(id = nil)
RemoteAsset.create(:path => @path, :virtual_path => self.virtual_path, :id => id)
end
|
#to_s ⇒ Object
54
55
56
|
# File 'lib/trackman/assets/asset.rb', line 54
def to_s
"\n<#{self.class}>:\npath='#{path}'\nfile_hash='#{file_hash}'\nvirtual_path='#{virtual_path}'"
end
|