Class: Qa::AuthorityWrapper
- Inherits:
-
Object
- Object
- Qa::AuthorityWrapper
show all
- Defined in:
- lib/qa/authority_wrapper.rb
Overview
The intention of this wrapper is to provide a common interface that both linked and non-linked data can use. There are implementation differences between the two, but with this wrapper, the goal is to draw attention to those differences and insulate the end user from those issues.
One benefit in introducing this class is that when interacting with a questioning authority implementation you don’t need to consider “Hey when I instantiate an authority, is this linked data or not?” And what specifically are the parameter differences. You will need to perhaps include some additional values in the context if you don’t call this from a controller.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(authority:, subauthority:, context:) ⇒ AuthorityWrapper
Returns a new instance of AuthorityWrapper.
18
19
20
21
22
23
|
# File 'lib/qa/authority_wrapper.rb', line 18
def initialize(authority:, subauthority:, context:)
@authority = authority
@subauthority = subauthority
@context = context
configure!
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
51
52
53
|
# File 'lib/qa/authority_wrapper.rb', line 51
def method_missing(method_name, *arguments, &block)
authority.send(method_name, *arguments, &block)
end
|
Instance Attribute Details
#authority ⇒ Object
24
25
26
|
# File 'lib/qa/authority_wrapper.rb', line 24
def authority
@authority
end
|
#context ⇒ Object
24
25
26
|
# File 'lib/qa/authority_wrapper.rb', line 24
def context
@context
end
|
#subauthority ⇒ Object
24
25
26
|
# File 'lib/qa/authority_wrapper.rb', line 24
def subauthority
@subauthority
end
|
Instance Method Details
59
60
61
|
# File 'lib/qa/authority_wrapper.rb', line 59
def configure!
@context.subauthority = @subauthority if @context.respond_to?(:subauthority)
end
|
#find(value) ⇒ Object
Also known as:
fetch
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/qa/authority_wrapper.rb', line 39
def find(value)
if linked_data?
authority.find(value, request_header: context.)
elsif authority.method(:find).arity == 2
authority.find(value, context)
else
authority.find(value)
end
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
55
56
57
|
# File 'lib/qa/authority_wrapper.rb', line 55
def respond_to_missing?(method_name, include_private = false)
authority.respond_to?(method_name, include_private)
end
|
#search(value) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/qa/authority_wrapper.rb', line 26
def search(value)
if linked_data?
authority.search(value, request_header: context.)
elsif authority.method(:search).arity == 2
authority.search(value, context)
else
authority.search(value)
end
end
|