Class: Restspec::Schema::Attribute
- Inherits:
-
Object
- Object
- Restspec::Schema::Attribute
- Defined in:
- lib/restspec/schema/attribute.rb
Overview
An attribute is a part of a schema. All attributes have a name and a type at least. A type is an instance of a subclass of Types::BasicType that keeps information about what are valid instances of the attribute and can generate valid instances of the attribute.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#can?(ability) ⇒ true, false
If the attribute has the ability being passed.
-
#can_be_checked? ⇒ true, false
If the attribute has the ability to be used in payloads.
-
#example ⇒ Object
The inner example in the attribute created calling the :example option when generating examples.
-
#initialize(name, type, options = {}) ⇒ Object
constructor
Creates an attribute.
Constructor Details
#initialize(name, type, options = {}) ⇒ Object
Creates an attribute. It uses an identifier (name), an instance of a subclass of Types::BasicType and a set of options.
43 44 45 46 47 48 |
# File 'lib/restspec/schema/attribute.rb', line 43 def initialize(name, type, = {}) self.name = name self.type = type self.example_override = .fetch(:example, nil) self.allowed_abilities = .fetch(:for, [:response, :payload]) end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
25 26 27 |
# File 'lib/restspec/schema/attribute.rb', line 25 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
25 26 27 |
# File 'lib/restspec/schema/attribute.rb', line 25 def type @type end |
Instance Method Details
#can?(ability) ⇒ true, false
Returns if the attribute has the ability being passed.
64 65 66 |
# File 'lib/restspec/schema/attribute.rb', line 64 def can?(ability) allowed_abilities.include?(ability) end |
#can_be_checked? ⇒ true, false
Returns if the attribute has the ability to be used in payloads.
59 60 61 |
# File 'lib/restspec/schema/attribute.rb', line 59 def can_be_checked? allowed_abilities.include?(:payload) end |
#example ⇒ Object
The inner example in the attribute created calling the :example option when generating examples.
54 55 56 |
# File 'lib/restspec/schema/attribute.rb', line 54 def example @example ||= example_override end |