Class: Lam::Build::HandlerGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/lam/build/handler_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(handler_info) ⇒ HandlerGenerator

handler_info:

{:handler=>"handlers/controllers/posts.create",
 :js_path=>"handlers/controllers/posts.js",
 :js_method=>"create"}


10
11
12
13
14
15
# File 'lib/lam/build/handler_generator.rb', line 10

def initialize(handler_info)
  @handler_info = handler_info
  @handler = handler_info[:handler]
  @js_path = handler_info[:js_path]
  @js_method = handler_info[:js_method]
end

Instance Method Details

#generateObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/lam/build/handler_generator.rb', line 17

def generate
  js_path = "#{Lam.root}#{@js_path}"
  FileUtils.mkdir_p(File.dirname(js_path))

  template_path = File.expand_path('../templates/handler.js', __FILE__)
  template = IO.read(template_path)

  # Important ERB variables with examples:
  #   @handler - handlers/controllers/posts.create
  #   @process_type - controller
  @process_type = @handler.split('/')[1].singularize
  result = ERB.new(template, nil, "-").result(binding)
  puts "generating #{js_path}"
  IO.write(js_path, result)
  # FileUtils.cp(template_path, js_path)
end