Class: BeamUp::Core
- Inherits:
-
Object
- Object
- BeamUp::Core
- Defined in:
- lib/beam_up/core.rb
Class Attribute Summary collapse
-
.config_file ⇒ Object
writeonly
Sets the attribute config_file.
Class Method Summary collapse
- .configuration(config_file: nil) ⇒ Object
- .configure {|configuration| ... } ⇒ Object
- .deploy!(path = nil, provider: nil, config_file: nil) ⇒ Object
- .init!(provider, config_file: nil, values: {}) ⇒ Object
Class Attribute Details
.config_file=(value) ⇒ Object (writeonly)
Sets the attribute config_file
13 14 15 |
# File 'lib/beam_up/core.rb', line 13 def config_file=(value) @config_file = value end |
Class Method Details
.configuration(config_file: nil) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/beam_up/core.rb', line 15 def configuration(config_file: nil) @configuration ||= begin custom_path = config_file || @config_file || ((@configuration&.config_file && File.exist?(@configuration.config_file)) ? @configuration.config_file : nil) config = custom_path ? configuration_file(custom_path) : configuration_file config || raise(ConfigurationError, "No .beam_up.yml found. Run `beam_up init PROVIDER` to create one.") end end |
.configure {|configuration| ... } ⇒ Object
9 10 11 |
# File 'lib/beam_up/core.rb', line 9 def configure(&block) yield(configuration) end |
.deploy!(path = nil, provider: nil, config_file: nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/beam_up/core.rb', line 24 def deploy!(path = nil, provider: nil, config_file: nil) config = configuration(config_file: config_file) config.provider = provider if provider deploy_path = path || config.path || raise(ConfigurationError, "No path specified") config.validate! execute! config.before_actions provider_class = PROVIDERS[config.provider.to_s] || raise(ConfigurationError, "Unknown provider: #{config.provider}") result = provider_class.new(config.provider_config).deploy! deploy_path execute! config.after_actions result end |
.init!(provider, config_file: nil, values: {}) ⇒ Object
42 43 44 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 |
# File 'lib/beam_up/core.rb', line 42 def init!(provider, config_file: nil, values: {}) raise ConfigurationError, "Unknown provider: #{provider}" unless PROVIDERS.key?(provider) config_file ||= ["config/beam_up.yml", ".beam_up.yml"].find { File.exist?(it) } config_file ||= ".beam_up.yml" if File.exist?(config_file) data = YAML.safe_load_file(config_file) || {} raise ConfigurationError, "Provider '#{provider}' already configured in #{config_file}" if data.key?(provider) end config_keys = PROVIDERS[provider]::Config.config_keys if values.empty? && $stdout.tty? && !ENV["TTY_TEST"] prompt = TTY::Prompt.new values = config_keys.to_h { |key| [key, prompt.ask("#{key}:") { it.required false }.to_s] } end configured_values = config_keys.to_h { [it, values[it].to_s] } if File.exist?(config_file) section = YAML.dump({provider => configured_values}, indent: 2, line_width: 80).sub(/^---\n/, "") File.write(config_file, File.read(config_file) + "\n" + section) else yaml = YAML.dump({ "provider" => provider, "path" => nil, provider => configured_values }, indent: 2, line_width: 80).gsub(/^path:$/, "# path: ./output # uncomment to set a default folder") File.write(config_file, yaml) end config_file end |