Class: Hx::Cache

Inherits:
Object
  • Object
show all
Includes:
Filter
Defined in:
lib/hx.rb

Defined Under Namespace

Classes: Record

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Filter

#each_entry

Constructor Details

#initialize(input, options = {}) ⇒ Cache

Returns a new instance of Cache.



268
269
270
271
# File 'lib/hx.rb', line 268

def initialize(input, options={})
  input = input.input while Cache === input
  @input = input
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



266
267
268
# File 'lib/hx.rb', line 266

def input
  @input
end

Instance Method Details

#each_entry_path(selector) ⇒ Object



283
284
285
286
287
288
289
290
291
292
# File 'lib/hx.rb', line 283

def each_entry_path(selector)
  get_cache_record.get_entry_paths do
    paths = []
    @input.each_entry_path(Path::ALL) { |path| paths << path }
    paths
  end.each do |path|
    yield path if selector.accept_path? path
  end
  self
end

#edit_entry(path, prototype = nil) ⇒ Object



277
278
279
280
281
# File 'lib/hx.rb', line 277

def edit_entry(path, prototype=nil)
  @input.edit_entry(path, prototype) { |text| yield text }
  get_cache_record.clear_path(path)
  self
end

#get_cache_recordObject



273
274
275
# File 'lib/hx.rb', line 273

def get_cache_record
  (Thread.current[:hx_cache_records] ||= {})[@input] ||= Record.new
end

#get_entry(path) ⇒ Object



294
295
296
# File 'lib/hx.rb', line 294

def get_entry(path)
  get_cache_record.get_entry(path) { @input.get_entry(path) }
end