rename qwaiter to mozo

This commit is contained in:
2025-09-20 17:35:58 -05:00
parent 7212d9041e
commit 0e051b1f93
99 changed files with 189 additions and 168 deletions
+6
View File
@@ -0,0 +1,6 @@
module Mozo
module Broadcaster
extend ActiveSupport::Autoload
autoload :Faye
end
end
+12
View File
@@ -0,0 +1,12 @@
module Mozo
module Broadcaster
class Faye
def broadcast(message)
@uri ||= URI.parse(Mozo.event_host)
Net::HTTP.post_form(@uri, message: message.merge(ext: {auth_token: '6be65f9b5e7d21b8ca8de4ccfad5ba24cf40d440b370af79'}).to_json)
rescue => e
Rails.logger.error("[FAYE][ERROR] #{e.message}")
end
end
end
end
+24
View File
@@ -0,0 +1,24 @@
module Mozo
module Couchbase
def self.connection
$cb
end
def self.load_design_docs!
return unless connection.present?
Dir.glob(Rails.root.join('config/couchbase/design_docs', "*.json")).each do |design_doc|
connection.save_design_doc File.open(design_doc)
end
end
def self.design_doc(name)
return unless connection.present?
connection.design_docs[name]
end
def self.flush_counters!
return unless connection.present?
design_doc('supplier').counters(reduce: false).each{|counter| Mozo::Counter.set counter.key, 0}
end
end
end
+24
View File
@@ -0,0 +1,24 @@
module Mozo
module Counter
mattr_accessor :connection
# mainly for testing purposes
def self.set(key, value)
connection.set(key, value) rescue value
end
def self.get(key)
connection.get(key, quiet: true).to_i rescue 0
end
def self.incr(key, options = {})
options[:initial] ||= 1
connection.incr(key, options) rescue 1
end
def self.decr(key, options = {})
options[:initial] ||= 0
connection.decr(key, options) rescue 0
end
end
end
+47
View File
@@ -0,0 +1,47 @@
module Mozo
module Distribution
module DistributionMethods
def epsilon
@@epsilon ||= (10 ** -(Float::DIG - 1)).to_f
end
##
# Distribute a section of width w and height h in a length and a width scale
# that makes n tables fit.
# distribute_lattice 10, 10, 3 #=> [5.0, 5.0]
# distribute_lattice 10, 10, 4 #=> [5.0, 5.0]
##
def distribute_lattice(w, h, n)
w, h = w.to_f, h.to_f
area = w*h
l = Math.sqrt(area.to_f/n)
nx = w/l
ny = h/l
while (w/l + epsilon).floor * (h/l + epsilon).floor < n
tx = w/l
ty = h/l
# The biggest remainder is closest to a fitting option
# Just add one if no remainder wins and it still is not enough
if tx.remainder(1) < epsilon && ty.remainder(1) < epsilon
# Both divide, but there is no solution yet. Just add one
l = [w/(tx + 1).round, h/(ty + 1).round].max
nx = tx.ceil
ny = ny.ceil
elsif tx.remainder(1) > ty.remainder(1)
nx = tx.ceil
ny = (n.to_f/nx).ceil
l = w/nx
else
ny = ty.ceil
nx = (n.to_f/ny).ceil
l = h/ny
end
end
[w/nx, h/ny]
end
end
include DistributionMethods
extend DistributionMethods
end
end
+8
View File
@@ -0,0 +1,8 @@
module Mozo
module DrbCounter
def self.object
require 'drb'
DRbObject.new_with_uri('druby://localhost:9022')
end
end
end
+44
View File
@@ -0,0 +1,44 @@
module Mozo::EmployeeBaseSerializer
extend ActiveSupport::Concern
include JSONAPI::Serializer
included do
class_attribute :related_link_for_attributes
attribute :created_at
attribute :updated_at
end
def base_url
nil
end
#def format_name(attribute_name)
# #attribute_name.to_s.dasherize
# attribute_name.to_s
#end
#def unformat_name(attribute_name)
# #attribute_name.to_s.underscore
# attribute_name.to_s
#end
#alias_method :default_relationship_related_link, :relationship_related_link
def relationship_related_link(attribute_name)
super if related_link_for_attributes.include?(attribute_name)
nil
end
def relationship_self_link(attribute_name)
end
module ClassMethods
def attributes(*attrs)
attrs.each do |attr|
attribute attr
end
end
def related_link_for(*attributes)
self.related_link_for_attributes = attributes
end
end
end
+48
View File
@@ -0,0 +1,48 @@
=begin
module Mozo
class Serializer < ActiveModel::Serializer
def self.root=(val)
ActiveSupport::Deprecation.new('1.0', 'Mozo')
end
def self.root(val)
ActiveSupport::Deprecation.new('1.0', 'Mozo')
end
# attribute :_id, key: :id
attributes :id, :created_at, :updated_at
# Bug in rails 4.1 serializing symbols in jsonify
#def to_json(*args)
#as_json.to_json(*args)
#end
#def id
#object._id
#end
def created_at
timestamp_attribute :created_at
end
def updated_at
timestamp_attribute :updated_at
end
private
def timestamp_attribute(attr)
timestamp = object.send(attr)
return nil unless timestamp
timestamp.iso8601
end
end
end
=end
# require 'active_model/array_serializer'
# module ActiveModel
# class ArraySerializer
# # Bug in rails 4.1 serializing symbols in jsonify
# def to_json(*args)
# as_json.to_json(*args)
# end
# end
# end
+49
View File
@@ -0,0 +1,49 @@
module Mozo::SupplierBaseSerializer
extend ActiveSupport::Concern
include JSONAPI::Serializer
included do
class_attribute :related_link_for_attributes
timestamp_attribute :created_at
timestamp_attribute :updated_at
end
def base_url
"/supplier/api/v1" # no api here, should be, but result from refacoring in steps, future update
end
#def format_name(attribute_name)
# attribute_name.to_s.dasherize
#end
#def unformat_name(attribute_name)
# attribute_name.to_s.underscore
#end
#alias_method :default_relationship_related_link, :relationship_related_link
def relationship_related_link(attribute_name)
return super if related_link_for_attributes.include?(attribute_name)
nil
end
def relationship_self_link(attribute_name)
end
module ClassMethods
def attributes(*attrs)
attrs.each do |attr|
attribute attr
end
end
def timestamp_attribute(attr)
attribute attr do
object.public_send(attr).try(:iso8601)
end
end
def related_link_for(*attributes)
self.related_link_for_attributes = attributes
end
end
end
+44
View File
@@ -0,0 +1,44 @@
module Mozo::UserBaseSerializer
extend ActiveSupport::Concern
include JSONAPI::Serializer
included do
class_attribute :related_link_for_attributes
attribute :created_at
attribute :updated_at
end
def base_url
"/user/api/v1"
end
def format_name(attribute_name)
#attribute_name.to_s.dasherize
attribute_name.to_s
end
def unformat_name(attribute_name)
#attribute_name.to_s.underscore
attribute_name.to_s
end
#alias_method :default_relationship_related_link, :relationship_related_link
def relationship_related_link(attribute_name)
return super if related_link_for_attributes.include?(attribute_name)
nil
end
def relationship_self_link(attribute_name)
end
module ClassMethods
def attributes(*attrs)
attrs.each do |attr|
attribute attr
end
end
def related_link_for(*attributes)
self.related_link_for_attributes = attributes
end
end
end
+50
View File
@@ -0,0 +1,50 @@
module Mozo::WaiterBaseSerializer
extend ActiveSupport::Concern
include JSONAPI::Serializer
included do
class_attribute :related_link_for_attributes
timestamp_attribute :created_at
timestamp_attribute :updated_at
end
def base_url
nil
end
def format_name(attribute_name)
attribute_name.to_s.dasherize
end
def unformat_name(attribute_name)
attribute_name.to_s.underscore
end
#alias_method :default_relationship_related_link, :relationship_related_link
def relationship_related_link(attribute_name)
#super if related_link_for_attributes.include?(attribute_name)
super
end
def relationship_self_link(attribute_name)
end
module ClassMethods
def attributes(*attrs)
attrs.each do |attr|
attribute attr
end
end
def timestamp_attribute(attr)
attribute attr do
return unless timestamp = object.public_send(attr)
timestamp.iso8601
end
end
def related_link_for(*attributes)
self.related_link_for_attributes = attributes
end
end
end