class Pico::Context
Attributes
mod[RW]
Public Class Methods
new(name, parent: nil, root:)
click to toggle source
# File lib/pico/context.rb, line 7 def initialize(name, parent: nil, root:) @mod = build_mod @name = name @root = Pathname(root) if root @parent = parent end
owner(const)
click to toggle source
# File lib/pico/context.rb, line 15 def owner(const) owner, _ = Autoloader.owner_and_ascending_nibbles const owner end
Public Instance Methods
boot!()
click to toggle source
# File lib/pico/context.rb, line 25 def boot! parent.const_set name, mod end
booted?()
click to toggle source
# File lib/pico/context.rb, line 29 def booted? parent.const_defined? name end
build_mod()
click to toggle source
# File lib/pico/context.rb, line 21 def build_mod Module.new end
eager_load!()
click to toggle source
# File lib/pico/context.rb, line 33 def eager_load! Dir[root.join('**/*.rb')].each do |rb_file| load_file rb_file end end
load_file(rb_file)
click to toggle source
# File lib/pico/context.rb, line 39 def load_file(rb_file) mod.module_eval File.read(rb_file), rb_file.to_s end
parent()
click to toggle source
# File lib/pico/context.rb, line 43 def parent return Object unless @parent Pico.contexts.fetch(@parent.to_sym).mod end
possible_implicit_namespace?(path)
click to toggle source
# File lib/pico/context.rb, line 54 def possible_implicit_namespace?(path) root.join(path).directory? end
reload!()
click to toggle source
# File lib/pico/context.rb, line 48 def reload! shutdown! @mod = build_mod boot! end
resolve_const(expanded_const)
click to toggle source
# File lib/pico/context.rb, line 58 def resolve_const(expanded_const) build_const_resolver(expanded_const).resolve end
shutdown!()
click to toggle source
# File lib/pico/context.rb, line 62 def shutdown! parent.send(:remove_const, name) end
Private Instance Methods
build_const_resolver(expanded_const)
click to toggle source
# File lib/pico/context.rb, line 68 def build_const_resolver(expanded_const) ConstResolver.new( context: self, expanded_const: String(expanded_const).dup.freeze, ) end