Class: Cocina::Config
- Inherits:
-
Object
- Object
- Cocina::Config
- Defined in:
- lib/cocina/config.rb
Instance Attribute Summary collapse
-
#cocinafile ⇒ Object
readonly
Returns the value of attribute cocinafile.
-
#instances ⇒ Object
readonly
Returns the value of attribute instances.
Instance Method Summary collapse
- #[](target) ⇒ Object
- #build_dependencies ⇒ Object
-
#initialize(file) ⇒ Config
constructor
A new instance of Config.
- #instance(id, &block) ⇒ Object
- #instance?(id) ⇒ Boolean
- #kitchen_instance(target) ⇒ Object
- #load_cocinafile ⇒ Object
Constructor Details
#initialize(file) ⇒ Config
Returns a new instance of Config.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cocina/config.rb', line 8 def initialize(file) @cocinafile = file @instances = [] $stdout.sync = true @loader = Kitchen::Loader::YAML.new( project_config: ENV["KITCHEN_YAML"], local_config: ENV["KITCHEN_LOCAL_YAML"], global_config: ENV["KITCHEN_GLOBAL_YAML"] ) @config = Kitchen::Config.new( loader: @loader ) @config.log_level = Kitchen.env_log unless Kitchen.env_log.nil? @config.log_overwrite = Kitchen.env_log_overwrite unless Kitchen.env_log_overwrite.nil? load_cocinafile build_dependencies end |
Instance Attribute Details
#cocinafile ⇒ Object (readonly)
Returns the value of attribute cocinafile.
6 7 8 |
# File 'lib/cocina/config.rb', line 6 def cocinafile @cocinafile end |
#instances ⇒ Object (readonly)
Returns the value of attribute instances.
6 7 8 |
# File 'lib/cocina/config.rb', line 6 def instances @instances end |
Instance Method Details
#[](target) ⇒ Object
64 65 66 |
# File 'lib/cocina/config.rb', line 64 def [](target) @instances.find {|i| i.name == target } end |
#build_dependencies ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/cocina/config.rb', line 49 def build_dependencies instances.each do |machine| machine.dependencies.each do |id| next if instance?(id) dep = Cocina::Instance.new(id) dep.runner = kitchen_instance(id) @instances << dep end end end |
#instance(id, &block) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/cocina/config.rb', line 40 def instance(id, &block) return true if instance?(id) cocina_instance = Cocina::Instance.new(id) cocina_instance.instance_eval(&block) cocina_instance.runner = kitchen_instance(id) @instances << cocina_instance nil end |
#instance?(id) ⇒ Boolean
60 61 62 |
# File 'lib/cocina/config.rb', line 60 def instance?(id) instances.map(&:name).include?(id) end |
#kitchen_instance(target) ⇒ Object
36 37 38 |
# File 'lib/cocina/config.rb', line 36 def kitchen_instance(target) @config.instances.get(target) end |
#load_cocinafile ⇒ Object
32 33 34 |
# File 'lib/cocina/config.rb', line 32 def load_cocinafile self.instance_eval(IO.read(cocinafile), cocinafile, 1) end |