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

- (Param) initialize(*args)

Returns a new instance of 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

- (Object) description (readonly)

Returns the value of attribute description



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

def description
  @description
end

- (Object) klass (readonly)

Returns the value of attribute klass



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

def klass
  @klass
end

- (Object) name (readonly)

Returns the value of attribute name



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

def name
  @name
end

- (Object) required (readonly)

Returns the value of attribute required



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

def required
  @required
end

- (Object) values (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

- (Boolean) enum?

Returns:

  • (Boolean)


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

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

- (Boolean) number?

Returns:

  • (Boolean)


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

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

- (Boolean) optional?

Returns:

  • (Boolean)


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

def optional?; !required?; end

- (Boolean) required?

Returns:

  • (Boolean)


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

def required?; @required == true; end

- (Boolean) string?

Returns:

  • (Boolean)


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

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

- (Object) to_s



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

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