Class: Lookbook::TagOptionsParser

Inherits:
Service
  • Object
show all
Defined in:
lib/lookbook/services/tags/tag_options_parser.rb

Constant Summary collapse

RESOLVERS =
[
  FileResolver,
  MethodResolver,
  EvalResolver,
  YamlResolver
]

Instance Method Summary collapse

Methods inherited from Service

call

Constructor Details

#initialize(input, resolver_opts = {}) ⇒ TagOptionsParser

Returns a new instance of TagOptionsParser.



10
11
12
13
14
15
# File 'lib/lookbook/services/tags/tag_options_parser.rb', line 10

def initialize(input, resolver_opts = {})
  @input = input.to_s.strip
  @resolve = resolver_opts.fetch(:resolve, true)
  @resolver_opts = resolver_opts.except(:resolve)
  @fallback = resolver_opts.fetch(:fallback, {})
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/lookbook/services/tags/tag_options_parser.rb', line 17

def call
  options_string, remaining_text = parse_input(@input)
  if resolve?
    resolved_options = resolver(options_string).call(options_string, **@resolver_opts)
    options = prepare_options(resolved_options)
    [options, remaining_text]
  else
    [options_string, remaining_text]
  end
end