Module: AppKernel::Function::ClassMethods
- Defined in:
- lib/appkernel/function.rb
Instance Method Summary collapse
- #apply(*args) ⇒ Object
- #call(*args) ⇒ Object
- #option(name, modifiers = {}) ⇒ Object
- #options ⇒ Object
- #prepare! ⇒ Object
Instance Method Details
permalink #apply(*args) ⇒ Object
[View source]
96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/appkernel/function.rb', line 96 def apply(*args) Result.new.tap do |result| @options.canonicalize(args, result.errors).tap do |params| if result.successful? new(params).tap do |function| function.validate(Validator.new(result.errors)) if result.successful? result.return_value = function.execute end end end end end end |
permalink #call(*args) ⇒ Object
[View source]
90 91 92 93 94 |
# File 'lib/appkernel/function.rb', line 90 def call(*args) apply(*args).tap {|result| result.verify! }.return_value end |
permalink #option(name, modifiers = {}) ⇒ Object
[View source]
70 71 72 |
# File 'lib/appkernel/function.rb', line 70 def option(name, modifiers = {}) @options.add(name, modifiers) end |
permalink #options ⇒ Object
[View source]
66 67 68 |
# File 'lib/appkernel/function.rb', line 66 def @options end |
permalink #prepare! ⇒ Object
[View source]
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/appkernel/function.rb', line 74 def prepare! @options = Options.new call = Module.new.tap do |mod| unless self.name.nil? || self.name.empty? fun = self path = self.name.split(/::/) simple_name = path[path.length - 1] fun_name = simple_name.gsub(/(\w)([A-Z])([a-z])/) {"#{$1}_#{$2.downcase}#{$3}"}.downcase mod.send(:define_method, fun_name) do |*args| fun.call(*args) end end end self.const_set(:Call, call) end |