Class: Render::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/render/attributes/attribute.rb

Direct Known Subclasses

ArrayAttribute, HashAttribute

Constant Summary collapse

SCHEMA_IDENTIFIERS =
[:properties, :items].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Attribute

Returns a new instance of Attribute.



22
23
24
# File 'lib/render/attributes/attribute.rb', line 22

def initialize(options = {})
  Render.logger.debug("Initializing attribute #{options}")
end

Instance Attribute Details

#default=(value) ⇒ Object (writeonly)

Sets the attribute default

Parameters:

  • value

    the value to set the attribute default to.



20
21
22
# File 'lib/render/attributes/attribute.rb', line 20

def default=(value)
  @default = value
end

#enumsObject

Returns the value of attribute enums.



7
8
9
# File 'lib/render/attributes/attribute.rb', line 7

def enums
  @enums
end

#exclusive_maximumObject

Returns the value of attribute exclusive_maximum.



7
8
9
# File 'lib/render/attributes/attribute.rb', line 7

def exclusive_maximum
  @exclusive_maximum
end

#exclusive_minimumObject

Returns the value of attribute exclusive_minimum.



7
8
9
# File 'lib/render/attributes/attribute.rb', line 7

def exclusive_minimum
  @exclusive_minimum
end

#formatObject

Returns the value of attribute format.



7
8
9
# File 'lib/render/attributes/attribute.rb', line 7

def format
  @format
end

#max_lengthObject

Returns the value of attribute max_length.



7
8
9
# File 'lib/render/attributes/attribute.rb', line 7

def max_length
  @max_length
end

#maximumObject

Returns the value of attribute maximum.



7
8
9
# File 'lib/render/attributes/attribute.rb', line 7

def maximum
  @maximum
end

#min_lengthObject

Returns the value of attribute min_length.



7
8
9
# File 'lib/render/attributes/attribute.rb', line 7

def min_length
  @min_length
end

#minimumObject

Returns the value of attribute minimum.



7
8
9
# File 'lib/render/attributes/attribute.rb', line 7

def minimum
  @minimum
end

#multiple_ofObject

Returns the value of attribute multiple_of.



7
8
9
# File 'lib/render/attributes/attribute.rb', line 7

def multiple_of
  @multiple_of
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/render/attributes/attribute.rb', line 7

def name
  @name
end

#schemaObject

Returns the value of attribute schema.



7
8
9
# File 'lib/render/attributes/attribute.rb', line 7

def schema
  @schema
end

#typesObject

Returns the value of attribute types.



7
8
9
# File 'lib/render/attributes/attribute.rb', line 7

def types
  @types
end

Instance Method Details

#bias_typeObject



26
27
28
# File 'lib/render/attributes/attribute.rb', line 26

def bias_type
  format || types.first
end

#default_valueObject



30
31
32
# File 'lib/render/attributes/attribute.rb', line 30

def default_value
  @default || (Render.live ? nil : faux_value)
end

#nested_schema?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/render/attributes/attribute.rb', line 34

def nested_schema?(options = {})
  options.any? { |name, value| SCHEMA_IDENTIFIERS.include?(name) }
end