Class: DotEnv
- Inherits:
-
Object
- Object
- DotEnv
- Defined in:
- lib/dot_example/dot_env.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #create_file ⇒ Object
- #create_file_if_does_not_exist ⇒ Object
-
#initialize(filename = nil) ⇒ DotEnv
constructor
A new instance of DotEnv.
- #key_lines ⇒ Object
- #keys ⇒ Object
- #lint! ⇒ Object
Constructor Details
#initialize(filename = nil) ⇒ DotEnv
Returns a new instance of DotEnv.
2 3 4 5 |
# File 'lib/dot_example/dot_env.rb', line 2 def initialize(filename = nil) @filename = filename || ".env" create_file_if_does_not_exist end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
7 8 9 |
# File 'lib/dot_example/dot_env.rb', line 7 def filename @filename end |
Instance Method Details
#create_file ⇒ Object
32 33 34 35 36 |
# File 'lib/dot_example/dot_env.rb', line 32 def create_file %x[ touch #{filename} ] puts Paint[".env created", :green] # TODO: Add to .gitignore if it's not there already. end |
#create_file_if_does_not_exist ⇒ Object
26 27 28 29 30 |
# File 'lib/dot_example/dot_env.rb', line 26 def create_file_if_does_not_exist unless Dir.glob(filename).any? create_file end end |
#key_lines ⇒ Object
9 10 11 |
# File 'lib/dot_example/dot_env.rb', line 9 def key_lines keys.map { |key| key + "=" }.join("\n") end |
#keys ⇒ Object
20 21 22 23 24 |
# File 'lib/dot_example/dot_env.rb', line 20 def keys lines.map do |line| line.split("=")[0] end end |
#lint! ⇒ Object
13 14 15 16 17 18 |
# File 'lib/dot_example/dot_env.rb', line 13 def lint! unless line.match(/^[^=\s]*=[^=\s]*$/) # TODO: Don't know if this is the best error message raise "Invalid Environment variable defintion" end end |