Class: DotEnvDotExample
- Inherits:
-
Object
- Object
- DotEnvDotExample
- Defined in:
- lib/dot_example/dot_env_dot_example.rb
Instance Attribute Summary collapse
-
#dot_env ⇒ Object
readonly
Returns the value of attribute dot_env.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ DotEnvDotExample
constructor
A new instance of DotEnvDotExample.
- #keys_new_to_example ⇒ Object
- #missing_keys ⇒ Object
- #pre_commit_hook ⇒ Object
- #print_missing_keys_message ⇒ Object
- #print_new_keys_message ⇒ Object
- #write! ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ DotEnvDotExample
Returns a new instance of DotEnvDotExample.
2 3 4 5 |
# File 'lib/dot_example/dot_env_dot_example.rb', line 2 def initialize( = {} ) @filename = [:filename] || ".env.example" @dot_env = [:dot_env] || DotEnv.new end |
Instance Attribute Details
#dot_env ⇒ Object (readonly)
Returns the value of attribute dot_env.
7 8 9 |
# File 'lib/dot_example/dot_env_dot_example.rb', line 7 def dot_env @dot_env end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
7 8 9 |
# File 'lib/dot_example/dot_env_dot_example.rb', line 7 def filename @filename end |
Instance Method Details
#keys_new_to_example ⇒ Object
18 19 20 21 22 |
# File 'lib/dot_example/dot_env_dot_example.rb', line 18 def keys_new_to_example dot_env.keys.reject do |key| keys.map(&:chomp).include? key end end |
#missing_keys ⇒ Object
32 33 34 |
# File 'lib/dot_example/dot_env_dot_example.rb', line 32 def missing_keys keys.reject { |key| dot_env.keys.include?(key) } end |
#pre_commit_hook ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/dot_example/dot_env_dot_example.rb', line 46 def pre_commit_hook # TODO: Make it possible to put .env and .env.example files somewhere else? # Maybe later if people actually want this feature [ "dot_example sync", "git add .env.example" ].join("\n") end |
#print_missing_keys_message ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/dot_example/dot_env_dot_example.rb', line 36 def if missing_keys.any? puts Paint[ "missing ENV variables from #{dot_env.filename}", :green ] puts missing_keys end end |
#print_new_keys_message ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/dot_example/dot_env_dot_example.rb', line 24 def puts Paint[ "New variables added to #{filename}", :green ] puts keys_new_to_example end |
#write! ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/dot_example/dot_env_dot_example.rb', line 9 def write! if keys_new_to_example.any? File.open(filename, "a") do |file| file.puts keys_new_to_example.map { |key| "#{key}=" } end end end |