Class: Hx::PathSubset

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

Instance Method Summary collapse

Constructor Details

#initialize(input, options) ⇒ PathSubset

Returns a new instance of PathSubset.



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/hx.rb', line 89

def initialize(input, options)
  @input = input
  only = patterns_to_selector(Array(options[:only] || []))
  except = patterns_to_selector(Array(options[:except] || []))
  except = ~except if except
  if only and except
    @selector = only & except
  else
    @selector = only || except || Path::ALL
  end
end

Instance Method Details

#each_entry(selector, &block) ⇒ Object



115
116
117
118
# File 'lib/hx.rb', line 115

def each_entry(selector, &block)
  @input.each_entry(@selector & selector, &block)
  self
end

#each_entry_path(selector, &block) ⇒ Object



110
111
112
113
# File 'lib/hx.rb', line 110

def each_entry_path(selector, &block)
  @input.each_entry_path(@selector & selector, &block)
  self
end

#edit_entry(path, prototype = nil) ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/hx.rb', line 101

def edit_entry(path, prototype=nil)
  if @selector.accept_path? path
    @input.edit_entry(path, prototype) { |text| yield text }
  else
    raise EditingNotSupportedError, "Editing not supported for #{path}"
  end
  self
end

#get_entry(path) ⇒ Object

Raises:



120
121
122
123
# File 'lib/hx.rb', line 120

def get_entry(path)
  raise NoSuchEntryError, path unless @selector.accept_path? path
  @input.get_entry(path)
end