Class: Kanpachi::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/kanpachi/resource.rb,
lib/kanpachi/resource/params.rb

Overview

The Resource class

Defined Under Namespace

Classes: Params

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_verb, url) ⇒ Resource

Resource constructor

Parameters:

  • http_berb (Symbol)

    Resource http verb.

  • url (String)

    Resource’s url. The url will automatically be prepended a slash if it doesn’t already contain one.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/kanpachi/resource.rb', line 27

def initialize(http_verb, url)
  @url                 = url.start_with?('/') ? url : "/#{url}"
  @http_verb           = http_verb
  @formats             = Set.new
  @versions            = Set.new
  @priority            = 50
  @ssl                 = false
  @authentication      = false
  @params              = Class.new(Params)
  @responses           = Kanpachi::ResponseList.new
end

Instance Attribute Details

#authenticationObject



20
21
22
# File 'lib/kanpachi/resource.rb', line 20

def authentication
  @authentication
end

#descriptionObject



17
18
19
# File 'lib/kanpachi/resource.rb', line 17

def description
  @description
end

#formatsObject (readonly)



12
13
14
# File 'lib/kanpachi/resource.rb', line 12

def formats
  @formats
end

#http_verbObject (readonly)



10
11
12
# File 'lib/kanpachi/resource.rb', line 10

def http_verb
  @http_verb
end

#nameObject



16
17
18
# File 'lib/kanpachi/resource.rb', line 16

def name
  @name
end

#paramsObject



15
16
17
# File 'lib/kanpachi/resource.rb', line 15

def params
  @params
end

#priorityObject



18
19
20
# File 'lib/kanpachi/resource.rb', line 18

def priority
  @priority
end

#responsesObject (readonly)



14
15
16
# File 'lib/kanpachi/resource.rb', line 14

def responses
  @responses
end

#sslObject



19
20
21
# File 'lib/kanpachi/resource.rb', line 19

def ssl
  @ssl
end

#urlObject (readonly)



11
12
13
# File 'lib/kanpachi/resource.rb', line 11

def url
  @url
end

#versionsObject (readonly)



13
14
15
# File 'lib/kanpachi/resource.rb', line 13

def versions
  @versions
end

Instance Method Details

#<=>(other) ⇒ Object

Compare two resources using the priority



47
48
49
# File 'lib/kanpachi/resource.rb', line 47

def <=> (other)
  priority <=> other.priority
end

#params?Boolean

Returns true if the resource has defined any params.

Returns:

  • (Boolean)


42
43
44
# File 'lib/kanpachi/resource.rb', line 42

def params?
  !(params.input_filters.required_inputs.empty? && params.input_filters.optional_inputs.empty?)
end

#routeObject

Returns the http verb concatenated with the url



52
53
54
# File 'lib/kanpachi/resource.rb', line 52

def route
  "#{@http_verb.to_s.upcase} #{@url}"
end