Class: Restspec::Schema::SchemaExample

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema, extensions = {}) ⇒ SchemaExample

Returns a new instance of SchemaExample.



6
7
8
9
# File 'lib/restspec/schema/schema_example.rb', line 6

def initialize(schema, extensions = {})
  self.schema = schema
  self.extensions = extensions
end

Instance Attribute Details

#extensionsObject

Returns the value of attribute extensions.



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

def extensions
  @extensions
end

#schemaObject

Returns the value of attribute schema.



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

def schema
  @schema
end

Instance Method Details

#valueObject



11
12
13
14
15
16
17
18
19
# File 'lib/restspec/schema/schema_example.rb', line 11

def value
  attributes.inject({}) do |sample, (_, attribute)|
    if attribute.can_generate_examples?
      sample.merge(attribute.name => AttributeExample.new(attribute).value)
    else
      sample
    end
  end.merge(extensions)
end