Class: AppKernel::FunctionApplication
- Inherits:
-
Object
- Object
- AppKernel::FunctionApplication
- Defined in:
- lib/appkernel/function.rb
Defined Under Namespace
Classes: Arguments
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#function ⇒ Object
readonly
Returns the value of attribute function.
-
#return_value ⇒ Object
readonly
Returns the value of attribute return_value.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(fun, *args) ⇒ FunctionApplication
constructor
A new instance of FunctionApplication.
- #options ⇒ Object
- #successful? ⇒ Boolean
Constructor Details
#initialize(fun, *args) ⇒ FunctionApplication
Returns a new instance of FunctionApplication.
38 39 40 41 42 43 |
# File 'lib/appkernel/function.rb', line 38 def initialize(fun, *args) @function = fun @errors = {} @args = Arguments.new(self, *args) @return_value = self.class.do_apply(self) end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
36 37 38 |
# File 'lib/appkernel/function.rb', line 36 def args @args end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
36 37 38 |
# File 'lib/appkernel/function.rb', line 36 def errors @errors end |
#function ⇒ Object (readonly)
Returns the value of attribute function.
36 37 38 |
# File 'lib/appkernel/function.rb', line 36 def function @function end |
#return_value ⇒ Object (readonly)
Returns the value of attribute return_value.
36 37 38 |
# File 'lib/appkernel/function.rb', line 36 def return_value @return_value end |
Class Method Details
.apply_or_die(fun, *args) ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/appkernel/function.rb', line 106 def apply_or_die(fun, *args) app = new(fun, *args) if app.successful? app.return_value else raise ValidationError, app end end |
.do_apply(app) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/appkernel/function.rb', line 115 def do_apply(app) fun = app.function app.errors.merge! fun.validation.validate(app.) if app.successful? if app.successful? scope = Object.new scope.extend fun.mod for k,v in app. do scope.instance_variable_set("@#{k}", v) end scope.instance_eval &fun.impl end end |
Instance Method Details
#options ⇒ Object
49 50 51 |
# File 'lib/appkernel/function.rb', line 49 def @args.canonical end |
#successful? ⇒ Boolean
45 46 47 |
# File 'lib/appkernel/function.rb', line 45 def successful? @errors.empty? end |