Class: MasterView::DirectiveLoadPath::Path
- Inherits:
-
Object
- Object
- MasterView::DirectiveLoadPath::Path
- Includes:
- Enumerable
- Defined in:
- lib/masterview/directive_load_path.rb
Overview
A directive load Path is a list of PathEntry specifications for directories containing MasterView directive implementations.
Instance Method Summary collapse
- #<<(entry) ⇒ Object
- #[](index) ⇒ Object
- #[]=(index, entry) ⇒ Object
-
#copy ⇒ Object
Answer a copy of a directive load path.
-
#directory_paths ⇒ Object
Answer the directory paths.
-
#each ⇒ Object
Calls the given block once for each entry specification on the path, passing the element as parameter.
-
#each_index ⇒ Object
Calls the given block once for each entry specification on the path, passing the element’s index as parameter.
- #empty? ⇒ Boolean
- #include?(dir_path) ⇒ Boolean
-
#initialize ⇒ Path
constructor
:nodoc: #??(entries=[]).
- #size ⇒ Object
Constructor Details
#initialize ⇒ Path
:nodoc: #??(entries=[])
221 222 223 224 |
# File 'lib/masterview/directive_load_path.rb', line 221 def initialize() #:nodoc: #??(entries=[]) @entries = [] #entries.each { | entry_spec | self << entry_spec } end |
Instance Method Details
#<<(entry) ⇒ Object
235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/masterview/directive_load_path.rb', line 235 def <<(entry) if entry.is_a?(String) entry = PathEntry.new(entry) elsif entry.is_a?(Array) && entry.size == 2 && entry[0].is_a?(String) && entry[1].is_a?(Hash) # wow, we're working WAY too hard at this compatability stuff entry = PathEntry.new(entry[0], entry[1]) else raise ArgumentError, "Invalid entry for {self.class.name}: #{entry.inspect}" if ! entry.is_a?(PathEntry) end @entries << entry end |
#[](index) ⇒ Object
226 227 228 |
# File 'lib/masterview/directive_load_path.rb', line 226 def [](index) @entries[index] end |
#[]=(index, entry) ⇒ Object
230 231 232 233 |
# File 'lib/masterview/directive_load_path.rb', line 230 def []=(index, entry) raise ArgumentError, "Invalid entry for {self.class.name}: #{entry.inspect}" if ! entry.is_a?(PathEntry) @entries[index] = entry end |
#copy ⇒ Object
Answer a copy of a directive load path
Does a deep_copy to ensure a clean copy of options maps
286 287 288 |
# File 'lib/masterview/directive_load_path.rb', line 286 def copy() @entries.collect{ | dpe | dpe.deep_copy } end |
#directory_paths ⇒ Object
Answer the directory paths
276 277 278 279 280 |
# File 'lib/masterview/directive_load_path.rb', line 276 def directory_paths dir_paths = [] self.each { |dpe| dir_paths << dpe.dir_path } dir_paths end |
#each ⇒ Object
Calls the given block once for each entry specification on the path, passing the element as parameter.
257 258 259 260 |
# File 'lib/masterview/directive_load_path.rb', line 257 def each @entries.each { |dpe| yield(dpe) } self end |
#each_index ⇒ Object
Calls the given block once for each entry specification on the path, passing the element’s index as parameter.
264 265 266 267 |
# File 'lib/masterview/directive_load_path.rb', line 264 def each_index @entries.each_index { |index| yield(index) } self end |
#empty? ⇒ Boolean
251 252 253 |
# File 'lib/masterview/directive_load_path.rb', line 251 def empty? @entries.empty? end |
#include?(dir_path) ⇒ Boolean
269 270 271 272 273 |
# File 'lib/masterview/directive_load_path.rb', line 269 def include?(dir_path) dir_path = dir_path.is_a?( PathEntry ) ? dir_path.dir_path : File.(dir_path) dpe = self.detect{ |dpe| dpe.dir_path == dir_path } ! dpe.nil? end |
#size ⇒ Object
247 248 249 |
# File 'lib/masterview/directive_load_path.rb', line 247 def size @entries.size end |