Class: Repub::App::Fetcher::Cache
Constant Summary
Constants included
from Logger
Logger::LOGGER_NORMAL, Logger::LOGGER_QUIET, Logger::LOGGER_VERBOSE
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Logger
#log
Instance Attribute Details
Returns the value of attribute name.
115
116
117
|
# File 'lib/repub/app/fetcher.rb', line 115
def name
@name
end
|
Returns the value of attribute path.
116
117
118
|
# File 'lib/repub/app/fetcher.rb', line 116
def path
@path
end
|
Returns the value of attribute url.
114
115
116
|
# File 'lib/repub/app/fetcher.rb', line 114
def url
@url
end
|
Class Method Details
108
109
110
111
112
|
# File 'lib/repub/app/fetcher.rb', line 108
def self.cleanup
Dir.chdir(self.root) { FileUtils.rm_r(Dir.glob('*')) }
rescue
end
|
.for_url(url, &block) ⇒ Object
118
119
120
|
# File 'lib/repub/app/fetcher.rb', line 118
def self.for_url(url, &block)
self.new(url).for_url(&block)
end
|
104
105
106
|
# File 'lib/repub/app/fetcher.rb', line 104
def self.root
return File.join(App.data_path, 'cache')
end
|
Instance Method Details
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/repub/app/fetcher.rb', line 140
def assets
unless @assets
Dir.chdir(@path) do
@assets = {}
AssetTypes.each_pair do |asset_type, file_types|
@assets[asset_type] ||= []
file_types.each do |file_type|
@assets[asset_type] << Dir.glob("*.#{file_type}")
end
@assets[asset_type].flatten!
end
end
end
@assets
end
|
#cached? ⇒ Boolean
161
162
163
|
# File 'lib/repub/app/fetcher.rb', line 161
def cached?
@cached == true
end
|
#empty? ⇒ Boolean
157
158
159
|
# File 'lib/repub/app/fetcher.rb', line 157
def empty?
Dir.glob(File.join(@path, '*')).empty?
end
|
#for_url(&block) ⇒ Object
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/repub/app/fetcher.rb', line 122
def for_url(&block)
@cached = File.exist?(@path)
unless @cached
FileUtils.mkdir_p(@path)
begin
Dir.chdir(@path) { yield self }
rescue
FileUtils.rm_r(@path)
raise
end
else
log.info "Using cached assets"
log.debug "-- Cache is #{@path}"
end
self
end
|