Class: PromptLists::List

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(list_name, sublist_names) ⇒ List

Returns a new instance of List.



10
11
12
13
# File 'lib/prompt_lists.rb', line 10

def initialize(list_name, sublist_names)
  @id = list_name.to_sym
  @sublist_names = sublist_names
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/prompt_lists.rb', line 15

def method_missing(method_name, *args)
  sublist = @sublist_names.find { |sublist| sublist == method_name }
  if sublist
    sublist_filename = method_name.to_s.gsub(/_/, "-")
    path = File.expand_path("../lists/#{@id}/#{sublist_filename}.yml", __dir__)
    Sublist.new(path)
  else
    super
  end
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/prompt_lists.rb', line 8

def id
  @id
end

#sublist_namesObject (readonly)

Returns the value of attribute sublist_names.



8
9
10
# File 'lib/prompt_lists.rb', line 8

def sublist_names
  @sublist_names
end

Instance Method Details

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/prompt_lists.rb', line 26

def respond_to_missing?(method_name, include_private = false)
  sublist = @sublist_names.find { |sublist| sublist == method_name }
  sublist || super
end