This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support/all' | |
module UnderwritingService | |
extend self | |
PolicyMeta = Struct.new(:product_type, :public_id, :status) | |
def policies_metas(user_id:) | |
UserPoliciesRegistry.all.flat_map do |provider| | |
provider.of_user(user_id:user_id).map { |policy| | |
PolicyMeta.new(provider.product_type, provider.public_id(policy), provider.status(policy)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
require "rspec/mocks/standalone" #spec/helpers.rb spec/helpers.rb:1 - without this line rspec prevents us from using mocks in context | |
class Box | |
attr_reader :color | |
def initialize | |
@color = Color.new | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JobListItem | |
include Mongoid::Document | |
include Mongoid::Timestamps::Created | |
belongs_to :next_job, :class_name => "JobListItem", :inverse_of => :prev_job, optional: true | |
has_one :prev_job, :class_name => "JobListItem", :inverse_of => :next_job | |
NONE=0 | |
RUNNING = 1 | |
FINISHED = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def execute_awaited | |
fiber = Fiber.current | |
execute # run some non blocking code (return immidiatly) | |
self.callback do |response| | |
EventMachine.schedule do | |
fiber.resume response | |
end | |
end | |
self.errback do |err| | |
EventMachine.schedule do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InProcessJob | |
unless Rails.env.test? | |
include SuckerPunch::Job | |
workers 1 | |
end | |
include Job::Deserializers | |
include Job::Serializers | |
def self.queue_as(_) | |
end |