Class: LocalPac::TranslationTable
- Inherits:
-
Object
- Object
- LocalPac::TranslationTable
- Defined in:
- lib/local_pac/translation_table.rb
Instance Method Summary collapse
-
#initialize(file = LocalPac.config.translation_file, rule_engine = TranslationRule, cache = ActiveSupport::Cache::MemoryStore.new) ⇒ TranslationTable
constructor
A new instance of TranslationTable.
- #rewrite(client_ip, requested_file) ⇒ Object
Constructor Details
#initialize(file = LocalPac.config.translation_file, rule_engine = TranslationRule, cache = ActiveSupport::Cache::MemoryStore.new) ⇒ TranslationTable
10 11 12 13 14 |
# File 'lib/local_pac/translation_table.rb', line 10 def initialize(file = LocalPac.config.translation_file, rule_engine = TranslationRule, cache = ActiveSupport::Cache::MemoryStore.new) @rule_engine = rule_engine @rules = read_table(file) @cache = cache end |
Instance Method Details
#rewrite(client_ip, requested_file) ⇒ Object
16 17 18 19 20 |
# File 'lib/local_pac/translation_table.rb', line 16 def rewrite(client_ip, requested_file) #cache.fetch("#{client_ip}_#{requested_file}") do rules.find( proc { OpenStruct.new(rewritten_file: requested_file) } ) { |r| r.match?(client_ip, requested_file) }.rewritten_file #end end |