Class: Teapot::Configuration

Inherits:
Definition show all
Defined in:
lib/teapot/configuration.rb

Defined Under Namespace

Classes: Import

Instance Attribute Summary collapse

Attributes inherited from Definition

#context, #description, #name, #package

Instance Method Summary collapse

Methods inherited from Definition

#path

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, options = {})
  super context, package, name

  @options = options

  @packages = packages
  @imports = []

  @visibility = :private
end

Instance Attribute Details

#importsObject (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

#optionsObject (readonly)

Options used to bind packages to this configuration.



59
60
61
# File 'lib/teapot/configuration.rb', line 59

def options
  @options
end

#packagesObject (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

#visibilityObject (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
  @options[key]
end

#[]=(key, value) ⇒ Object

Set a configuration option.



95
96
97
# File 'lib/teapot/configuration.rb', line 95

def []= key, value
  @options[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, options)
  @packages += configuration.packages.collect do |package|
    package.dup.tap{|package| package.options = options.merge(package.options)}
  end
  
  @imports += configuration.imports.collect do |import|
    import.dup.tap{|import| import.options = options.merge(import.options)}
  end
end

#groupObject

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
  options = @options.dup
  
  yield
  
  @options = options
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, @options.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, options = nil)
  require(name, options)
  import(name)
end

#load_allObject

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_pathObject



114
115
116
# File 'lib/teapot/configuration.rb', line 114

def lock_path
  context.root + "#{@name}-lock.yml"
end

#lock_storeObject



118
119
120
# File 'lib/teapot/configuration.rb', line 118

def lock_store
  @lock_store ||= YAML::Store.new(lock_path.to_s)
end

#materializeObject

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, @options.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.options)
    else
      # It couldn't be resolved...
      configuration.imports << import
    end
  end
  
  return configuration
end

#packages_pathObject

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_pathObject

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, options = nil)
  options = options ? @options.merge(options) : @options.dup
  
  @packages << Package.new(packages_path + name.to_s, name, options)
end

#to_sObject



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