Class: Opto::Resolvers::File
- Inherits:
-
Opto::Resolver
- Object
- Opto::Resolver
- Opto::Resolvers::File
- Defined in:
- lib/opto/resolvers/file_content.rb
Overview
Read the value from a file, path defined in hint.
Instance Attribute Summary
Attributes inherited from Opto::Resolver
Instance Method Summary collapse
Methods inherited from Opto::Resolver
for, inherited, #initialize, origin, #origin, resolvers
Constructor Details
This class inherits a constructor from Opto::Resolver
Instance Method Details
#file_path ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/opto/resolvers/file_content.rb', line 10 def file_path if hint.kind_of?(String) hint elsif hint.kind_of?(Hash) && (hint['path'] || hint[:path]) hint['path'] || hint[:path] else raise ArgumentError, "File path not set" end end |
#ignore_errors? ⇒ Boolean
6 7 8 |
# File 'lib/opto/resolvers/file_content.rb', line 6 def ignore_errors? hint.kind_of?(Hash) && (hint['ignore_errors'] || hint[:ignore_errors]) end |
#resolve ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/opto/resolvers/file_content.rb', line 20 def resolve if ignore_errors? file_path ::File.read(file_path) rescue nil else ::File.read(file_path) end end |