Class: CloverSandboxSimulator::Services::Clover::ServicesManager
- Inherits:
-
Object
- Object
- CloverSandboxSimulator::Services::Clover::ServicesManager
- Defined in:
- lib/clover_sandbox_simulator/services/clover/services_manager.rb
Overview
Central manager for all Clover services Provides thread-safe, lazy-loaded access to all service classes
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #cash_event ⇒ Object
-
#clear_services ⇒ Object
Clear all cached service instances.
- #customer ⇒ Object
- #discount ⇒ Object
- #ecommerce ⇒ Object
-
#ecommerce_available? ⇒ Boolean
Check if Ecommerce API is available.
- #employee ⇒ Object
- #gift_card ⇒ Object
-
#initialize(config: nil) ⇒ ServicesManager
constructor
A new instance of ServicesManager.
- #inventory ⇒ Object
- #oauth ⇒ Object
-
#oauth_available? ⇒ Boolean
Check if OAuth is configured.
- #order ⇒ Object
- #order_type ⇒ Object
- #payment ⇒ Object
- #refund ⇒ Object
- #service_charge ⇒ Object
- #shift ⇒ Object
- #tax ⇒ Object
- #tender ⇒ Object
-
#token_expired? ⇒ Boolean
Check if current token is expired.
Constructor Details
#initialize(config: nil) ⇒ ServicesManager
Returns a new instance of ServicesManager.
11 12 13 14 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 11 def initialize(config: nil) @config = config || CloverSandboxSimulator.configuration @mutex = Mutex.new end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 9 def config @config end |
Instance Method Details
#cash_event ⇒ Object
76 77 78 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 76 def cash_event thread_safe_memoize(:@cash_event) { CashEventService.new(config: config) } end |
#clear_services ⇒ Object
Clear all cached service instances
96 97 98 99 100 101 102 103 104 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 96 def clear_services @mutex.synchronize do instance_variables.each do |var| next if var == :@config || var == :@mutex instance_variable_set(var, nil) end end end |
#customer ⇒ Object
44 45 46 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 44 def customer thread_safe_memoize(:@customer) { CustomerService.new(config: config) } end |
#discount ⇒ Object
28 29 30 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 28 def discount thread_safe_memoize(:@discount) { DiscountService.new(config: config) } end |
#ecommerce ⇒ Object
56 57 58 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 56 def ecommerce thread_safe_memoize(:@ecommerce) { EcommerceService.new(config: config) } end |
#ecommerce_available? ⇒ Boolean
Check if Ecommerce API is available
81 82 83 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 81 def ecommerce_available? config.ecommerce_enabled? end |
#employee ⇒ Object
40 41 42 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 40 def employee thread_safe_memoize(:@employee) { EmployeeService.new(config: config) } end |
#gift_card ⇒ Object
52 53 54 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 52 def gift_card thread_safe_memoize(:@gift_card) { GiftCardService.new(config: config) } end |
#inventory ⇒ Object
16 17 18 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 16 def inventory thread_safe_memoize(:@inventory) { InventoryService.new(config: config) } end |
#oauth ⇒ Object
60 61 62 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 60 def oauth thread_safe_memoize(:@oauth) { OauthService.new(config: config) } end |
#oauth_available? ⇒ Boolean
Check if OAuth is configured
86 87 88 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 86 def oauth_available? oauth.oauth_configured? end |
#order ⇒ Object
32 33 34 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 32 def order thread_safe_memoize(:@order) { OrderService.new(config: config) } end |
#order_type ⇒ Object
72 73 74 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 72 def order_type thread_safe_memoize(:@order_type) { OrderTypeService.new(config: config) } end |
#payment ⇒ Object
36 37 38 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 36 def payment thread_safe_memoize(:@payment) { PaymentService.new(config: config) } end |
#refund ⇒ Object
48 49 50 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 48 def refund thread_safe_memoize(:@refund) { RefundService.new(config: config) } end |
#service_charge ⇒ Object
64 65 66 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 64 def service_charge thread_safe_memoize(:@service_charge) { ServiceChargeService.new(config: config) } end |
#shift ⇒ Object
68 69 70 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 68 def shift thread_safe_memoize(:@shift) { ShiftService.new(config: config) } end |
#tax ⇒ Object
24 25 26 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 24 def tax thread_safe_memoize(:@tax) { TaxService.new(config: config) } end |
#tender ⇒ Object
20 21 22 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 20 def tender thread_safe_memoize(:@tender) { TenderService.new(config: config) } end |
#token_expired? ⇒ Boolean
Check if current token is expired
91 92 93 |
# File 'lib/clover_sandbox_simulator/services/clover/services_manager.rb', line 91 def token_expired? oauth.token_expired? end |