Class: Sinatra::Schema::Link

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Link

Returns a new instance of Link.



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

def initialize(options={})
  @resource   = options[:resource]
  @method     = options[:method]
  @href       = options[:href]
  @properties = {}
end

Instance Attribute Details

#action_blockObject

Returns the value of attribute action_block.



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

def action_block
  @action_block
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#hrefObject

Returns the value of attribute href.



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

def href
  @href
end

#methodObject

Returns the value of attribute method.



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

def method
  @method
end

#propertiesObject

Returns the value of attribute properties.



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

def properties
  @properties
end

#relObject

Returns the value of attribute rel.



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

def rel
  @rel
end

#resourceObject

Returns the value of attribute resource.



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

def resource
  @resource
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

Instance Method Details

#handlerObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sinatra/schema/link.rb', line 17

def handler
  link = self
  lambda do
    begin
      schema_params = parse_params(link.properties)
      validate_params!(schema_params, link.properties)
      res = instance_exec(schema_params, &link.action_block)
      link.resource.validate_response!(link.rel, res)
      res
    end
  end
end

#register(app) ⇒ Object



13
14
15
# File 'lib/sinatra/schema/link.rb', line 13

def register(app)
  app.send(method, href, &handler)
end