Module: Luo::Prompts

Extended by:
Dry::Configurable, Prompts
Included in:
Prompts
Defined in:
lib/luo/prompts.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/luo/prompts.rb', line 33

def method_missing(method_name, *args, &block)
  template_file = template_file_path(method_name)
  if template_file
    define_template(method_name, template_file)
    send(method_name)
  else
    super
  end
end

Instance Method Details

#define_template(template_name, file_path) ⇒ Object



25
26
27
28
29
# File 'lib/luo/prompts.rb', line 25

def define_template(template_name, file_path)
  define_method(template_name) do
    PromptTemplate.create(file_path)
  end
end

#define_templatesObject



12
13
14
15
# File 'lib/luo/prompts.rb', line 12

def define_templates
  define_templates_in_dir(config.gem_templates_dir)
  define_templates_in_dir(config.prompts_dir)
end

#define_templates_in_dir(dir_path) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/luo/prompts.rb', line 17

def define_templates_in_dir(dir_path)
  path = Pathname.new(dir_path).expand_path.join("*.md.erb").to_s
  Dir.glob(path) do |file|
    template_name = File.basename(file, '.md.erb').to_sym
    define_template(template_name, file)
  end
end

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

Returns:

  • (Boolean)


43
44
45
# File 'lib/luo/prompts.rb', line 43

def respond_to_missing?(method_name, include_private = false)
  template_file_path(method_name) || super
end