class GeolocationService::Services::BaseService

Public Class Methods

call(**args) click to toggle source
# File lib/geolocation_service/services/base_service.rb, line 7
def self.call(**args)
  validate(contract, args).bind do |contract|
    Try() do
      self.new(**contract.to_h).call
    end.to_result
  end
end
contract() click to toggle source
# File lib/geolocation_service/services/base_service.rb, line 23
def self.contract
  unless defined?(self::Contract)
    raise NotImplementedError.new("#{self.class.name} - doesnt have Contract")
  end

  self::Contract.new
end
validate(contract, args) click to toggle source
# File lib/geolocation_service/services/base_service.rb, line 15
def self.validate(contract, args)
  raise ArgumentError.new("missing contract or args") if contract.nil? || args.nil?

  contract.call(args.to_h).to_monad
rescue => e
  Dry::Monads::Failure(e)
end

Public Instance Methods

call() click to toggle source
# File lib/geolocation_service/services/base_service.rb, line 31
def call
  raise NotImplementedError
end