Class: S3Rails::Resolver
- Inherits:
-
ActionView::PathResolver
- Object
- ActionView::PathResolver
- S3Rails::Resolver
- Includes:
- Singleton
- Defined in:
- lib/s3_rails/resolver.rb
Instance Attribute Summary collapse
-
#s3 ⇒ Object
Returns the value of attribute s3.
Instance Method Summary collapse
- #build_query(path, details) ⇒ Object
-
#initialize ⇒ Resolver
constructor
A new instance of Resolver.
- #query(path, details, formats) ⇒ Object
Constructor Details
Instance Attribute Details
#s3 ⇒ Object
Returns the value of attribute s3.
4 5 6 |
# File 'lib/s3_rails/resolver.rb', line 4 def s3 @s3 end |
Instance Method Details
#build_query(path, details) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/s3_rails/resolver.rb', line 11 def build_query(path, details) exts = EXTENSIONS.map do |ext, prefix| "{" + details[ext].compact.uniq.map { |e| "#{prefix}#{e}," }.join + "}" end.join path.to_s + exts end |
#query(path, details, formats) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/s3_rails/resolver.rb', line 21 def query(path, details, formats) query = build_query(path, details) if File.exists?('tmp/reload_s3.txt') && @s3.last_load < File.mtime('tmp/reload_s3.txt') @s3.load_cache clear_cache end # objects = @s3.bucket.objects.with_prefix(path.prefix).select do |obj| # File.fnmatch query, obj.key, File::FNM_EXTGLOB # end objects = @s3.objects.select do |key, obj| File.fnmatch query, key, File::FNM_EXTGLOB end objects.map do |key, obj| template = "s3/#{@s3.bucket_name}/#{obj.key}" handler, format, variant = extract_handler_and_format_and_variant(template, formats) contents = obj.read ActionView::Template.new(contents, template, handler, :virtual_path => path.virtual, :format => format, :variant => variant, :updated_at => obj.last_modified ) end end |