Class: Kanpachi::Resource
- Inherits:
-
Object
- Object
- Kanpachi::Resource
- Defined in:
- lib/kanpachi/resource.rb,
lib/kanpachi/resource/params.rb
Overview
The Resource class
Defined Under Namespace
Classes: Params
Instance Attribute Summary collapse
- #authentication ⇒ Object
- #description ⇒ Object
- #formats ⇒ Object readonly
- #http_verb ⇒ Object readonly
- #name ⇒ Object
- #params ⇒ Object
- #priority ⇒ Object
- #responses ⇒ Object readonly
- #ssl ⇒ Object
- #url ⇒ Object readonly
- #versions ⇒ Object readonly
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compare two resources using the priority.
-
#initialize(http_verb, url) ⇒ Resource
constructor
Resource constructor.
-
#params? ⇒ Boolean
Returns true if the resource has defined any params.
-
#route ⇒ Object
Returns the http verb concatenated with the url.
Constructor Details
#initialize(http_verb, url) ⇒ Resource
Resource constructor
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
#authentication ⇒ Object
20 21 22 |
# File 'lib/kanpachi/resource.rb', line 20 def authentication @authentication end |
#description ⇒ Object
17 18 19 |
# File 'lib/kanpachi/resource.rb', line 17 def description @description end |
#formats ⇒ Object (readonly)
12 13 14 |
# File 'lib/kanpachi/resource.rb', line 12 def formats @formats end |
#http_verb ⇒ Object (readonly)
10 11 12 |
# File 'lib/kanpachi/resource.rb', line 10 def http_verb @http_verb end |
#name ⇒ Object
16 17 18 |
# File 'lib/kanpachi/resource.rb', line 16 def name @name end |
#params ⇒ Object
15 16 17 |
# File 'lib/kanpachi/resource.rb', line 15 def params @params end |
#priority ⇒ Object
18 19 20 |
# File 'lib/kanpachi/resource.rb', line 18 def priority @priority end |
#responses ⇒ Object (readonly)
14 15 16 |
# File 'lib/kanpachi/resource.rb', line 14 def responses @responses end |
#ssl ⇒ Object
19 20 21 |
# File 'lib/kanpachi/resource.rb', line 19 def ssl @ssl end |
#url ⇒ Object (readonly)
11 12 13 |
# File 'lib/kanpachi/resource.rb', line 11 def url @url end |
#versions ⇒ Object (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.
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 |
#route ⇒ Object
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 |