Class: Restspec::Schema::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/restspec/schema/attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, options = {}) ⇒ Attribute

Returns a new instance of Attribute.



6
7
8
9
10
11
# File 'lib/restspec/schema/attribute.rb', line 6

def initialize(name, type, options = {})
  self.name = name
  self.type = type
  self.example_override = options.fetch(:example, nil)
  self.allowed_abilities = options.fetch(:for, [:checks, :examples])
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/restspec/schema/attribute.rb', line 4

def name
  @name
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/restspec/schema/attribute.rb', line 4

def type
  @type
end

Instance Method Details

#can_be_checked?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/restspec/schema/attribute.rb', line 21

def can_be_checked?
  allowed_abilities.include?(:checks)
end

#can_generate_examples?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/restspec/schema/attribute.rb', line 17

def can_generate_examples?
  allowed_abilities.include?(:examples)
end

#exampleObject



13
14
15
# File 'lib/restspec/schema/attribute.rb', line 13

def example
  @example ||= example_override
end