class Frizz::Local
Attributes
ignorance[R]
options[R]
root_path[R]
Public Class Methods
new(root_path, ignorance, options = {})
click to toggle source
# File lib/frizz/local.rb, line 3 def initialize(root_path, ignorance, options = {}) @root_path = root_path @ignorance = ignorance @options = options end
Public Instance Methods
file_for(local_path)
click to toggle source
# File lib/frizz/local.rb, line 19 def file_for(local_path) if is_redirect?(local_path) Tempfile.new(local_path.gsub(/\.|\//, '-')) else ::File.read expand_path(local_path) end end
files()
click to toggle source
# File lib/frizz/local.rb, line 9 def files @files ||= begin Dir.chdir(root_path) do Dir["**/*"].map do |local_path| File.new(expand_path(local_path), local_path) unless ignore?(local_path) end.compact end end.concat(redirect_files) end
Private Instance Methods
expand_path(local_path)
click to toggle source
# File lib/frizz/local.rb, line 31 def expand_path(local_path) ::File.join root_path, local_path end
ignore?(path)
click to toggle source
# File lib/frizz/local.rb, line 35 def ignore?(path) ::File.directory?(path) || ignorance.ignore?(path) end
is_redirect?(path)
click to toggle source
# File lib/frizz/local.rb, line 39 def is_redirect?(path) redirect_files.any? { |r| r.key == path } end
redirect_files()
click to toggle source
# File lib/frizz/local.rb, line 43 def redirect_files @redirect_files ||= if options[:redirect_rules] options[:redirect_rules].map do |redirect_rule| File.new( expand_path(redirect_rule['from']), redirect_rule['from'], redirect_to: redirect_rule['to'] ) end else [] end end