Class: Playbook::KitResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/playbook/kit_resolver.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeKitResolver

Returns a new instance of KitResolver.



10
11
12
13
14
15
16
17
# File 'lib/playbook/kit_resolver.rb', line 10

def initialize
  @cache = Hash.new do |_cache, kit_name|
    is_subkit = kit_name.match(%r{[/\\]})
    folder = is_subkit ? kit_name.split("/")[0] : kit_name
    item = is_subkit ? kit_name.split("/")[-1] : kit_name
    @cache[kit_name] = "Playbook::Pb#{folder.camelize}::#{item.camelize}"
  end
end

Class Method Details

.resolve(*args) ⇒ Object



5
6
7
8
# File 'lib/playbook/kit_resolver.rb', line 5

def self.resolve(*args)
  @resolver ||= new
  @resolver.resolve(*args)
end

Instance Method Details

#resolve(kit_name) ⇒ Object



19
20
21
# File 'lib/playbook/kit_resolver.rb', line 19

def resolve(kit_name)
  @cache[kit_name].safe_constantize
end