Class: Milieu::EnvFileExporter
- Inherits:
-
Object
- Object
- Milieu::EnvFileExporter
- Defined in:
- lib/milieu/env_file_exporter.rb
Instance Method Summary collapse
- #export ⇒ Object
- #export_development_schema ⇒ Object
- #export_production_schema ⇒ Object
- #export_schema ⇒ Object
- #export_test_schema ⇒ Object
- #format_value(value) ⇒ Object
-
#initialize(schema) ⇒ EnvFileExporter
constructor
A new instance of EnvFileExporter.
Constructor Details
#initialize(schema) ⇒ EnvFileExporter
Returns a new instance of EnvFileExporter.
5 6 7 |
# File 'lib/milieu/env_file_exporter.rb', line 5 def initialize(schema) @schema = schema end |
Instance Method Details
#export ⇒ Object
9 10 11 12 13 14 |
# File 'lib/milieu/env_file_exporter.rb', line 9 def export File.write("./.env", export_schema) File.write("./.env.development", export_development_schema) File.write("./.env.test", export_test_schema) File.write("./.env.production", export_production_schema) end |
#export_development_schema ⇒ Object
20 21 22 |
# File 'lib/milieu/env_file_exporter.rb', line 20 def export_development_schema @schema.env_overrides[:development].map { |key, value| "#{key}=#{format_value(value)}\n" }.join end |
#export_production_schema ⇒ Object
28 29 30 |
# File 'lib/milieu/env_file_exporter.rb', line 28 def export_production_schema @schema.env_overrides[:production].map { |key, value| "#{key}=#{format_value(value)}\n" }.join end |
#export_schema ⇒ Object
16 17 18 |
# File 'lib/milieu/env_file_exporter.rb', line 16 def export_schema @schema.env_variables.map { |key, value| "#{key}=#{format_value(value)}\n" }.join end |
#export_test_schema ⇒ Object
24 25 26 |
# File 'lib/milieu/env_file_exporter.rb', line 24 def export_test_schema @schema.env_overrides[:test].map { |key, value| "#{key}=#{format_value(value)}\n" }.join end |
#format_value(value) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/milieu/env_file_exporter.rb', line 32 def format_value(value) case value when String %("#{value}") else value end end |