Class: Blueprints::FileContext
- Inherits:
-
Object
- Object
- Blueprints::FileContext
- Defined in:
- lib/blueprints/file_context.rb
Overview
Module that blueprints file is executed against. Defined blueprint
and namespace
methods.
Constant Summary collapse
- @@current =
nil
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
-
#blueprint(name, &block) ⇒ Object
Creates a new blueprint by name and block passed.
-
#d(*args) ⇒ Object
Wrapper around Blueprints::Dependency.new.
-
#initialize(file) ⇒ FileContext
constructor
A new instance of FileContext.
-
#namespace(name) ⇒ Object
Creates new namespace by name, and evaluates block against it.
Constructor Details
#initialize(file) ⇒ FileContext
Returns a new instance of FileContext.
8 9 10 11 12 13 14 |
# File 'lib/blueprints/file_context.rb', line 8 def initialize(file) file = Pathname.new(file) @file = file.relative_path_from(Blueprints.config.root) FileContext.current = self instance_eval(File.read(file)) FileContext.current = nil end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
6 7 8 |
# File 'lib/blueprints/file_context.rb', line 6 def file @file end |
Instance Method Details
#blueprint(name, &block) ⇒ Object
Creates a new blueprint by name and block passed
17 18 19 |
# File 'lib/blueprints/file_context.rb', line 17 def blueprint(name, &block) Blueprint.new(name, @file, &block) end |
#d(*args) ⇒ Object
Wrapper around Blueprints::Dependency.new. See Blueprints::Dependency for more information.
33 34 35 |
# File 'lib/blueprints/file_context.rb', line 33 def d(*args) Dependency.new(*args) end |
#namespace(name) ⇒ Object
Creates new namespace by name, and evaluates block against it.
22 23 24 25 26 27 28 29 30 |
# File 'lib/blueprints/file_context.rb', line 22 def namespace(name) old_namespace = Namespace.root namespace = Namespace.new(name) Namespace.root = namespace yield old_namespace.add_child(namespace) Namespace.root = old_namespace namespace end |