Class: Cfer::Auster::Repo
- Inherits:
-
Object
- Object
- Cfer::Auster::Repo
- Includes:
- Logging::Mixin
- Defined in:
- lib/cfer/auster/repo.rb
Constant Summary collapse
- REPO_FILE =
".auster.yaml"
- STEP_REGEX =
/(?<count>[0-9]{2})\.(?<tag>[a-z0-9][a-z0-9\-]*[a-z0-9])/
- INT_REGEX =
/[0-9]+/
Instance Attribute Summary collapse
-
#config_sets ⇒ Object
readonly
Returns the value of attribute config_sets.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#param_validator ⇒ Object
readonly
Returns the value of attribute param_validator.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
Class Method Summary collapse
Instance Method Summary collapse
- #config_set(id) ⇒ Object
-
#initialize(root) ⇒ Repo
constructor
A new instance of Repo.
- #nuke(config_set) ⇒ Object
- #ordered_steps ⇒ Object
- #run_task(task_name, config_set, args = []) ⇒ Object
- #step_by_count(count) ⇒ Object
- #step_by_count_or_tag(value) ⇒ Object
- #step_by_tag(tag) ⇒ Object
- #tasks ⇒ Object
Methods included from Logging::Mixin
Constructor Details
#initialize(root) ⇒ Repo
Returns a new instance of Repo.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cfer/auster/repo.rb', line 19 def initialize(root) raise "root must be a String." unless root.is_a?(String) @root = File.(root).freeze logger.debug "Repo location: #{@root}" = File.(REPO_FILE, @root) logger.debug "Loading options file..." raise "#{} does not exist." unless File.file?() @options = YAML.load_file() @cfg_root = File.join(@root, "config").freeze raise "#{@cfg_root} does not exist." unless File.directory?(@cfg_root) @step_root = File.join(@root, "steps").freeze raise "#{@step_root} does not exist." unless File.directory?(@step_root) logger.debug "Enumerating steps..." steps = build_steps = steps.map(&:tag) step_counts = steps.map(&:count) raise "Multiple steps with the same tag found. Can't continue." \ if .uniq.length != steps.length raise "Multiple steps with the same count found. Can't continue." \ if step_counts.uniq.length != steps.length @steps = steps.map { |step| [step.count, step] }.to_h.freeze @steps_by_tag = steps.map { |step| [step.tag, step.count] }.to_h.freeze logger.debug "Enumerating config sets..." @config_sets = find_config_sets logger.debug "Loading param validator..." @param_validator = load_param_validator end |
Instance Attribute Details
#config_sets ⇒ Object (readonly)
Returns the value of attribute config_sets.
15 16 17 |
# File 'lib/cfer/auster/repo.rb', line 15 def config_sets @config_sets end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/cfer/auster/repo.rb', line 12 def @options end |
#param_validator ⇒ Object (readonly)
Returns the value of attribute param_validator.
17 18 19 |
# File 'lib/cfer/auster/repo.rb', line 17 def param_validator @param_validator end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
11 12 13 |
# File 'lib/cfer/auster/repo.rb', line 11 def root @root end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
14 15 16 |
# File 'lib/cfer/auster/repo.rb', line 14 def steps @steps end |
Class Method Details
.discover_from_cwd ⇒ Object
168 169 170 171 172 173 174 175 176 |
# File 'lib/cfer/auster/repo.rb', line 168 def discover_from_cwd require "search_up" repo_file = SearchUp.search(Dir.pwd, REPO_FILE) { |f| File.file?(f) }.first raise "No repo found (signaled by #{REPO_FILE}) from pwd to root." if repo_file.nil? Cfer::Auster::Repo.new File.dirname(repo_file) end |
Instance Method Details
#config_set(id) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/cfer/auster/repo.rb', line 98 def config_set(id) raise "Config set not found with id '#{id}'." unless @config_sets.include?(id) tokens = id.split("/") name = tokens[1] region = tokens[0] filename = File.join(@cfg_root, "#{id}.yaml") schema_file = File.join(@cfg_root, "schema.yaml") schema_file = nil unless File.file?(schema_file) Cfer::Auster::Config.from_file(name: name, aws_region: region, schema_file: schema_file, data_file: filename) end |
#nuke(config_set) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/cfer/auster/repo.rb', line 115 def nuke(config_set) raise "config_set must be a Cfer::Auster::Config." unless config_set.is_a?(Cfer::Auster::Config) logger.info "Nuking '#{config_set.full_name}'." ordered_steps.reverse.each { |step| step.destroy(config_set) } end |
#ordered_steps ⇒ Object
72 73 74 |
# File 'lib/cfer/auster/repo.rb', line 72 def ordered_steps @steps.sort.map(&:last) end |
#run_task(task_name, config_set, args = []) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/cfer/auster/repo.rb', line 82 def run_task(task_name, config_set, args = []) logger.debug "Attempting to run task '#{task_name}'." task_file = "#{root}/tasks/#{task_name}.rb" raise "task '#{task_name}' (#{task_file}) doesn't exist." \ unless File.file?(task_file) Cfer::Auster::ScriptExecutor.new( config_set.env_vars_for_shell.merge( repo: self, config_set: config_set, args: args ) ).run(task_file) end |
#step_by_count(count) ⇒ Object
60 61 62 |
# File 'lib/cfer/auster/repo.rb', line 60 def step_by_count(count) @steps[count.to_i] end |
#step_by_count_or_tag(value) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/cfer/auster/repo.rb', line 64 def step_by_count_or_tag(value) if INT_REGEX.match(value) step_by_count(value) else step_by_tag(value) end end |
#step_by_tag(tag) ⇒ Object
55 56 57 58 |
# File 'lib/cfer/auster/repo.rb', line 55 def step_by_tag(tag) raise "Couldn't find a step with tag '#{tag}'." unless @steps_by_tag.key?(tag) @steps[@steps_by_tag[tag]] end |