Class: Onair::Config
- Inherits:
-
Object
- Object
- Onair::Config
- Defined in:
- lib/onair/config.rb
Overview
Resolution order: CLI flags → env vars → .onair.yml (searched upward
from cwd to the git root) → error with a hint to run onair init.
Constant Summary collapse
- FILENAME =
".onair.yml"
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#fetch ⇒ Object
readonly
Returns the value of attribute fetch.
-
#platform ⇒ Object
readonly
Returns the value of attribute platform.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#task ⇒ Object
readonly
Returns the value of attribute task.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(platform:, app:, repo:, branch:, fetch:, task: nil) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(platform:, app:, repo:, branch:, fetch:, task: nil) ⇒ Config
Returns a new instance of Config.
13 14 15 16 17 18 19 20 |
# File 'lib/onair/config.rb', line 13 def initialize(platform:, app:, repo:, branch:, fetch:, task: nil) @platform = platform @app = app @repo = repo @branch = branch @fetch = fetch @task = task end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
11 12 13 |
# File 'lib/onair/config.rb', line 11 def app @app end |
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
11 12 13 |
# File 'lib/onair/config.rb', line 11 def branch @branch end |
#fetch ⇒ Object (readonly)
Returns the value of attribute fetch.
11 12 13 |
# File 'lib/onair/config.rb', line 11 def fetch @fetch end |
#platform ⇒ Object (readonly)
Returns the value of attribute platform.
11 12 13 |
# File 'lib/onair/config.rb', line 11 def platform @platform end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
11 12 13 |
# File 'lib/onair/config.rb', line 11 def repo @repo end |
#task ⇒ Object (readonly)
Returns the value of attribute task.
11 12 13 |
# File 'lib/onair/config.rb', line 11 def task @task end |
Class Method Details
.find_file(start) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/onair/config.rb', line 37 def self.find_file(start) dir = File.(start) loop do path = File.join(dir, FILENAME) return YAML.safe_load_file(path) || {} if File.file?(path) return nil if File.exist?(File.join(dir, ".git")) parent = File.dirname(dir) return nil if parent == dir dir = parent end end |
.resolve(flags = {}, env: ENV, dir: Dir.pwd) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/onair/config.rb', line 22 def self.resolve(flags = {}, env: ENV, dir: Dir.pwd) file = find_file(dir) || {} app = flags[:app] || env["HEROKU_APP"] || file["app"] raise Error, "no app configured — pass --app NAME, set HEROKU_APP, or run `onair init`" if app.nil? new( platform: file["platform"] || "heroku", app: app, repo: env["GITHUB_REPO"] || file["repo"], branch: file["branch"] || "main", fetch: !flags[:no_fetch], task: TaskLink.from_config(file["task"]) ) end |