Module: Kanal::Core::Helpers::ParameterFinderWithMethodMissingMixin
- Includes:
- Logging::Logger
- Included in:
- Input::Input, Output::Output
- Defined in:
- lib/kanal/core/helpers/parameter_finder_with_method_missing_mixin.rb
Overview
Module assumes that class where it was included has methods set(name, value) get(name) transforms unknown methods to setters/getters for parameters
Instance Method Summary collapse
Methods included from Logging::Logger
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/kanal/core/helpers/parameter_finder_with_method_missing_mixin.rb', line 15 def method_missing(symbol, *args, &block) if block && !args.first.nil? logger.error "Block and arg given simultaneously. Parameter name: '#{symbol.to_s}, arg: #{args.first}'" raise "Block and arg given simultaneously for parameter #{symbol.to_s}" end parameter_name = symbol.to_s parameter_name.sub! "=", "" parameter_name = parameter_name.to_sym value = block_given? ? block : args.first # standard workflow with settings properties with # input.prop = 123 if symbol.to_s.include? "=" @parameter_bag.set parameter_name, value elsif !args.empty? || block_given? # this approach can be used also in dsl # like that # setters: prop value # getters: prop @parameter_bag.set parameter_name, value # means it is used as setter in dsl, # method call with argument else @parameter_bag.get parameter_name end end |