Class: Lam::Process::ProcessorDeducer
- Inherits:
-
Object
- Object
- Lam::Process::ProcessorDeducer
- Defined in:
- lib/lam/process/processor_deducer.rb
Instance Method Summary collapse
-
#controller ⇒ Object
Deduces the path and method from the handler.
-
#function ⇒ Object
Deduces the path and method from the handler.
-
#initialize(handler) ⇒ ProcessorDeducer
constructor
A new instance of ProcessorDeducer.
Constructor Details
#initialize(handler) ⇒ ProcessorDeducer
Returns a new instance of ProcessorDeducer.
2 3 4 |
# File 'lib/lam/process/processor_deducer.rb', line 2 def initialize(handler) @handler = handler end |
Instance Method Details
#controller ⇒ Object
Deduces the path and method from the handler. Example:
ProcessorDeducer.new("handlers/controllers/posts.create").controller
=> {path: "controllers/posts_controller.rb", code: "create"}
Summary:
Input:
handler: handlers/controllers/posts.create
Output:
path: app/controllers/posts_controller.rb
code: create # code to instance_eval
Returns: path, code: code
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/lam/process/processor_deducer.rb', line 41 def controller handler_path, meth = @handler.split('.') path = Lam.root + handler_path.sub("handlers", "app") + "_controller.rb" controller_name = handler_path.sub(%r{.*handlers/controllers/}, "") + "_controller" # posts_controller controller_class = controller_name.split('_').collect(&:capitalize).join # PostsController code = "#{controller_class}.new(event, context).#{meth}" # PostsController.new(event, context).create {path: path, code: code, class_name: controller_class} end |
#function ⇒ Object
Deduces the path and method from the handler. Example:
ProcessorDeducer.new("handlers/functions/posts.create").function
=> {path: "app/functions/posts.rb", code: "create(event, context)"}
Summary:
Input:
handler: handlers/functions/posts.create
Output:
path: app/functions/posts.rb
code: create(event, context) # code to instance_eval
Returns: path, code: code
20 21 22 23 24 25 |
# File 'lib/lam/process/processor_deducer.rb', line 20 def function path, meth = @handler.split('.') path = Lam.root + path.sub("handlers", "app") + ".rb" code = "#{meth}(event, context)" {path: path, code: code} end |