Class: Teapot::Context
- Inherits:
-
Object
- Object
- Teapot::Context
- Defined in:
- lib/teapot/context.rb
Overview
A context represents a specific root package instance with a given configuration and all related definitions. A context is stateful in the sense that package selection is specialized based on #select and #dependency_chain. These parameters are usually set up initially as part of the context setup.
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
The primary configuration.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#project ⇒ Object
readonly
The primary project.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#initialize(root, **options) ⇒ Context
constructor
Initialize a new context.
-
#load(package) ⇒ Object
Load a package from its teapot.rb, tracking loaded packages to prevent duplicates.
-
#repository ⇒ Object
Discover and open the git repository for this context’s root directory.
-
#root_package ⇒ Object
The root package is a special package which is used to load definitions from a given root path.
-
#select(names = nil, configuration = @configuration) ⇒ Object
Create a selection that resolves dependencies and loads definitions for the specified targets or configurations.
-
#substitutions ⇒ Object
Get substitutions for template generation.
Constructor Details
Instance Attribute Details
#configuration ⇒ Object (readonly)
The primary configuration.
29 30 31 |
# File 'lib/teapot/context.rb', line 29 def configuration @configuration end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
26 27 28 |
# File 'lib/teapot/context.rb', line 26 def @options end |
#project ⇒ Object (readonly)
The primary project.
32 33 34 |
# File 'lib/teapot/context.rb', line 32 def project @project end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
25 26 27 |
# File 'lib/teapot/context.rb', line 25 def root @root end |
Instance Method Details
#load(package) ⇒ Object
Load a package from its teapot.rb, tracking loaded packages to prevent duplicates.
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/teapot/context.rb', line 87 def load(package) if loader = @loaded[package] return loader.script unless loader.changed? end loader = Loader.new(self, package) @loaded[package] = loader return loader.script end |
#repository ⇒ Object
Discover and open the git repository for this context’s root directory.
36 37 38 |
# File 'lib/teapot/context.rb', line 36 def repository @repository ||= Rugged::Repository.discover(@root.to_s) end |
#root_package ⇒ Object
The root package is a special package which is used to load definitions from a given root path.
100 101 102 |
# File 'lib/teapot/context.rb', line 100 def root_package @root_package ||= Package.new(@root, "root") end |
#select(names = nil, configuration = @configuration) ⇒ Object
Create a selection that resolves dependencies and loads definitions for the specified targets or configurations.
44 45 46 |
# File 'lib/teapot/context.rb', line 44 def select(names = nil, configuration = @configuration) Select.new(self, configuration, names || []) end |
#substitutions ⇒ Object
Get substitutions for template generation.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/teapot/context.rb', line 50 def substitutions substitutions = Build::Text::Substitutions.new substitutions["TEAPOT_VERSION"] = Teapot::VERSION if @project name = @project.name # e.g. Foo Bar, typically used as a title, directory, etc. substitutions["PROJECT_NAME"] = name.text # e.g. FooBar, typically used as a namespace substitutions["PROJECT_IDENTIFIER"] = name.identifier # e.g. foo-bar, typically used for targets, executables substitutions["PROJECT_TARGET_NAME"] = name.target # e.g. foo_bar, typically used for variables. substitutions["PROJECT_VARIABLE_NAME"] = name.key substitutions["LICENSE"] = @project.license end # The user's current name: substitutions["AUTHOR_NAME"] = repository.config["user.name"] substitutions["AUTHOR_EMAIL"] = repository.config["user.email"] current_date = Time.new substitutions["DATE"] = current_date.strftime("%-d/%-m/%Y") substitutions["YEAR"] = current_date.strftime("%Y") return substitutions end |