Class: Lookbook::DataResolver

Inherits:
Service
  • Object
show all
Defined in:
lib/lookbook/services/data/resolvers/data_resolver.rb

Constant Summary collapse

MATCHER =
/(?!.*)/
MATCH_INDEX =
1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Service

call

Constructor Details

#initialize(input, eval_context: nil, fail_silently: false, base_dir: Rails.root, file: nil, fallback: nil) ⇒ DataResolver

Returns a new instance of DataResolver.



8
9
10
11
12
13
14
15
# File 'lib/lookbook/services/data/resolvers/data_resolver.rb', line 8

def initialize(input, eval_context: nil, fail_silently: false, base_dir: Rails.root, file: nil, fallback: nil)
  @input = input.to_s
  @eval_context = eval_context
  @fail_silently = fail_silently
  @fallback = fallback
  @base_dir = base_dir.to_s
  @file = file.to_s
end

Instance Attribute Details

#base_dirObject (readonly)



6
7
8
# File 'lib/lookbook/services/data/resolvers/data_resolver.rb', line 6

def base_dir
  @base_dir
end

#eval_contextObject (readonly)



6
7
8
# File 'lib/lookbook/services/data/resolvers/data_resolver.rb', line 6

def eval_context
  @eval_context
end

#fallbackObject (readonly)



6
7
8
# File 'lib/lookbook/services/data/resolvers/data_resolver.rb', line 6

def fallback
  @fallback
end

#fileObject (readonly)



6
7
8
# File 'lib/lookbook/services/data/resolvers/data_resolver.rb', line 6

def file
  @file
end

Class Method Details

.resolveable?(input) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/lookbook/services/data/resolvers/data_resolver.rb', line 24

def self.resolveable?(input)
  input.to_s.match?(self::MATCHER)
end

Instance Method Details

#callObject



17
18
19
20
21
22
# File 'lib/lookbook/services/data/resolvers/data_resolver.rb', line 17

def call
  resolve extract(@input)
rescue => exception
  Lookbook.logger.debug "Data resolution failed. (Input: '#{@input}')"
  @fail_silently ? fallback : raise(exception)
end