Class: Lookbook::DataResolver
- Inherits:
-
Service
- Object
- Service
- Lookbook::DataResolver
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_dir ⇒ Object
6
7
8
|
# File 'lib/lookbook/services/data/resolvers/data_resolver.rb', line 6
def base_dir
@base_dir
end
|
#eval_context ⇒ Object
6
7
8
|
# File 'lib/lookbook/services/data/resolvers/data_resolver.rb', line 6
def eval_context
@eval_context
end
|
#fallback ⇒ Object
6
7
8
|
# File 'lib/lookbook/services/data/resolvers/data_resolver.rb', line 6
def fallback
@fallback
end
|
#file ⇒ Object
6
7
8
|
# File 'lib/lookbook/services/data/resolvers/data_resolver.rb', line 6
def file
@file
end
|
Class Method Details
.resolveable?(input) ⇒ 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
#call ⇒ Object
17
18
19
20
21
22
|
# File 'lib/lookbook/services/data/resolvers/data_resolver.rb', line 17
def call
resolve (@input)
rescue => exception
Lookbook.logger.debug "Data resolution failed. (Input: '#{@input}')"
@fail_silently ? fallback : raise(exception)
end
|