Class: Opto::Resolvers::File

Inherits:
Opto::Resolver show all
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

#hint, #option

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_pathObject


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

Returns:

  • (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

#resolveObject


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