Class Tap::Env
In: lib/tap/env.rb
lib/tap/env/cache.rb
lib/tap/env/constant.rb
lib/tap/env/path.rb
lib/tap/env/string_ext.rb
Parent: Object

Methods

activate   auto   constant   generate   loadpath   match   new   path   register   resolve   set   unloadpath   unregister   unset  

Included Modules

Signals

Classes and Modules

Module Tap::Env::StringExt
Class Tap::Env::Cache
Class Tap::Env::Constant
Class Tap::Env::Path

Constants

INLINE_TYPE = /(.*)::([a-z_]*)\z/   Matches an inline type. After the match:
  $1:: The prefix string (ex 'Const' for '::Const::type')
  $2:: The inline type (ex 'type' for '::Const::type')

Attributes

constants  [R] 
paths  [R] 

Public Class methods

[Source]

    # File lib/tap/env.rb, line 9
 9:       def generate(options={})
10:         options = {
11:           :register => true, 
12:           :load_paths => true,
13:           :set => true
14:         }.merge(options)
15:         
16:         dir = File.expand_path(options[:dir] || Dir.pwd)
17:         pathfile = options[:pathfile] || File.expand_path(Path::FILE, dir)
18:         map = options[:map] || Path.load(pathfile)
19:         lib = options[:lib] || 'lib'
20:         pattern = options[:pattern] || '**/*.rb'
21:         
22:         register = options[:register]
23:         load_paths = options[:load_paths] 
24:         set = options[:set]
25:         
26:         lines = []
27:         lines << "register #{Path.escape(dir)}" if register
28:         
29:         path = Path.new(dir, map)
30:         path[lib].each do |lib_dir|
31:           lines << "loadpath #{Path.escape(lib_dir)}" if load_paths
32:           
33:           Constant.scan(lib_dir, pattern).each do |constant|
34:             require_paths = Path.join(constant.require_paths)
35:             types = constant.types.to_a.collect {|type| Path.escape(Path.join(type)) }
36:             lines << "set #{constant.const_name} #{Path.escape require_paths} #{types.join(' ')}"
37:           end if set
38:         end
39:         
40:         lines.uniq!
41:         lines.sort!
42:         lines
43:       end

[Source]

    # File lib/tap/env.rb, line 74
74:     def initialize(options={})
75:       @paths = options[:paths] || []
76:       @paths.collect! {|path| path.kind_of?(Path) ? path : Path.new(*path) }
77:       @constants = options[:constants] || []
78:       @constants.collect! {|constant| constant.kind_of?(Constant) ? constant : Constant.new(constant) }
79:     end

Public Instance methods

[Source]

     # File lib/tap/env.rb, line 124
124:     def activate(name, version)
125:       Gem.activate(name, version)
126:     end

[Source]

     # File lib/tap/env.rb, line 116
116:     def auto(options, log=nil)
117:       Env.generate(options).each do |line|
118:         sig, *args = Utils.shellsplit(line)
119:         signal(sig).call(args)
120:       end
121:       self
122:     end

[Source]

     # File lib/tap/env.rb, line 103
103:     def constant(const_str, type=nil)
104:       const_str.kind_of?(Module) ? const_str : resolve(const_str, type).constantize
105:     end

Expands and prepends the specified paths to $LOAD_PATH, removing any duplicates. Returns $LOAD_PATH.

[Source]

     # File lib/tap/env.rb, line 136
136:     def loadpath(*paths)
137:       paths.reverse_each do |path|
138:         $LOAD_PATH.unshift File.expand_path(path)
139:       end
140:       
141:       $LOAD_PATH.uniq!
142:       $LOAD_PATH
143:     end

[Source]

    # File lib/tap/env.rb, line 89
89:     def match(const_str, type=nil)
90:       const_str = const_str.to_s
91:       const_str =~ Constant::CONST_REGEXP ? constants_by_const_name($1) : constants_by_path(const_str, type)
92:     end

[Source]

    # File lib/tap/env.rb, line 81
81:     def path(type)
82:       result = []
83:       paths.each do |path|
84:         result.concat path[type]
85:       end
86:       result
87:     end

Registers the directory and path mappings as a Path, into paths. The path is unshifted to paths to provide similar functionality as loadpath. Returns the new path.

[Source]

     # File lib/tap/env.rb, line 110
110:     def register(dir, map={})
111:       new_path = Path.new(dir, map)
112:       paths.unshift new_path
113:       new_path
114:     end

[Source]

     # File lib/tap/env.rb, line 94
 94:     def resolve(const_str, type=nil)
 95:       matches = match(const_str, type)
 96:       case matches.length
 97:       when 0 then raise "unresolvable constant: #{const_str.inspect}"
 98:       when 1 then matches.at(0)
 99:       else raise "multiple matching constants: #{const_str.inspect} (#{matches.join(', ')})"
100:       end
101:     end

[Source]

     # File lib/tap/env.rb, line 152
152:     def set(const_name, require_path=nil, *types)
153:       if const_name =~ INLINE_TYPE
154:         const_name = $1
155:         types << $2
156:       end
157:       
158:       constant = constants.find {|c| c.const_name == const_name }
159:       
160:       unless constant
161:         constant = Constant.new(const_name)
162:         constants << constant
163:       end
164:       
165:       require_paths = require_path ? Path.split(require_path, nil) : []
166:       if require_paths.empty? && const_name.kind_of?(String)
167:         require_paths << const_name.underscore
168:       end
169:       
170:       constant.require_paths.concat(require_paths).uniq!
171:       types.each {|type| constant.register_as(*Path.split(type, nil)) }
172:       
173:       constant
174:     end

Expands and removes the specified paths from $LOAD_PATH. Returns $LOAD_PATH.

[Source]

     # File lib/tap/env.rb, line 147
147:     def unloadpath(*paths)
148:       paths.each {|path| $LOAD_PATH.delete File.expand_path(path) }
149:       $LOAD_PATH
150:     end

[Source]

     # File lib/tap/env.rb, line 128
128:     def unregister(*dirs)
129:       dirs.collect! {|dir| File.expand_path(dir) }
130:       paths.delete_if {|path| dirs.include?(path.base) }
131:       self
132:     end

[Source]

     # File lib/tap/env.rb, line 176
176:     def unset(*const_names)
177:       const_names.each do |const_name|
178:         constants.delete_if do |constant|
179:           constant.const_name == const_name
180:         end
181:       end
182:       self
183:     end

[Validate]