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.
104
105
106
|
# File 'lib/repub/app/fetcher.rb', line 104
def name
@name
end
|
Returns the value of attribute path.
105
106
107
|
# File 'lib/repub/app/fetcher.rb', line 105
def path
@path
end
|
Returns the value of attribute url.
103
104
105
|
# File 'lib/repub/app/fetcher.rb', line 103
def url
@url
end
|
Class Method Details
97
98
99
100
101
|
# File 'lib/repub/app/fetcher.rb', line 97
def self.cleanup
Dir.chdir(self.root) { FileUtils.rm_r(Dir.glob('*')) }
rescue
end
|
.for_url(url, &block) ⇒ Object
107
108
109
|
# File 'lib/repub/app/fetcher.rb', line 107
def self.for_url(url, &block)
self.new(url).for_url(&block)
end
|
93
94
95
|
# File 'lib/repub/app/fetcher.rb', line 93
def self.root
return File.join(App.data_path, 'cache')
end
|
Instance Method Details
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/repub/app/fetcher.rb', line 129
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
150
151
152
|
# File 'lib/repub/app/fetcher.rb', line 150
def cached?
@cached == true
end
|
#empty? ⇒ Boolean
146
147
148
|
# File 'lib/repub/app/fetcher.rb', line 146
def empty?
Dir.glob(File.join(@path, '*')).empty?
end
|
#for_url(&block) ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/repub/app/fetcher.rb', line 111
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
|