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

#collapse, file_from_backtrace, #file_from_backtrace, #from_here, from_here, repath, string_to_segments, unpath, up_to, #up_to

Constructor Details

#initializeDefinedDefaults

Returns a new instance of DefinedDefaults.



90
91
92
# File 'lib/valise/search-root.rb', line 90

def initialize
  @files = {}
end

Class Method Details

.define(&block) ⇒ Object



124
125
126
# File 'lib/valise/search-root.rb', line 124

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

Instance Method Details

#add_dir(path) ⇒ Object



139
140
141
# File 'lib/valise/search-root.rb', line 139

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

#add_file(path, data = nil) ⇒ Object



143
144
145
# File 'lib/valise/search-root.rb', line 143

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

#add_item(path, contents) ⇒ Object



128
129
130
131
132
133
134
135
136
137
# File 'lib/valise/search-root.rb', line 128

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[path] = contents
end

#define(&block) ⇒ Object



116
117
118
119
120
121
122
# File 'lib/valise/search-root.rb', line 116

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

#eachObject



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

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

#full_path(segments) ⇒ Object



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

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

#get_from(item) ⇒ Object



112
113
114
# File 'lib/valise/search-root.rb', line 112

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

#present?(segments) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#segmentsObject



94
95
96
# File 'lib/valise/search-root.rb', line 94

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