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.



14
15
16
17
# File 'lib/render/attributes/attribute.rb', line 14

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

Instance Attribute Details

#enumsObject

Returns the value of attribute enums.



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

def enums
  @enums
end

#formatObject

Returns the value of attribute format.



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

def format
  @format
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#requiredObject

Returns the value of attribute required.



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

def required
  @required
end

#schemaObject

Returns the value of attribute schema.



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

def schema
  @schema
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#bias_typeObject



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

def bias_type
  format || type
end

#default_valueObject



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

def default_value
  Render.live ? nil : faux_value
end

#nested_schema?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


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

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