Class: Builderator::Config::File
- Inherits:
-
Attributes
- Object
- Attributes
- Builderator::Config::File
- Defined in:
- lib/builderator/config/file.rb
Overview
DSL Loader for a configuration file
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Provide an authoritative, UTC-based date for any consumers.
-
#policies ⇒ Object
readonly
Returns the value of attribute policies.
-
#source ⇒ Object
readonly
Where the instance was defined.
-
#type ⇒ Object
readonly
How compile should populate attributes.
Attributes inherited from Attributes
#attributes, #extends, #nodes, #parent
Class Method Summary collapse
-
.from_file(source, **options) ⇒ Object
DSL Loaders.
- .from_json(source, **options) ⇒ Object
- .lookup_cache ⇒ Object
Instance Method Summary collapse
-
#autoversion ⇒ Object
Enable/disable auto-versioning features.
-
#aws ⇒ Object
AWS configurations.
-
#cleaner ⇒ Object
Cleaner Parameters.
-
#cleanup ⇒ Object
Option to disable cleanup of build resources.
- #compile ⇒ Object
-
#cookbook ⇒ Object
Cookbook build options.
-
#generator ⇒ Object
Generator Options.
-
#initialize(attributes = {}, options = {}, &block) ⇒ File
constructor
A new instance of File.
-
#local ⇒ Object
Local resource paths.
-
#lookup(source, query) ⇒ Object
Use the Data controller to fetch IDs from the EC2 API at compile time.
-
#relative(*path) ⇒ Object
Helper to resolve absolute paths relative to this ‘File`.
-
#vendor ⇒ Object
Configure resources that must be fetched for a build.
-
#vendored(name, *path) ⇒ Object
Helper to resolve paths to vendored files.
Methods inherited from Attributes
#==, attribute, #clean, collection, #dirty, #dirty!, #merge, namespace, #reset!, #root, #root?, #seal, #to_json, #unseal
Constructor Details
#initialize(attributes = {}, options = {}, &block) ⇒ File
Returns a new instance of File.
35 36 37 38 39 40 41 42 43 |
# File 'lib/builderator/config/file.rb', line 35 def initialize(attributes = {}, = {}, &block) @policies = {} @date = Time.now.utc @type = .fetch(:type, :code) @source = .fetch(:source, nil) super(attributes, , &block) end |
Instance Attribute Details
#date ⇒ Object (readonly)
Provide an authoritative, UTC-based date for any consumers
30 31 32 |
# File 'lib/builderator/config/file.rb', line 30 def date @date end |
#policies ⇒ Object (readonly)
Returns the value of attribute policies.
33 34 35 |
# File 'lib/builderator/config/file.rb', line 33 def policies @policies end |
#source ⇒ Object (readonly)
Where the instance was defined
31 32 33 |
# File 'lib/builderator/config/file.rb', line 31 def source @source end |
#type ⇒ Object (readonly)
How compile should populate attributes
32 33 34 |
# File 'lib/builderator/config/file.rb', line 32 def type @type end |
Class Method Details
.from_file(source, **options) ⇒ Object
DSL Loaders
17 18 19 |
# File 'lib/builderator/config/file.rb', line 17 def from_file(source, **) new({}, .merge(:type => :file, :source => source)) end |
.from_json(source, **options) ⇒ Object
21 22 23 |
# File 'lib/builderator/config/file.rb', line 21 def from_json(source, **) new({}, .merge(:type => :json, :source => source)) end |
.lookup_cache ⇒ Object
25 26 27 |
# File 'lib/builderator/config/file.rb', line 25 def lookup_cache @lookup_cache ||= {} end |
Instance Method Details
#autoversion ⇒ Object
Enable/disable auto-versioning features
115 116 117 118 |
# File 'lib/builderator/config/file.rb', line 115 namespace :autoversion do attribute :create_tags attribute :search_tags end |
#aws ⇒ Object
AWS configurations
166 167 168 169 170 |
# File 'lib/builderator/config/file.rb', line 166 namespace :aws do attribute :region attribute :access_key attribute :secret_key end |
#cleaner ⇒ Object
Cleaner Parameters
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'lib/builderator/config/file.rb', line 349 namespace :cleaner do attribute :commit attribute :force attribute :filters, Hash attribute :group_by, :type => :list attribute :sort_by attribute :keep namespace :limits do attribute :images attribute :launch_configs attribute :snapshots attribute :volumes end end |
#cleanup ⇒ Object
Option to disable cleanup of build resources
398 |
# File 'lib/builderator/config/file.rb', line 398 attribute :cleanup |
#compile ⇒ Object
45 46 47 48 49 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/builderator/config/file.rb', line 45 def compile clean ## Clear dirty flag before re-parsing file or block case @type when :file instance_eval(IO.read(source), source, 0) super(false) when :json update = Rash.coerce(JSON.parse(IO.read(source))) unless @attributes == update dirty(true) @attributes = update end else instance_eval(&@block) if @block super(false) end ## Overlay policies policy.each do |name, policy| if policy.has?(:path) next unless ::File.exist?(policy.path) policies[name] ||= self.class.from_file(policy.path) elsif policy.has?(:json) next unless ::File.exist?(policy.json) policies[name] ||= self.class.from_json(policy.json) end policies[name].compile dirty(policies[name].dirty) end self end |
#cookbook ⇒ Object
Cookbook build options
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/builderator/config/file.rb', line 142 namespace :cookbook do attribute :path attribute :berkshelf_config attribute :sources, :type => :list, :singular => :add_source attribute :metadata collection :depends do attribute :version attribute :git attribute :github attribute :branch attribute :tag attribute :ref attribute :rel attribute :path, :relative => true end end |
#generator ⇒ Object
Generator Options
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/builderator/config/file.rb', line 368 namespace :generator do collection :project do namespace :builderator do attribute :version end namespace :ruby do attribute :version end namespace :vagrant do attribute :install attribute :version collection :plugin do attribute :version end end collection :resource do attribute :path, :type => :list attribute :action attribute :template end end end |
#local ⇒ Object
Local resource paths
123 124 125 126 127 |
# File 'lib/builderator/config/file.rb', line 123 namespace :local do attribute :cookbook_path attribute :data_bag_path attribute :environment_path end |
#lookup(source, query) ⇒ Object
Use the Data controller to fetch IDs from the EC2 API at compile time
85 86 87 |
# File 'lib/builderator/config/file.rb', line 85 def lookup(source, query) self.class.lookup_cache[cache_key(query)] ||= Control::Data.lookup(source, query) end |
#relative(*path) ⇒ Object
Helper to resolve absolute paths relative to this ‘File`. Only works for `File`s with valid filesystem source attributes!
96 97 98 |
# File 'lib/builderator/config/file.rb', line 96 def relative(*path) Pathname.new(source).join(*(['..', path].flatten)). end |
#vendor ⇒ Object
Configure resources that must be fetched for a build
334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/builderator/config/file.rb', line 334 collection :vendor do attribute :path, :relative => true attribute :git attribute :github attribute :remote attribute :branch attribute :tag attribute :ref attribute :rel end |
#vendored(name, *path) ⇒ Object
Helper to resolve paths to vendored files
90 91 92 |
# File 'lib/builderator/config/file.rb', line 90 def vendored(name, *path) Util.vendor(name, *path) end |