Class: Sinatra::Schema::Resource
- Inherits:
-
Object
- Object
- Sinatra::Schema::Resource
- Defined in:
- lib/sinatra/schema/resource.rb
Instance Attribute Summary collapse
-
#defs ⇒ Object
Returns the value of attribute defs.
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
Returns the value of attribute id.
-
#links ⇒ Object
Returns the value of attribute links.
-
#path ⇒ Object
Returns the value of attribute path.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(options) ⇒ Resource
constructor
A new instance of Resource.
- #validate_response!(raw) ⇒ Object
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() @path = .fetch(:path).chomp("/") @links = [] @defs = {} @properties = {} end |
Instance Attribute Details
#defs ⇒ Object
Returns the value of attribute defs.
4 5 6 |
# File 'lib/sinatra/schema/resource.rb', line 4 def defs @defs end |
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/sinatra/schema/resource.rb', line 4 def description @description end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/sinatra/schema/resource.rb', line 4 def id @id end |
#links ⇒ Object
Returns the value of attribute links.
4 5 6 |
# File 'lib/sinatra/schema/resource.rb', line 4 def links @links end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/sinatra/schema/resource.rb', line 4 def path @path end |
#properties ⇒ Object
Returns the value of attribute properties.
4 5 6 |
# File 'lib/sinatra/schema/resource.rb', line 4 def properties @properties end |
#title ⇒ Object
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 |