Class: Truck::Context
- Inherits:
-
Object
- Object
- Truck::Context
- Defined in:
- lib/truck/context.rb,
lib/truck/const_resolver.rb
Defined Under Namespace
Classes: ConstResolver
Instance Attribute Summary collapse
-
#autoload_paths ⇒ Object
readonly
Returns the value of attribute autoload_paths.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
- #boot! ⇒ Object
- #booted? ⇒ Boolean
- #context_for?(other_mod) ⇒ Boolean
- #eager_load! ⇒ Object
-
#initialize(name, root, parent, autoload_paths) ⇒ Context
constructor
A new instance of Context.
- #load_file(rb_file) ⇒ Object
- #mod ⇒ Object
- #parent ⇒ Object
- #resolve_const(expanded_const, skip = nil) ⇒ Object
- #shutdown! ⇒ Object
Constructor Details
Instance Attribute Details
#autoload_paths ⇒ Object (readonly)
Returns the value of attribute autoload_paths.
3 4 5 |
# File 'lib/truck/context.rb', line 3 def autoload_paths @autoload_paths end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/truck/context.rb', line 3 def name @name end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
3 4 5 |
# File 'lib/truck/context.rb', line 3 def root @root end |
Class Method Details
.owner(const) ⇒ Object
13 14 15 16 |
# File 'lib/truck/context.rb', line 13 def owner(const) owner, _ = Autoloader.owner_and_ascending_nibbles const owner end |
Instance Method Details
#boot! ⇒ Object
19 20 21 |
# File 'lib/truck/context.rb', line 19 def boot! parent.const_set name, build_mod end |
#booted? ⇒ Boolean
32 33 34 |
# File 'lib/truck/context.rb', line 32 def booted? mod ? true : false end |
#context_for?(other_mod) ⇒ Boolean
28 29 30 |
# File 'lib/truck/context.rb', line 28 def context_for?(other_mod) mod == other_mod or other_mod.included_modules.include? mod end |
#eager_load! ⇒ Object
36 37 38 39 40 |
# File 'lib/truck/context.rb', line 36 def eager_load! Dir[root.join('**/*.rb')].each do |rb_file| load_file rb_file end end |
#load_file(rb_file) ⇒ Object
42 43 44 45 |
# File 'lib/truck/context.rb', line 42 def load_file(rb_file) ruby_code = File.read rb_file mod.module_eval ruby_code, rb_file.to_s end |
#mod ⇒ Object
23 24 25 26 |
# File 'lib/truck/context.rb', line 23 def mod return nil unless parent and parent.const_defined? name parent.const_get name end |
#parent ⇒ Object
47 48 49 50 |
# File 'lib/truck/context.rb', line 47 def parent return Object unless @parent Truck.contexts.fetch(@parent.to_sym).mod end |
#resolve_const(expanded_const, skip = nil) ⇒ Object
52 53 54 |
# File 'lib/truck/context.rb', line 52 def resolve_const(, skip = nil) build_const_resolver(, Array[skip]).resolve end |
#shutdown! ⇒ Object
56 57 58 |
# File 'lib/truck/context.rb', line 56 def shutdown! parent.send :remove_const, name end |