Module: PromptLists

Defined in:
lib/prompt_lists.rb

Defined Under Namespace

Classes: List, Sublist

Constant Summary collapse

VERSION =
'0.1.6'

Class Method Summary collapse

Class Method Details

.allObject



49
50
51
52
53
54
# File 'lib/prompt_lists.rb', line 49

def all
  Dir[File.expand_path("../lists/*", __dir__)].map do |list|
    list_name = File.basename(list)
    find(list_name)
  end
end

.find(list_name) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/prompt_lists.rb', line 56

def find(list_name)
  @lists ||= {}

  if list_name.to_s.include?('.')
    main_list, sublist = list_name.to_s.split('.')
    if list_exists?(main_list)
      list = find(main_list)
      sublist_sym = sublist&.gsub(/-/, '_')&.to_sym
      return list.send(sublist_sym) if list.sublist_names.include?(sublist_sym)
    end
  elsif list_exists?(list_name)
    @lists[list_name.to_sym] ||= List.new(list_name, load_sublists(list_name))
    return @lists[list_name.to_sym]
  end
  nil
end

.method_missing(method_name, *args) ⇒ Object



73
74
75
# File 'lib/prompt_lists.rb', line 73

def method_missing(method_name, *args)
  find(method_name) || super
end