Class: BooticClient::Relation
- Inherits:
-
Object
- Object
- BooticClient::Relation
- Defined in:
- lib/bootic_client/relation.rb
Constant Summary collapse
- GET =
'get'.freeze
- HEAD =
'head'.freeze
- OPTIONS =
'options'.freeze
Class Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #docs ⇒ Object
- #href ⇒ Object
-
#initialize(attrs, client, complain_on_undeclared_params: self.class.complain_on_undeclared_params) ⇒ Relation
constructor
A new instance of Relation.
- #inspect ⇒ Object
- #name ⇒ Object
- #parameters ⇒ Object
- #run(opts = {}) ⇒ Object
- #templated? ⇒ Boolean
- #title ⇒ Object
- #to_hash ⇒ Object
- #transport_method ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(attrs, client, complain_on_undeclared_params: self.class.complain_on_undeclared_params) ⇒ Relation
Returns a new instance of Relation.
21 22 23 24 |
# File 'lib/bootic_client/relation.rb', line 21 def initialize(attrs, client, complain_on_undeclared_params: self.class.complain_on_undeclared_params) @attrs, @client = attrs, client @complain_on_undeclared_params = complain_on_undeclared_params end |
Class Attribute Details
.complain_on_undeclared_params ⇒ Object
15 16 17 18 |
# File 'lib/bootic_client/relation.rb', line 15 def complain_on_undeclared_params return true unless instance_variable_defined?('@complain_on_undeclared_params') @complain_on_undeclared_params end |
Class Method Details
Instance Method Details
#docs ⇒ Object
54 55 56 |
# File 'lib/bootic_client/relation.rb', line 54 def docs attrs['docs'] end |
#href ⇒ Object
30 31 32 |
# File 'lib/bootic_client/relation.rb', line 30 def href attrs['href'] end |
#inspect ⇒ Object
26 27 28 |
# File 'lib/bootic_client/relation.rb', line 26 def inspect %(#<#{self.class.name} #{attrs.inspect}>) end |
#name ⇒ Object
42 43 44 |
# File 'lib/bootic_client/relation.rb', line 42 def name attrs['name'] end |
#parameters ⇒ Object
38 39 40 |
# File 'lib/bootic_client/relation.rb', line 38 def parameters @parameters ||= templated? ? uri.variables : [] end |
#run(opts = {}) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/bootic_client/relation.rb', line 66 def run(opts = {}) if templated? uri_vars = uri.variables payload = opts.each_with_object({}) do |(k,v),memo| memo[k] = v unless uri_vars.include?(k.to_s) end # remove payload vars from URI opts if destructive action opts = opts.reject{|k, v| !uri_vars.include?(k.to_s) } if destructive? client.request_and_wrap transport_method.to_sym, uri.(opts), payload else client.request_and_wrap transport_method.to_sym, href, opts end end |
#templated? ⇒ Boolean
34 35 36 |
# File 'lib/bootic_client/relation.rb', line 34 def templated? !!attrs['templated'] end |
#title ⇒ Object
46 47 48 |
# File 'lib/bootic_client/relation.rb', line 46 def title attrs['title'] end |
#to_hash ⇒ Object
58 59 60 |
# File 'lib/bootic_client/relation.rb', line 58 def to_hash attrs end |
#transport_method ⇒ Object
62 63 64 |
# File 'lib/bootic_client/relation.rb', line 62 def transport_method @transport_method ||= attrs.key?('method') ? attrs['method'].to_s.downcase : GET end |
#type ⇒ Object
50 51 52 |
# File 'lib/bootic_client/relation.rb', line 50 def type attrs['type'] end |