Class: Valise::DefinedDefaults

Inherits:
ReadOnlySearchRoot show all
Defined in:
lib/valise/search-root.rb

Defined Under Namespace

Classes: DefinitionHelper

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ReadOnlySearchRoot

#writable?, #write

Methods inherited from SearchRoot

#inspect, #to_s, #writable?, #write

Methods included from Unpath

#clean_pathname, #containing_workspace, #current_directory, #file_from_backtrace, #from_here, #make_pathname, #starting_directory, #up_to, #up_until

Constructor Details

#initializeDefinedDefaults

Returns a new instance of DefinedDefaults.



80
81
82
# File 'lib/valise/search-root.rb', line 80

def initialize
  @files = {}
end

Class Method Details

.define(&block) ⇒ Object



114
115
116
# File 'lib/valise/search-root.rb', line 114

def self.define(&block)
  return self.new.define(&block)
end

Instance Method Details

#add_dir(path) ⇒ Object



129
130
131
# File 'lib/valise/search-root.rb', line 129

def add_dir(path)
  #add_item(path, ValiseWorks::Directory.new(path))
end

#add_file(path, data = nil) ⇒ Object



133
134
135
# File 'lib/valise/search-root.rb', line 133

def add_file(path, data = nil)
  add_item(path, data)
end

#add_item(path, contents) ⇒ Object



118
119
120
121
122
123
124
125
126
127
# File 'lib/valise/search-root.rb', line 118

def add_item(path, contents)
  check_path = path[0..-2]
  until check_path.empty?
    if @files.has_key?(check_path)
      raise Errors::MalformedTree, "Tried to add items below #{path[0..-2]} which is not a directory"
    end
    check_path.pop
  end
  @files[make_pathname(path)] = contents
end

#define(&block) ⇒ Object



106
107
108
109
110
111
112
# File 'lib/valise/search-root.rb', line 106

def define(&block)
  unless block.nil?
    definer = DefinitionHelper.new(self)
    definer.instance_eval &block
  end
  return self
end

#eachObject



96
97
98
99
100
# File 'lib/valise/search-root.rb', line 96

def each
  @files.each_key do |path|
    yield(make_pathname(path))
  end
end

#full_path(segments) ⇒ Object



88
89
90
# File 'lib/valise/search-root.rb', line 88

def full_path(segments)
  "<DEFAULTS>:" + segments.to_s
end

#get_from(item) ⇒ Object



102
103
104
# File 'lib/valise/search-root.rb', line 102

def get_from(item)
  return @files[item.segments]
end

#present?(segments) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/valise/search-root.rb', line 92

def present?(segments)
  @files.has_key?(segments)
end

#segmentsObject



84
85
86
# File 'lib/valise/search-root.rb', line 84

def segments
  raise Errors::VirtualSearchPath, "does not have a real path"
end