Class: Callapi::Routes::HelperMethodCreator
- Inherits:
-
Object
- Object
- Callapi::Routes::HelperMethodCreator
- Defined in:
- lib/callapi/routes/helper_method_creator.rb
Constant Summary collapse
- POSTFIX =
'_call'
Instance Method Summary collapse
- #create ⇒ Object
- #helper_method_base_name ⇒ Object
- #helper_method_name ⇒ Object
-
#initialize(call_class) ⇒ HelperMethodCreator
constructor
A new instance of HelperMethodCreator.
Constructor Details
#initialize(call_class) ⇒ HelperMethodCreator
Returns a new instance of HelperMethodCreator.
4 5 6 7 |
# File 'lib/callapi/routes/helper_method_creator.rb', line 4 def initialize(call_class) @call_class = call_class @call_class_name = call_class.to_s end |
Instance Method Details
#create ⇒ Object
9 10 11 12 13 14 |
# File 'lib/callapi/routes/helper_method_creator.rb', line 9 def create call_class = @call_class Object.send(:define_method, helper_method_name) do |*args| call_class.new(*args) end end |
#helper_method_base_name ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/callapi/routes/helper_method_creator.rb', line 16 def helper_method_base_name class_name = @call_class_name.dup class_name.scan(/(::)?((\w)+)Param/).map { |matched_groups| matched_groups[1] }.compact.each do |pattern| class_name.sub!(pattern, "By#{pattern}") class_name.sub!('Param', '') end class_name end |
#helper_method_name ⇒ Object
25 26 27 |
# File 'lib/callapi/routes/helper_method_creator.rb', line 25 def helper_method_name SuperString.underscore(helper_method_base_name).gsub('/', '_').gsub('callapi_', '') + POSTFIX end |