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

Methods included from View

#each_entry

Constructor Details

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

Returns a new instance of Cache.



280
281
282
283
# File 'lib/hx.rb', line 280

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

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



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

def input
  @input
end

Instance Method Details

#each_entry_path(selector) ⇒ Object



295
296
297
298
299
300
301
302
303
304
# File 'lib/hx.rb', line 295

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



289
290
291
292
293
# File 'lib/hx.rb', line 289

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



285
286
287
# File 'lib/hx.rb', line 285

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

#get_entry(path) ⇒ Object



306
307
308
# File 'lib/hx.rb', line 306

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