Class: AppKernel::FunctionDefinition

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

Defined Under Namespace

Classes: Option, Validator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, mod, definition) ⇒ FunctionDefinition

Returns a new instance of FunctionDefinition.



134
135
136
137
138
139
140
141
# File 'lib/appkernel/function.rb', line 134

def initialize(name, mod, definition)
  @name = name
  @mod = mod
  @options = {}
  @impl = lambda {}
  @validation = ::AppKernel::Validation::Validator.new(self)
  self.instance_eval &definition
end

Instance Attribute Details

#implObject (readonly)

Returns the value of attribute impl.



132
133
134
# File 'lib/appkernel/function.rb', line 132

def impl
  @impl
end

#modObject (readonly)

Returns the value of attribute mod.



132
133
134
# File 'lib/appkernel/function.rb', line 132

def mod
  @mod
end

#nameObject (readonly)

Returns the value of attribute name.



132
133
134
# File 'lib/appkernel/function.rb', line 132

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



132
133
134
# File 'lib/appkernel/function.rb', line 132

def options
  @options
end

#validationObject (readonly)

Returns the value of attribute validation.



132
133
134
# File 'lib/appkernel/function.rb', line 132

def validation
  @validation
end

Instance Method Details

#execute(&impl) ⇒ Object



152
153
154
# File 'lib/appkernel/function.rb', line 152

def execute(&impl)
  @impl = impl
end

#indexed_optionsObject



148
149
150
# File 'lib/appkernel/function.rb', line 148

def indexed_options
  @options.values.select {|o| o.index}.sort_by {|a| a.index}
end

#option(name, params = {}) ⇒ Object



143
144
145
146
# File 'lib/appkernel/function.rb', line 143

def option(name, params = {})
  name = name.to_sym
  @options[name] = Option.new(name, params)
end

#to_sObject



160
161
162
# File 'lib/appkernel/function.rb', line 160

def to_s
  "#{@name}()"
end

#validate(&checks) ⇒ Object



156
157
158
# File 'lib/appkernel/function.rb', line 156

def validate(&checks)
  @validation = AppKernel::Validation::Validator.new(self, &checks)
end