Class: Hako::EnvProviders::File
- Inherits:
-
Hako::EnvProvider
- Object
- Hako::EnvProvider
- Hako::EnvProviders::File
- Defined in:
- lib/hako/env_providers/file.rb
Instance Method Summary collapse
- #ask(variables) ⇒ Hash<String, String>
- #ask_keys(variables) ⇒ Array<String>
- #can_ask_keys? ⇒ Boolean
-
#initialize(root_path, options) ⇒ File
constructor
A new instance of File.
- #read_from_file {|key, val| ... } ⇒ nil private
Methods inherited from Hako::EnvProvider
Constructor Details
#initialize(root_path, options) ⇒ File
Returns a new instance of File.
10 11 12 13 14 15 |
# File 'lib/hako/env_providers/file.rb', line 10 def initialize(root_path, ) # rubocop:disable Lint/MissingSuper unless ['path'] validation_error!('path must be set') end @path = root_path.join(['path']) end |
Instance Method Details
#ask(variables) ⇒ Hash<String, String>
19 20 21 22 23 24 25 26 27 |
# File 'lib/hako/env_providers/file.rb', line 19 def ask(variables) env = {} read_from_file do |key, val| if variables.include?(key) env[key] = val end end env end |
#ask_keys(variables) ⇒ Array<String>
36 37 38 39 40 41 42 43 44 |
# File 'lib/hako/env_providers/file.rb', line 36 def ask_keys(variables) keys = [] read_from_file do |key, _| if variables.include?(key) keys << key end end keys end |
#can_ask_keys? ⇒ Boolean
30 31 32 |
# File 'lib/hako/env_providers/file.rb', line 30 def can_ask_keys? true end |
#read_from_file {|key, val| ... } ⇒ nil (private)
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/hako/env_providers/file.rb', line 51 def read_from_file(&block) ::File.open(@path) do |f| f.each_line do |line| line.chomp! line.lstrip! if line[0] == '#' # line comment next end key, val = line.split('=', 2) if val block.call(key, val) end end end end |