Class: AppKernel::FunctionApplication

Inherits:
Object
  • Object
show all
Defined in:
lib/appkernel/function.rb

Defined Under Namespace

Classes: Arguments

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#argsObject (readonly)

Returns the value of attribute args.



36
37
38
# File 'lib/appkernel/function.rb', line 36

def args
  @args
end

#errorsObject (readonly)

Returns the value of attribute errors.



36
37
38
# File 'lib/appkernel/function.rb', line 36

def errors
  @errors
end

#functionObject (readonly)

Returns the value of attribute function.



36
37
38
# File 'lib/appkernel/function.rb', line 36

def function
  @function
end

#return_valueObject (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.options) if app.successful?
  if app.successful?
    scope = Object.new
    scope.extend fun.mod
    for k,v in app.options do
      scope.instance_variable_set("@#{k}", v)
    end
    scope.instance_eval &fun.impl
  end
end

Instance Method Details

#optionsObject



49
50
51
# File 'lib/appkernel/function.rb', line 49

def options
  @args.canonical
end

#successful?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/appkernel/function.rb', line 45

def successful?
  @errors.empty?
end