Class: Sinatra::Schema::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/schema/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Resource

Returns a new instance of Resource.



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

def initialize(options)
  @path       = options.fetch(:path).chomp("/")
  @links      = []
  @defs       = {}
  @properties = {}
end

Instance Attribute Details

#defsObject

Returns the value of attribute defs.



4
5
6
# File 'lib/sinatra/schema/resource.rb', line 4

def defs
  @defs
end

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/sinatra/schema/resource.rb', line 4

def description
  @description
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/sinatra/schema/resource.rb', line 4

def id
  @id
end

Returns the value of attribute links.



4
5
6
# File 'lib/sinatra/schema/resource.rb', line 4

def links
  @links
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/sinatra/schema/resource.rb', line 4

def path
  @path
end

#propertiesObject

Returns the value of attribute properties.



4
5
6
# File 'lib/sinatra/schema/resource.rb', line 4

def properties
  @properties
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/sinatra/schema/resource.rb', line 4

def title
  @title
end

Instance Method Details

#validate_response!(raw) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sinatra/schema/resource.rb', line 21

def validate_response!(raw)
  # only validate responses in tests
  return unless ENV["RACK_ENV"] == "test"

  res = MultiJson.decode(raw)
  unless res.is_a?(Hash)
    raise "Response should return a hash"
  end

  unless properties.empty?
    Utils.validate_keys!(properties, res)
  end
end