Class: Hx::PathSubset
Instance Method Summary collapse
- #each_entry(selector, &block) ⇒ Object
- #each_entry_path(selector, &block) ⇒ Object
- #edit_entry(path, prototype = nil) ⇒ Object
- #get_entry(path) ⇒ Object
-
#initialize(input, options) ⇒ PathSubset
constructor
A new instance of PathSubset.
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, ) @input = input only = patterns_to_selector(Array([:only] || [])) except = patterns_to_selector(Array([: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
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 |