Class: Apipie::Params::Description

Inherits:
Object
  • Object
show all
Defined in:
lib/apipie/params/description.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {}, &block)
  @options = 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,
                                                options,
                                                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_nilObject

Returns the value of attribute allow_nil.



7
8
9
# File 'lib/apipie/params/description.rb', line 7

def allow_nil
  @allow_nil
end

#descObject

Returns the value of attribute desc.



7
8
9
# File 'lib/apipie/params/description.rb', line 7

def desc
  @desc
end

#descriptorObject

Returns the value of attribute descriptor.



7
8
9
# File 'lib/apipie/params/description.rb', line 7

def descriptor
  @descriptor
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/apipie/params/description.rb', line 7

def name
  @name
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/apipie/params/description.rb', line 7

def options
  @options
end

#requiredObject

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

Returns:

  • (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