Class: Teapot::Configuration
- Inherits:
-
Definition
- Object
- Definition
- Teapot::Configuration
- Defined in:
- lib/teapot/configuration.rb
Defined Under Namespace
Classes: Import
Instance Attribute Summary collapse
-
#imports ⇒ Object
readonly
A list of other configurations to include when materialising the list of packages.
-
#options ⇒ Object
readonly
Options used to bind packages to this configuration.
-
#packages ⇒ Object
readonly
A list of packages which are required by this configuration.
-
#visibility ⇒ Object
readonly
Controls how the configuration is exposed in the context.
Attributes inherited from Definition
#context, #description, #name, #package
Instance Method Summary collapse
-
#[](key) ⇒ Object
Get a configuration option.
-
#[]=(key, value) ⇒ Object
Set a configuration option.
- #append(configuration, options) ⇒ Object
-
#group ⇒ Object
Create a group for configuration options which will be only be active within the group block.
-
#import(name) ⇒ Object
Specifies that this package will import additional configuration records from another definition.
-
#import!(name, options = nil) ⇒ Object
Require and import the named package.
-
#initialize(context, package, name, packages = Set.new, options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
-
#load_all ⇒ Object
Load all packages defined by this configuration.
- #lock_path ⇒ Object
- #lock_store ⇒ Object
-
#materialize ⇒ Object
Process all import directives and return a new configuration based on the current configuration.
-
#packages_path ⇒ Object
The path where packages will be located when fetched.
-
#platforms_path ⇒ Object
The path where built products will be installed.
- #public! ⇒ Object
- #public? ⇒ Boolean
-
#require(name, options = nil) ⇒ Object
Specifies that this configuration depends on an external package of some sort.
- #to_s ⇒ Object
-
#top! ⇒ Object
Conceptually, a configuration belongs to a package.
Methods inherited from Definition
Constructor Details
#initialize(context, package, name, packages = Set.new, options = {}) ⇒ Configuration
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/teapot/configuration.rb', line 36 def initialize(context, package, name, packages = Set.new, = {}) super context, package, name = @packages = packages @imports = [] @visibility = :private end |
Instance Attribute Details
#imports ⇒ Object (readonly)
A list of other configurations to include when materialising the list of packages.
65 66 67 |
# File 'lib/teapot/configuration.rb', line 65 def imports @imports end |
#options ⇒ Object (readonly)
Options used to bind packages to this configuration.
59 60 61 |
# File 'lib/teapot/configuration.rb', line 59 def end |
#packages ⇒ Object (readonly)
A list of packages which are required by this configuration.
62 63 64 |
# File 'lib/teapot/configuration.rb', line 62 def packages @packages end |
#visibility ⇒ Object (readonly)
Controls how the configuration is exposed in the context.
48 49 50 |
# File 'lib/teapot/configuration.rb', line 48 def visibility @visibility end |
Instance Method Details
#[](key) ⇒ Object
Get a configuration option.
100 101 102 |
# File 'lib/teapot/configuration.rb', line 100 def [] key [key] end |
#[]=(key, value) ⇒ Object
Set a configuration option.
95 96 97 |
# File 'lib/teapot/configuration.rb', line 95 def []= key, value [key] = value end |
#append(configuration, options) ⇒ Object
162 163 164 165 166 167 168 169 170 |
# File 'lib/teapot/configuration.rb', line 162 def append(configuration, ) @packages += configuration.packages.collect do |package| package.dup.tap{|package| package. = .merge(package.)} end @imports += configuration.imports.collect do |import| import.dup.tap{|import| import. = .merge(import.)} end end |
#group ⇒ Object
Create a group for configuration options which will be only be active within the group block.
86 87 88 89 90 91 92 |
# File 'lib/teapot/configuration.rb', line 86 def group = .dup yield = end |
#import(name) ⇒ Object
Specifies that this package will import additional configuration records from another definition.
75 76 77 |
# File 'lib/teapot/configuration.rb', line 75 def import(name) @imports << Import.new(name, .dup) end |
#import!(name, options = nil) ⇒ Object
Require and import the named package.
80 81 82 83 |
# File 'lib/teapot/configuration.rb', line 80 def import!(name, = nil) require(name, ) import(name) end |
#load_all ⇒ Object
Load all packages defined by this configuration.
123 124 125 126 127 |
# File 'lib/teapot/configuration.rb', line 123 def load_all @packages.each do |package| @context.load(package) end end |
#lock_path ⇒ Object
114 115 116 |
# File 'lib/teapot/configuration.rb', line 114 def lock_path context.root + "#{@name}-lock.yml" end |
#lock_store ⇒ Object
118 119 120 |
# File 'lib/teapot/configuration.rb', line 118 def lock_store @lock_store ||= YAML::Store.new(lock_path.to_s) end |
#materialize ⇒ Object
Process all import directives and return a new configuration based on the current configuration. Import directives bring packages and other import directives from the specififed configuration definition.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/teapot/configuration.rb', line 135 def materialize # Potentially no materialization is required: return self if @imports.count == 0 # Before trying to materialize, we should load all possible packages: @packages.each do |package| @context.load(package) rescue nil end # Create a new configuration which will represent the materialised version: configuration = self.class.new(@context, @package, @name, @packages.dup, .dup) # Enumerate all imports and attempt to resolve the packages: @imports.each do |import| named_configuration = @context.configurations[import.name] if named_configuration && named_configuration != self configuration.append(named_configuration.materialize, import.) else # It couldn't be resolved... configuration.imports << import end end return configuration end |
#packages_path ⇒ Object
The path where packages will be located when fetched.
105 106 107 |
# File 'lib/teapot/configuration.rb', line 105 def packages_path context.root + "teapot/packages/#{name}" end |
#platforms_path ⇒ Object
The path where built products will be installed.
110 111 112 |
# File 'lib/teapot/configuration.rb', line 110 def platforms_path context.root + "teapot/platforms/#{name}" end |
#public! ⇒ Object
54 55 56 |
# File 'lib/teapot/configuration.rb', line 54 def public! @visibility = :public end |
#public? ⇒ Boolean
50 51 52 |
# File 'lib/teapot/configuration.rb', line 50 def public? @visibility == :public end |
#require(name, options = nil) ⇒ Object
Specifies that this configuration depends on an external package of some sort.
68 69 70 71 72 |
# File 'lib/teapot/configuration.rb', line 68 def require(name, = nil) = ? .merge() : .dup @packages << Package.new(packages_path + name.to_s, name, ) end |
#to_s ⇒ Object
172 173 174 |
# File 'lib/teapot/configuration.rb', line 172 def to_s "<#{self.class.name} #{@name.dump} visibility=#{@visibility}>" end |
#top! ⇒ Object
Conceptually, a configuration belongs to a package. Primarily, a configuration lists dependent packages, but this also includes itself as the dependencies are purely target based, e.g. this configuration has access to any targets exposed by its own package.
130 131 132 |
# File 'lib/teapot/configuration.rb', line 130 def top! @packages << @package end |