Class: Lam::Build::HandlerGenerator
- Inherits:
-
Object
- Object
- Lam::Build::HandlerGenerator
- Defined in:
- lib/lam/build/handler_generator.rb
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(handler_info) ⇒ HandlerGenerator
constructor
handler_info: :js_path=>“handlers/controllers/posts.js”, :js_method=>“create”.
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
#generate ⇒ Object
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.('../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 |