Class: SolidusGraphqlApi::Context
- Inherits:
-
Object
- Object
- SolidusGraphqlApi::Context
- Defined in:
- lib/solidus_graphql_api/context.rb
Constant Summary collapse
- AUTHORIZATION_HEADER =
"Authorization"
- TOKEN_PATTERN =
/^Bearer (?<token>.*)/
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #current_ability ⇒ Object
- #current_order ⇒ Object
- #current_pricing_options ⇒ Object
- #current_store ⇒ Object
- #current_user ⇒ Object
-
#initialize(request:) ⇒ Context
constructor
A new instance of Context.
- #order_token ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(request:) ⇒ Context
Returns a new instance of Context.
10 11 12 13 |
# File 'lib/solidus_graphql_api/context.rb', line 10 def initialize(request:) @request = request @headers = request.headers end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
8 9 10 |
# File 'lib/solidus_graphql_api/context.rb', line 8 def headers @headers end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
8 9 10 |
# File 'lib/solidus_graphql_api/context.rb', line 8 def request @request end |
Instance Method Details
#current_ability ⇒ Object
32 33 34 |
# File 'lib/solidus_graphql_api/context.rb', line 32 def current_ability @current_ability ||= Spree::Ability.new(current_user) end |
#current_order ⇒ Object
44 45 46 47 48 |
# File 'lib/solidus_graphql_api/context.rb', line 44 def current_order return @current_order if instance_variable_defined?(:@current_order) @current_order = current_order_by_current_user || current_order_by_guest_token end |
#current_pricing_options ⇒ Object
50 51 52 |
# File 'lib/solidus_graphql_api/context.rb', line 50 def @current_pricing_options ||= end |
#current_store ⇒ Object
40 41 42 |
# File 'lib/solidus_graphql_api/context.rb', line 40 def current_store @current_store ||= Spree::Config.current_store_selector_class.new(request).store end |
#current_user ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/solidus_graphql_api/context.rb', line 24 def current_user @current_user ||= begin return nil if bearer_token.blank? Spree.user_class.find_by(spree_api_key: bearer_token) end end |
#order_token ⇒ Object
36 37 38 |
# File 'lib/solidus_graphql_api/context.rb', line 36 def order_token @order_token ||= headers["X-Spree-Order-Token"] end |
#to_h ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/solidus_graphql_api/context.rb', line 15 def to_h { current_user: current_user, current_ability: current_ability, current_store: current_store, current_order: current_order, current_pricing_options: , order_token: order_token } end |