Class: AppKernel::FunctionApplication::Arguments
- Inherits:
-
Object
- Object
- AppKernel::FunctionApplication::Arguments
- Defined in:
- lib/appkernel/function.rb
Instance Attribute Summary collapse
-
#canonical ⇒ Object
readonly
Returns the value of attribute canonical.
Instance Method Summary collapse
-
#initialize(app, *args) ⇒ Arguments
constructor
A new instance of Arguments.
- #set(opt, value) ⇒ Object
Constructor Details
#initialize(app, *args) ⇒ Arguments
Returns a new instance of Arguments.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/appkernel/function.rb', line 57 def initialize(app, *args) fun = app.function @app = app @canonical = {} @required = Set.new(fun..values.select {|o| o.required?}) @optorder = fun. for arg in args if (arg.is_a?(Hash)) arg.each do |k,v| if opt = fun.[k.to_sym] set opt, v else raise FunctionCallError, "#{fun.name}: unknown option :#{k}" end end elsif opt = @optorder.shift set opt, arg end end for opt in fun..values if @canonical[opt.name].nil? && !opt.default.nil? @canonical[opt.name] = opt.default @required.delete opt end end for opt in @required app.errors[opt.name] = "missing required option '#{opt.name}'" end for name in fun..keys @canonical[name] = nil if @canonical[name].nil? end end |
Instance Attribute Details
#canonical ⇒ Object (readonly)
Returns the value of attribute canonical.
55 56 57 |
# File 'lib/appkernel/function.rb', line 55 def canonical @canonical end |
Instance Method Details
#set(opt, value) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/appkernel/function.rb', line 91 def set(opt, value) resolved = opt.resolve(@app, value) if !resolved.nil? @canonical[opt.name] = resolved @required.delete opt elsif !value.nil? && opt.required? @required.delete opt @required.delete opt @app.errors[opt.name] = "no such value '#{value}' for required option '#{opt.name}'" end end |