Class: Apipie::Params::Descriptor::Array
- Inherits:
-
JsonSchema
- Object
- Base
- JsonSchema
- Apipie::Params::Descriptor::Array
- Extended by:
- Forwardable
- Defined in:
- lib/apipie/params/descriptor.rb
Class Method Summary collapse
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize(descriptor_or_block, options) ⇒ Array
constructor
A new instance of Array.
- #json_schema ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
-
#respond_to?(method) ⇒ Boolean
delegate to params and param only if @descriptor supports those.
Methods inherited from JsonSchema
Methods inherited from Base
find, inherited, #invalid_param_error, #to_json
Constructor Details
#initialize(descriptor_or_block, options) ⇒ Array
Returns a new instance of Array.
248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/apipie/params/descriptor.rb', line 248 def initialize(descriptor_or_block, ) super() case descriptor_or_block when ::Proc @descriptor = Hash.new(descriptor_or_block, ) when Descriptor::Base @descriptor = descriptor_or_block else raise ArgumentError, "Proc or Descriptor::Base expected, got #{descriptor_or_block.class.name}" end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
281 282 283 284 285 286 287 |
# File 'lib/apipie/params/descriptor.rb', line 281 def method_missing(method, *args, &block) if respond_to?(method) @descriptor.send(method, *args, &block) else super end end |
Class Method Details
.build(argument, options, block) ⇒ Object
242 243 244 245 246 |
# File 'lib/apipie/params/descriptor.rb', line 242 def self.build(argument, , block) if argument == ::Array && block.is_a?(::Proc) self.new(block, ) end end |
Instance Method Details
#description ⇒ Object
260 261 262 |
# File 'lib/apipie/params/descriptor.rb', line 260 def description "Must be an Array" end |
#json_schema ⇒ Object
264 265 266 267 268 269 |
# File 'lib/apipie/params/descriptor.rb', line 264 def json_schema super.merge( 'type' => 'array', 'items' => @descriptor.json_schema ) end |
#respond_to?(method) ⇒ Boolean
delegate to params and param only if @descriptor supports those
272 273 274 275 276 277 278 279 |
# File 'lib/apipie/params/descriptor.rb', line 272 def respond_to?(method) case method.to_s when 'params', 'param' @descriptor.respond_to?(method) else super end end |