Class: Apipie::Params::Description
- Inherits:
-
Object
- Object
- Apipie::Params::Description
- Defined in:
- lib/apipie/params/description.rb
Instance Attribute Summary collapse
-
#allow_nil ⇒ Object
Returns the value of attribute allow_nil.
-
#desc ⇒ Object
Returns the value of attribute desc.
-
#descriptor ⇒ Object
Returns the value of attribute descriptor.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#required ⇒ Object
Returns the value of attribute required.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, descriptor_arg, options = {}, &block) ⇒ Description
constructor
A new instance of Description.
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to?(method) ⇒ Boolean
- #validate!(value) ⇒ Object
Constructor Details
#initialize(name, descriptor_arg, options = {}, &block) ⇒ Description
Returns a new instance of Description.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/apipie/params/description.rb', line 15 def initialize(name, descriptor_arg, = {}, &block) @options = @name = name @desc = @options[:desc] # if required is specified, set to boolean of the value, nil # otherwise: nil allows us specify the default value later. @required = @options.has_key?(:required) ? !!@options[:required] : nil @allow_nil = @options.has_key?(:allow_nil) ? !!@options[:allow_nil] : nil unless descriptor_arg.nil? @descriptor = Params::Descriptor::Base.find(descriptor_arg, , block) else @descriptor = nil end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/apipie/params/description.rb', line 47 def method_missing(method, *args, &block) if respond_to?(method) @descriptor.send(method, *args, &block) else super end end |
Instance Attribute Details
#allow_nil ⇒ Object
Returns the value of attribute allow_nil.
7 8 9 |
# File 'lib/apipie/params/description.rb', line 7 def allow_nil @allow_nil end |
#desc ⇒ Object
Returns the value of attribute desc.
7 8 9 |
# File 'lib/apipie/params/description.rb', line 7 def desc @desc end |
#descriptor ⇒ Object
Returns the value of attribute descriptor.
7 8 9 |
# File 'lib/apipie/params/description.rb', line 7 def descriptor @descriptor end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/apipie/params/description.rb', line 7 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/apipie/params/description.rb', line 7 def @options end |
#required ⇒ Object
Returns the value of attribute required.
7 8 9 |
# File 'lib/apipie/params/description.rb', line 7 def required @required end |
Class Method Details
.define(&block) ⇒ Object
9 10 11 12 13 |
# File 'lib/apipie/params/description.rb', line 9 def self.define(&block) param_description = Description.new(nil, nil, {}) param_description.descriptor = Descriptor::Hash.new(block, {}) return param_description end |
Instance Method Details
#respond_to?(method) ⇒ Boolean
38 39 40 41 42 43 44 45 |
# File 'lib/apipie/params/description.rb', line 38 def respond_to?(method) case method.to_s when 'params', 'param' @descriptor.respond_to?(method) else super end end |
#validate!(value) ⇒ Object
34 35 36 |
# File 'lib/apipie/params/description.rb', line 34 def validate!(value) descriptor.validate!(self, value) end |