Class: Sinatra::Rabbit::Param

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/rabbit/param.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Param



22
23
24
25
26
27
28
# File 'lib/sinatra/rabbit/param.rb', line 22

def initialize(*args)
  args.reverse!
  @name, @klass = args.pop, args.pop
  raise "DSL: You need to specify the name and param type (#{@name})" unless @name or @klass
  parse_params!(args)
  @description ||= "Description not available"
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description



20
21
22
# File 'lib/sinatra/rabbit/param.rb', line 20

def description
  @description
end

#klassObject (readonly)

Returns the value of attribute klass



20
21
22
# File 'lib/sinatra/rabbit/param.rb', line 20

def klass
  @klass
end

#nameObject (readonly)

Returns the value of attribute name



20
21
22
# File 'lib/sinatra/rabbit/param.rb', line 20

def name
  @name
end

#requiredObject (readonly)

Returns the value of attribute required



20
21
22
# File 'lib/sinatra/rabbit/param.rb', line 20

def required
  @required
end

#valuesObject (readonly)

Returns the value of attribute values



20
21
22
# File 'lib/sinatra/rabbit/param.rb', line 20

def values
  @values
end

Instance Method Details

#enum?Boolean



32
# File 'lib/sinatra/rabbit/param.rb', line 32

def enum?; !@values.nil?; end

#number?Boolean



33
# File 'lib/sinatra/rabbit/param.rb', line 33

def number?; [:integer, :float, :number].include?(@klass); end

#optional?Boolean



31
# File 'lib/sinatra/rabbit/param.rb', line 31

def optional?; !required?; end

#required?Boolean



30
# File 'lib/sinatra/rabbit/param.rb', line 30

def required?; @required == true; end

#string?Boolean



34
# File 'lib/sinatra/rabbit/param.rb', line 34

def string?; @klass == :string; end

#to_sObject



36
37
38
# File 'lib/sinatra/rabbit/param.rb', line 36

def to_s
  "#{name}:#{klass}:#{required? ? 'required' : 'optional'}"
end