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.



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

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



127
128
129
130
# File 'lib/hx.rb', line 127

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

#each_entry_path(selector, &block) ⇒ Object



122
123
124
125
# File 'lib/hx.rb', line 122

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

#edit_entry(path, prototype = nil) ⇒ Object



113
114
115
116
117
118
119
120
# File 'lib/hx.rb', line 113

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:



132
133
134
135
# File 'lib/hx.rb', line 132

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