class Despecable::Spectator
Attributes
params[R]
This class is used to read (eval) the despec block Any methods in that block must be defined here, and this object must be stateful to be read by the controller
specd[R]
This class is used to read (eval) the despec block Any methods in that block must be defined here, and this object must be stateful to be read by the controller
Public Class Methods
new(params)
click to toggle source
# File lib/despecable/spectator.rb, line 9 def initialize(params) @input_params = params # TODO: allow this to be the same object to save copies @params = {} @spectacles = ::Despecable::Spectacles.new @specd = [] end
Public Instance Methods
any(name, options = {})
click to toggle source
# File lib/despecable/spectator.rb, line 45 def any(name, options = {}) _spec(name, :any, options) end
boolean(name, options = {})
click to toggle source
# File lib/despecable/spectator.rb, line 25 def boolean(name, options = {}) _spec(name, :boolean, options) end
custom(name, options = {}, &blk)
click to toggle source
# File lib/despecable/spectator.rb, line 49 def custom(name, options = {}, &blk) _spec(name, :custom, options, &blk) end
date(name, options = {})
click to toggle source
# File lib/despecable/spectator.rb, line 29 def date(name, options = {}) _spec(name, :date, options) end
datetime(name, options = {})
click to toggle source
# File lib/despecable/spectator.rb, line 33 def datetime(name, options = {}) _spec(name, :datetime, options) end
file(name, options = {})
click to toggle source
# File lib/despecable/spectator.rb, line 41 def file(name, options = {}) _spec(name, :file, options) end
float(name, options = {})
click to toggle source
# File lib/despecable/spectator.rb, line 37 def float(name, options = {}) _spec(name, :float, options) end
integer(name, options = {})
click to toggle source
# File lib/despecable/spectator.rb, line 17 def integer(name, options = {}) _spec(name, :integer, options) end
string(name, options = {})
click to toggle source
# File lib/despecable/spectator.rb, line 21 def string(name, options = {}) _spec(name, :string, options) end
Private Instance Methods
_spec(name, type, options = {}, &blk)
click to toggle source
# File lib/despecable/spectator.rb, line 55 def _spec(name, type, options = {}, &blk) @specd << (name) if @input_params.key?(name) @params[name] = @spectacles.read(name, @input_params[name], type, options, &blk) elsif options.key?(:default) @params[name] = options[:default] elsif options.key?(:required) ::Kernel.raise ::Despecable::MissingParameterError.new("Missing required parameter: '#{name}'", parameters: name) end end