Module: Roro::FileReflection
- Included in:
- CLI, Crypto, Crypto::Exposer, Crypto::KeyWriter, Crypto::Obfuscator
- Defined in:
- lib/roro.rb,
lib/roro/common/file_reflection.rb
Instance Method Summary collapse
- #gather_environments(dir, ext) ⇒ Object
- #get_key(environment, _dir = Roro::CLI.mise) ⇒ Object
- #source_files(dir, pattern) ⇒ Object
Instance Method Details
#gather_environments(dir, ext) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/roro/common/file_reflection.rb', line 10 def gather_environments(dir, ext) environments = source_files(dir, ext).map do |file| file.split('/').last.split('.').first end if environments.empty? raise Roro::Error, "No #{ext} files in #{dir}" else environments.uniq end end |
#get_key(environment, _dir = Roro::CLI.mise) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/roro/common/file_reflection.rb', line 21 def get_key(environment, _dir = Roro::CLI.mise) env_key = "#{environment.upcase}_KEY" key_file = Dir.glob("#{Roro::CLI.mise}/keys/#{environment}.key").first if ENV[env_key] ENV[env_key] elsif key_file File.read(key_file).strip else raise Roro::Error, "No #{env_key} set. Please set one as a variable or in a file." end end |
#source_files(dir, pattern) ⇒ Object
6 7 8 |
# File 'lib/roro/common/file_reflection.rb', line 6 def source_files(dir, pattern) Dir.glob("#{dir}/**/*#{pattern}") end |