Class: ActionView::S3Resolver
- Inherits:
-
PathResolver
- Object
- PathResolver
- ActionView::S3Resolver
- Defined in:
- lib/erp_tech_svcs/file_support/railties/s3_resolver.rb
Instance Method Summary collapse
-
#cached(key, path_info, details, locals) ⇒ Object
:nodoc:.
- #eql?(resolver) ⇒ Boolean (also: #==)
- #get_dir_entries(path, file_support) ⇒ Object
-
#initialize(path, pattern = nil) ⇒ S3Resolver
constructor
A new instance of S3Resolver.
- #mtime(p, file_support) ⇒ Object
- #query(path, details, formats) ⇒ Object
- #to_s ⇒ Object (also: #to_path)
Constructor Details
#initialize(path, pattern = nil) ⇒ S3Resolver
Returns a new instance of S3Resolver.
3 4 5 6 7 |
# File 'lib/erp_tech_svcs/file_support/railties/s3_resolver.rb', line 3 def initialize(path, pattern=nil) raise ArgumentError, "path already is a Resolver class" if path.is_a?(Resolver) super(pattern) @path = path end |
Instance Method Details
#cached(key, path_info, details, locals) ⇒ Object
:nodoc:
19 20 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/erp_tech_svcs/file_support/railties/s3_resolver.rb', line 19 def cached(key, path_info, details, locals) #:nodoc: file_support = ErpTechSvcs::FileSupport::Base.new(:storage => :s3) name, prefix, partial = path_info locals = sort_locals(locals) if key && caching? if @cached[key][name][prefix][partial][locals].nil? or @cached[key][name][prefix][partial][locals].empty? @cached[key][name][prefix][partial][locals] = decorate(yield, path_info, details, locals) else @cached[key][name][prefix][partial][locals].each do |template| @cached[key][name][prefix][partial][locals].delete_if{|item| item.identifier == template.identifier} #check if the file still exists if file_support.exists? template.identifier @cached[key][name][prefix][partial][locals] << build_template(template.identifier, template.virtual_path, (details[:formats] || [:html] if template.formats.empty?), file_support, template.locals) end end @cached[key][name][prefix][partial][locals] end else fresh = decorate(yield, path_info, details, locals) return fresh unless key scope = @cached[key][name][prefix][partial] cache = scope[locals] mtime = cache && cache.map(&:updated_at).max if !mtime || fresh.empty? || fresh.any? { |t| t.updated_at > mtime } scope[locals] = fresh else cache end end end |
#eql?(resolver) ⇒ Boolean Also known as: ==
14 15 16 |
# File 'lib/erp_tech_svcs/file_support/railties/s3_resolver.rb', line 14 def eql?(resolver) self.class.equal?(resolver.class) && to_path == resolver.to_path end |
#get_dir_entries(path, file_support) ⇒ Object
60 61 62 63 64 |
# File 'lib/erp_tech_svcs/file_support/railties/s3_resolver.rb', line 60 def get_dir_entries(path, file_support) full_path = File.join(@path, path) node = file_support.find_node(File.dirname(full_path)) node.nil? ? [] : node[:children].select{|child| child[:leaf]}.collect{|child| child[:id]}.select{|p|!p.scan(full_path).empty?} end |
#mtime(p, file_support) ⇒ Object
66 67 68 69 |
# File 'lib/erp_tech_svcs/file_support/railties/s3_resolver.rb', line 66 def mtime(p, file_support) node = file_support.find_node(p) node[:last_modified] end |
#query(path, details, formats) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/erp_tech_svcs/file_support/railties/s3_resolver.rb', line 53 def query(path, details, formats) file_support = ErpTechSvcs::FileSupport::Base.new(:storage => :s3) templates = [] get_dir_entries(path, file_support).each{|p|templates << build_template(p, path.virtual, formats, file_support)} templates end |
#to_s ⇒ Object Also known as: to_path
9 10 11 |
# File 'lib/erp_tech_svcs/file_support/railties/s3_resolver.rb', line 9 def to_s @path.to_s end |