source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/adaptable.rb | Ruby | mit | 87 | master | 1,015 | module Hipbot
module Adaptable
extend ActiveSupport::Concern
included do
extend ClassMethods
Hipbot.adapters.unshift(self)
end
module ClassMethods
attr_reader :options
def inherited child
Hipbot.adapters.unshift(child)
end
def add_config_options *keys
... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/bot.rb | Ruby | mit | 87 | master | 1,240 | require "singleton"
module Hipbot
class << self
attr_accessor :bot, :plugins, :adapters
delegate :name, to: :bot
def plugins
@plugins ||= []
end
def adapters
@adapters ||= []
end
def method_missing name, *params, &block
bot.send(name, *params, &block)
end
end
... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/matchable.rb | Ruby | mit | 87 | master | 1,276 | module Hipbot
module Matchable
def react sender, room, body
message = Message.new(body, room, sender)
matches = set_matches(reaction_sets, message)
Match.invoke_all(matches)
end
def react_to_presence sender, status, room
presence = Presence.new(sender, status, room)
matches ... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/user.rb | Ruby | mit | 87 | master | 353 | module Hipbot
class User
def send_message message
Hipbot.send_to_user self, message
end
def mention
attributes[:mention] || name.gsub(/\s+/, '')
end
def first_name
name.split.first
end
def myself?
self == Hipbot.user
end
def guest?
attributes[:role... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/adapter.rb | Ruby | mit | 87 | master | 1,928 | module Hipbot
module Adapter
attr_accessor :connection
def start!
logger.info("STARTING")
self.connection = adapter.new
connection.start!
set_presence(status)
join_rooms(join)
end
def restart!
logger.info("RESTARTING")
leave_all_rooms
connection.restar... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/reaction.rb | Ruby | mit | 87 | master | 1,458 | module Hipbot
class Reaction < Struct.new(:plugin, :options, :block)
include Cache
def in_any_room?
options[:room] == true
end
def to_anything?
regexps.empty?
end
def from_anywhere?
options[:room].nil?
end
def condition
options[:if] || Proc.new{ true }
e... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/helpers/http.rb | Ruby | mit | 87 | master | 1,582 | # encoding: utf-8
module Hipbot
module Http
class Request < Struct.new(:url, :params, :method)
DEFAULT_HEADERS = { 'accept-encoding' => 'gzip, compressed' }.freeze
CONNECTION_SETTINGS = { connect_timeout: 5, inactivity_timeout: 10 }.freeze
ERROR_CALLBACK = ->(error){ Hipbot.logger.error... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/callbacks/base.rb | Ruby | mit | 87 | master | 779 | module Hipbot
module Callbacks
class Base
protected
def with_room params
yield Room.find_or_create_by(params) if valid_params?(params)
end
def with_user params
yield User.find_or_create_by(params) if valid_params?(params)
end
def with_user_by_name_or_mention ... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/callbacks/lobby_presence.rb | Ruby | mit | 87 | master | 353 | module Hipbot
module Callbacks
class LobbyPresence < Presence
def initialize user_id, presence
self.presence = presence
with_user(id: user_id) do |user|
Hipbot.logger.info("PRESENCE from #{user}: #{presence}")
user.update_attribute(:is_online, !offline_presence?)
... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/callbacks/room_invite.rb | Ruby | mit | 87 | master | 291 | module Hipbot
module Callbacks
class RoomInvite < Base
def initialize room_id, room_name
return unless Hipbot.configuration.join_on_invite
with_room(id: room_id, name: room_name) do |room|
Hipbot.join_room(room)
end
end
end
end
end |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/callbacks/private_message.rb | Ruby | mit | 87 | master | 296 | module Hipbot
module Callbacks
class PrivateMessage < Message
def initialize user_id, message_body
with_user(id: user_id) do |user|
return if ignore_message?(user, message_body)
Hipbot.react(user, nil, message_body)
end
end
end
end
end |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/callbacks/room_presence.rb | Ruby | mit | 87 | master | 925 | module Hipbot
module Callbacks
class RoomPresence < Presence
attr_accessor :room_id, :user_name_or_mention
def initialize room_id, user_name_or_mention, presence, role
self.room_id = room_id
self.user_name_or_mention = user_name_or_mention
self.presence = presence
han... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/callbacks/room_message.rb | Ruby | mit | 87 | master | 406 | module Hipbot
module Callbacks
class RoomMessage < Message
def initialize room_id, user_name_or_mention, message_body
with_room(id: room_id) do |room|
with_user_by_name_or_mention(user_name_or_mention) do |user|
return if ignore_message?(user, message_body)
Hipbot.... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/callbacks/room_topic.rb | Ruby | mit | 87 | master | 384 | module Hipbot
module Callbacks
class RoomTopic < Message
def initialize room_id, topic
with_room(id: room_id) do |room|
Hipbot.logger.info("TOPIC in ##{room}: #{topic}")
update_topic(room, topic)
end
end
protected
def update_topic room, topic
r... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/patches/encoding.rb | Ruby | mit | 87 | master | 380 | require 'socket'
class TCPSocket
def external_encoding
Encoding::BINARY
end
end
require 'rexml/source'
class REXML::IOSource
alias_method :encoding_assign, :encoding=
def encoding=(value)
encoding_assign(value) if value
end
end
begin
require 'openssl'
class OpenSSL::SSL::SSLSocket
def extern... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/storages/mongoid.rb | Ruby | mit | 87 | master | 315 | module Hipbot
module Storages
module Mongoid
extend ActiveSupport::Concern
included do
include ::Mongoid::Document
field :_id, type: String
field :name, type: String
alias_method :to_s, :name
validates :name, presence: true
end
end
end
end |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/storages/base.rb | Ruby | mit | 87 | master | 1,418 | module Hipbot
module Storages
module Base
extend ActiveSupport::Concern
included do
extend ClassMethods
alias_method :to_s, :name
end
def initialize attributes
raise NotImplementedError
end
def attributes
raise NotImplementedError
end
... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/storages/hash.rb | Ruby | mit | 87 | master | 1,716 | module Hipbot
module Storages
module Hash
extend ActiveSupport::Concern
included do
extend ClassMethods
attr_accessor :attributes
alias_method :to_s, :name
end
def initialize params = {}
self.attributes = params.with_indifferent_access
end
de... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/adapters/xmpp.rb | Ruby | mit | 87 | master | 1,173 | require 'hipbot/adapters/xmpp/client'
module Hipbot
module Adapters
class XMPP
include Hipbot::Adaptable
add_config_options :jid, :conference_host
attr_accessor :client
def start!
self.client = self.class::Client.new.client
end
def restart!
start!
end... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/adapters/shell.rb | Ruby | mit | 87 | master | 581 | module Hipbot
module Adapters
class Shell
include Hipbot::Adaptable
attr_accessor :connection
def start!
EM.open_keyboard(KeyboardHandler, self)
end
module KeyboardHandler
include EM::Protocols::LineText2
include Cache
def initialize adapter
... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/adapters/telnet.rb | Ruby | mit | 87 | master | 704 | module Hipbot
module Adapters
class Telnet
include Hipbot::Adaptable
attr_accessor :connection
def start!
::EM::start_server('0.0.0.0', 3001, Connection, self)
end
def send_to_user user, message
connection.send_data("#{self}:#{user}:#{message}\n")
end
... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/adapters/slack/client.rb | Ruby | mit | 87 | master | 1,329 | require "slack"
module Hipbot
module Adapters
class Slack < XMPP
class Client < XMPP::Client
def initialize
::Slack.configure do |config|
config.token = Hipbot.configuration.slack_api_token
end
super
end
protected
def initialize_ro... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/adapters/xmpp/client.rb | Ruby | mit | 87 | master | 3,169 | require 'xmpp4r-hipchat'
module Hipbot
module Adapters
class XMPP
class Client
attr_accessor :client
KEEP_ALIVE_INTERVAL = 60
def initialize
initialize_logger
Hipbot.logger.info("INITIALIZE XMPP Client")
initialize_client do
Hipbot.logger... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | lib/hipbot/utilities/cache.rb | Ruby | mit | 87 | master | 432 | module Hipbot
module Cache
extend ActiveSupport::Concern
included do
extend ClassMethods
end
def _cache
@_cache ||= {}
end
module ClassMethods
def attr_cache *attributes, &block
attributes.each do |attr_name|
define_method(attr_name) do
_cache... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | spec/spec_helper.rb | Ruby | mit | 87 | master | 325 | require 'rspec/its'
require_relative '../lib/hipbot'
begin
require 'coveralls'
Coveralls.wear!
rescue LoadError
end
RSpec.configure do |config|
config.mock_with :rspec
config.before(:all) do
Hipbot::User.send(:include, Hipbot::Storages::Hash)
Hipbot::Room.send(:include, Hipbot::Storages::Hash)
end... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | spec/integration/my_hipbot.rb | Ruby | mit | 87 | master | 2,664 | module HipbotHelpers
def project_name
"Project: #{room.name}"
end
def sender_first_name
"you are #{message.sender.split[0]}"
end
end
class AwesomePlugin
include Hipbot::Plugin
desc 'respond awesome - responds with awesome'
on /respond awesome/ do
reply('awesome responded')
end
def meth... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | spec/integration/my_hipbot_spec.rb | Ruby | mit | 87 | master | 6,191 | require 'spec_helper'
require_relative './my_hipbot'
describe MyHipbot do
before(:all) { MyHipbot.instance.setup }
subject { MyHipbot.instance }
let(:room) { Hipbot::Room.create(id: '1', name: 'Project 1', topic: 'project 1 stuff only') }
let(:sender) { Hipbot::User.create(id: '1', name: 'John Doe') }
let... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | spec/unit/message_spec.rb | Ruby | mit | 87 | master | 1,986 | require 'spec_helper'
describe Hipbot::Message do
subject { Hipbot::Message }
let(:sender) { double }
let(:room) { double }
before(:all) do
Hipbot::Bot.instance.setup
end
before do
Hipbot.configuration.user.stub(mention: 'dave')
end
after do
Hipbot.configuration.user.unstub(:mention)
e... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | spec/unit/match_spec.rb | Ruby | mit | 87 | master | 3,660 | require 'spec_helper'
describe Hipbot::Match do
subject { described_class.new(reaction, message) }
let(:message) { double(for?: true, body: 'test message', private?: false) }
let(:reaction) do
double(
global?: false,
from_anywhere?: true,
to_anything?: false,
from_all?: true,
r... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | spec/unit/matchable_spec.rb | Ruby | mit | 87 | master | 445 | require 'spec_helper'
describe Hipbot::Matchable do
include Hipbot::Matchable
before(:all) do
Hipbot::Bot.instance.setup
end
let(:sender) { Hipbot::User.new(name: 'test user') }
let(:room) { Hipbot::Room.new(name: 'test room') }
def plugins
[]
end
describe '#react' do
it 'calls #invoke_... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | spec/unit/reaction_spec.rb | Ruby | mit | 87 | master | 2,764 | require 'spec_helper'
describe Hipbot::Reaction do
subject { Hipbot::Reaction }
before(:each) do
Hipbot::Bot.instance.setup
end
context 'instance' do
let(:options){ {} }
let(:reaction){ subject.new(@plugin, options, @block) }
it '#in_any_room?' do
reaction.in_any_room?.should be_falsy
... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | spec/unit/reaction_factory_spec.rb | Ruby | mit | 87 | master | 1,475 | require 'spec_helper'
describe Hipbot::ReactionFactory do
subject { described_class.new(double) }
before(:each) do
Hipbot::Bot.instance.setup
end
let(:params) { [] }
let(:block) { double }
let(:options_stack) { [subject.get_reaction_options(params)] }
let(:reaction) { subject.build(options_stack, ... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | spec/unit/user_spec.rb | Ruby | mit | 87 | master | 399 | require 'spec_helper'
describe Hipbot::User do
subject { described_class.new(id: '1234', name: 'test bot', mention: 'testbotmention') }
its(:first_name) { should == 'test' }
its(:mention) { should == 'testbotmention' }
describe "when no mention is provided" do
subject { described_class.new(id: '1234', na... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | spec/unit/bot_spec.rb | Ruby | mit | 87 | master | 8,970 | require 'spec_helper'
describe "a class that inherits", Hipbot::Bot do
let(:described_class) { Class.new(Hipbot::Bot) }
before(:each) do
described_class.instance.plugins.clear
described_class.instance.setup
end
subject { described_class.instance }
let(:room) { Hipbot::Room.new(name: 'Test Room') }
... |
github | pewniak747/hipbot | https://github.com/pewniak747/hipbot | spec/unit/storages/hash_spec.rb | Ruby | mit | 87 | master | 1,889 | require 'spec_helper'
describe Hipbot::Storages::Hash do
let(:collection) { Class.new{ include Hipbot::Storages::Hash } }
let(:item) { collection.find(1) }
before do
@item = collection.create(id: 1, name: 'item', something: 'value')
end
context 'collection' do
context '#create' do
it 'creates ... |
github | flyerhzm/code_analyzer | https://github.com/flyerhzm/code_analyzer | code_analyzer.gemspec | Ruby | mit | 87 | master | 967 | # frozen_string_literal: true
require File.expand_path('../lib/code_analyzer/version', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ["Richard Huang"]
gem.email = ["flyerhzm@gmail.com"]
gem.description = %q{a code analyzer tool which extracted from rails_best_practices, it helps you ea... |
github | flyerhzm/code_analyzer | https://github.com/flyerhzm/code_analyzer | lib/code_analyzer.rb | Ruby | mit | 87 | master | 380 | # frozen_string_literal: true
require 'ripper'
require 'code_analyzer/version'
require 'code_analyzer/nil'
require 'code_analyzer/sexp'
module CodeAnalyzer
autoload :AnalyzerException, 'code_analyzer/analyzer_exception'
autoload :Checker, 'code_analyzer/checker'
autoload :CheckingVisitor, 'code_analyzer/checkin... |
github | flyerhzm/code_analyzer | https://github.com/flyerhzm/code_analyzer | lib/code_analyzer/warning.rb | Ruby | mit | 87 | master | 477 | # frozen_string_literal: true
module CodeAnalyzer
# Warning is the violation.
#
# it indicates the filenname, line number and error message for the violation.
class Warning
attr_reader :filename, :line_number, :message
def initialize(options = {})
@filename = options[:filename]
@line_numbe... |
github | flyerhzm/code_analyzer | https://github.com/flyerhzm/code_analyzer | lib/code_analyzer/checking_visitor.rb | Ruby | mit | 87 | master | 268 | # frozen_string_literal: true
module CodeAnalyzer
module CheckingVisitor
autoload :Base, 'code_analyzer/checking_visitor/base'
autoload :Plain, 'code_analyzer/checking_visitor/plain'
autoload :Default, 'code_analyzer/checking_visitor/default'
end
end |
github | flyerhzm/code_analyzer | https://github.com/flyerhzm/code_analyzer | lib/code_analyzer/sexp.rb | Ruby | mit | 87 | master | 25,686 | # frozen_string_literal: true
require 'sexp'
class Sexp
# check current node.
#
# @param [CodeAnalyzer::CheckingVisitor::Default] visitor the visitor to check current node
def check(visitor)
visitor.check_node(self)
end
# return the line number of a sexp node.
#
# s(:@ident, "test", s(2, 12)
... |
github | flyerhzm/code_analyzer | https://github.com/flyerhzm/code_analyzer | lib/code_analyzer/checker.rb | Ruby | mit | 87 | master | 2,338 | # frozen_string_literal: true
module CodeAnalyzer
# A checker class that takes charge of checking the sexp.
class Checker
# interesting nodes that the check will parse.
def interesting_nodes
self.class.interesting_nodes
end
# interesting files that the check will parse.
def interesting_f... |
github | flyerhzm/code_analyzer | https://github.com/flyerhzm/code_analyzer | lib/code_analyzer/nil.rb | Ruby | mit | 87 | master | 453 | # frozen_string_literal: true
module CodeAnalyzer
# Fake nil.
class Nil
# hash_size is 0.
def hash_size
0
end
# array_size is 0.
def array_size
0
end
# return self for to_s.
def to_s
self
end
# false
def present?
false
end
# true
d... |
github | flyerhzm/code_analyzer | https://github.com/flyerhzm/code_analyzer | lib/code_analyzer/checking_visitor/plain.rb | Ruby | mit | 87 | master | 459 | # frozen_string_literal: true
module CodeAnalyzer::CheckingVisitor
# This is the checking visitor to check ruby plain code.
class Plain < Base
# check the ruby plain code.
#
# @param [String] filename is the filename of ruby code.
# @param [String] content is the content of ruby file.
def check... |
github | flyerhzm/code_analyzer | https://github.com/flyerhzm/code_analyzer | lib/code_analyzer/checking_visitor/default.rb | Ruby | mit | 87 | master | 2,032 | # frozen_string_literal: true
module CodeAnalyzer::CheckingVisitor
# This is the default checking visitor to check ruby sexp nodes.
class Default < Base
def initialize(options = {})
super
@checks = {}
@checkers.each do |checker|
checker.interesting_nodes.each do |node|
@chec... |
github | flyerhzm/code_analyzer | https://github.com/flyerhzm/code_analyzer | lib/code_analyzer/checking_visitor/base.rb | Ruby | mit | 87 | master | 312 | # frozen_string_literal: true
module CodeAnalyzer::CheckingVisitor
# Base class for checking visitor.
class Base
def initialize(options = {})
@checkers = options[:checkers]
end
def after_check; end
def warnings
@warnings ||= @checkers.map(&:warnings).flatten
end
end
end |
github | flyerhzm/code_analyzer | https://github.com/flyerhzm/code_analyzer | spec/spec_helper.rb | Ruby | mit | 87 | master | 389 | # frozen_string_literal: true
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'rspec'
require 'code_analyzer'
RSpec.configure do |config|
config.filter_run focus: true
config.run_all_when_everything_filtered = true
end
def parse_content(conte... |
github | flyerhzm/code_analyzer | https://github.com/flyerhzm/code_analyzer | spec/code_analyzer/sexp_spec.rb | Ruby | mit | 87 | master | 28,735 | # frozen_string_literal: true
require 'spec_helper'
describe Sexp do
describe 'line_number' do
before :each do
content = <<-EOF
class Demo
def test
ActiveRecord::Base.connection
end
alias :test_new :test
CONST = { foo: :bar }
def massign
a,... |
github | flyerhzm/code_analyzer | https://github.com/flyerhzm/code_analyzer | spec/code_analyzer/nil_spec.rb | Ruby | mit | 87 | master | 740 | # frozen_string_literal: true
require 'spec_helper'
module CodeAnalyzer
describe Nil do
let(:core_nil) { Nil.new }
context 'to_s' do
it 'should return self' do
expect(core_nil.to_s).to eq core_nil
end
end
context 'hash_size' do
it 'should return 0' do
expect(core_... |
github | flyerhzm/code_analyzer | https://github.com/flyerhzm/code_analyzer | spec/code_analyzer/warning_spec.rb | Ruby | mit | 87 | master | 347 | # frozen_string_literal: true
require 'spec_helper'
module CodeAnalyzer
describe Warning do
it 'should return error with filename, line number and message' do
expect(
Warning.new(filename: 'app/models/user.rb', line_number: '100', message: 'not good').to_s
).to eq 'app/models/user.rb:100 - n... |
github | flyerhzm/code_analyzer | https://github.com/flyerhzm/code_analyzer | spec/code_analyzer/checker_spec.rb | Ruby | mit | 87 | master | 2,133 | # frozen_string_literal: true
require 'spec_helper'
module CodeAnalyzer
describe Checker do
let(:checker) { Checker.new }
context 'interesting_nodes' do
it 'should get empty interesting nodes' do
expect(checker.interesting_nodes).to eq []
end
it 'should add interesting nodes' do
... |
github | flyerhzm/code_analyzer | https://github.com/flyerhzm/code_analyzer | spec/code_analyzer/checking_visitor/plain_spec.rb | Ruby | mit | 87 | master | 676 | # frozen_string_literal: true
require 'spec_helper'
module CodeAnalyzer::CheckingVisitor
describe Plain do
let(:checker1) { double(:checker) }
let(:checker2) { double(:checker) }
let(:visitor) { Plain.new(checkers: [checker1, checker2]) }
it 'should check by all checkers' do
filename = 'filen... |
github | flyerhzm/code_analyzer | https://github.com/flyerhzm/code_analyzer | spec/code_analyzer/checking_visitor/base_spec.rb | Ruby | mit | 87 | master | 496 | # frozen_string_literal: true
require 'spec_helper'
module CodeAnalyzer
module CheckingVisitor
describe Base do
it "should return all checkers' warnings" do
warning1 = Warning.new
checker1 = double(:checker, warnings: [warning1])
warning2 = Warning.new
checker2 = double(:ch... |
github | flyerhzm/code_analyzer | https://github.com/flyerhzm/code_analyzer | spec/code_analyzer/checking_visitor/default_spec.rb | Ruby | mit | 87 | master | 1,502 | # frozen_string_literal: true
require 'spec_helper'
module CodeAnalyzer::CheckingVisitor
describe Default do
let(:checker1) { double(:checker, interesting_nodes: %i[class def]) }
let(:checker2) { double(:checker, interesting_nodes: %i[def call]) }
let(:visitor) { Default.new(checkers: [checker1, checker... |
github | krisleech/wisper-sidekiq | https://github.com/krisleech/wisper-sidekiq | wisper-sidekiq.gemspec | Ruby | mit | 87 | master | 893 | # coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'wisper/sidekiq/version'
Gem::Specification.new do |spec|
spec.name = "wisper-sidekiq"
spec.version = Wisper::Sidekiq::VERSION
spec.authors = ["Kris Leech"]
spec.email... |
github | krisleech/wisper-sidekiq | https://github.com/krisleech/wisper-sidekiq | Gemfile | Ruby | mit | 87 | master | 243 | source 'https://rubygems.org'
gemspec
gem 'bundler'
gem 'rake'
gem 'rspec'
gem 'coveralls', require: false
gem 'redis', '<= 4.0.3' if RUBY_VERSION < '2.3'
gem 'psych', platforms: :rbx
group :extras do
gem 'rerun'
gem 'pry-byebug'
end |
github | krisleech/wisper-sidekiq | https://github.com/krisleech/wisper-sidekiq | spec/integration_spec.rb | Ruby | mit | 87 | master | 1,120 | require 'wisper/sidekiq'
require_relative 'dummy_app/app'
require 'sidekiq/api'
RSpec.describe 'integration tests:' do
let(:publisher) do
Class.new do
include Wisper::Publisher
def run
broadcast(:it_happened, { hello: 'world' })
end
end.new
end
let(:shared_content) { File.read... |
github | krisleech/wisper-sidekiq | https://github.com/krisleech/wisper-sidekiq | spec/spec_helper.rb | Ruby | mit | 87 | master | 830 | require 'coveralls'
require 'simplecov'
require 'pry' unless ENV['CI']
require 'sidekiq/testing'
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
SimpleCov.start { add_filter 'spec/dummy_app' }
if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
YAML::ENGINE.yamler = 'psych'
end
RSpec.configure do |config|
co... |
github | krisleech/wisper-sidekiq | https://github.com/krisleech/wisper-sidekiq | spec/configuration_spec.rb | Ruby | mit | 87 | master | 384 | require 'wisper/sidekiq'
RSpec.describe 'configuration' do
let(:configuration) { Wisper.configuration }
it 'configures sidekiq as a broadcaster' do
expect(configuration.broadcasters).to include :sidekiq
end
it 'configures sidekiq as default async broadcaster' do
expect(configuration.broadcasters[:asy... |
github | krisleech/wisper-sidekiq | https://github.com/krisleech/wisper-sidekiq | spec/wisper/sidekiq_broadcaster_spec.rb | Ruby | mit | 87 | master | 6,497 | require 'wisper/sidekiq'
RSpec.describe Wisper::SidekiqBroadcaster do
class PublisherUnderTest
include Wisper::Publisher
def run
broadcast(:it_happened)
end
end
class RegularSubscriberUnderTest
def self.it_happened(*_)
end
end
class CustomizedSubscriberUnderTest
def self.it_h... |
github | krisleech/wisper-sidekiq | https://github.com/krisleech/wisper-sidekiq | lib/wisper/sidekiq.rb | Ruby | mit | 87 | master | 2,155 | require 'yaml'
require 'wisper'
require 'sidekiq'
require 'wisper/sidekiq/version'
require 'wisper/sidekiq/config'
require 'wisper/sidekiq/publisher_extensions'
module Wisper
# based on Sidekiq 4.x #delay method, which is not enabled by default in Sidekiq 5.x
# https://github.com/mperham/sidekiq/blob/4.x/lib/side... |
github | krisleech/wisper-sidekiq | https://github.com/krisleech/wisper-sidekiq | lib/wisper/sidekiq/config.rb | Ruby | mit | 87 | master | 767 | module Wisper
module Sidekiq
class Config
class << self
attr_reader :use_unsafe_yaml
DEFAULT_SAFE_TYPES = [
Class,
Symbol,
Time,
Date,
DateTime,
].freeze
def use_unsafe_yaml!
@use_unsafe_yaml = true
end
... |
github | krisleech/wisper-sidekiq | https://github.com/krisleech/wisper-sidekiq | lib/wisper/sidekiq/publisher_extensions.rb | Ruby | mit | 87 | master | 753 | module Wisper
module Sidekiq
module PublisherExtensions
# Extension to automatically register subscriber classes as safe
module SubscribeRegisterTypes
def subscribe(listener, *args, **kargs, &block)
Wisper::Sidekiq::Config.register_safe_types(listener)
super
end
... |
github | mattyr/sidecloq | https://github.com/mattyr/sidecloq | Appraisals | Ruby | mit | 87 | main | 235 | appraise "sidekiq-6.4" do
gem "sidekiq", "~> 6.4.0"
end
appraise "sidekiq-6.5" do
gem "sidekiq", "~> 6.5.0"
end
appraise "sidekiq-7.0" do
gem "sidekiq", "~> 7.0.0"
end
appraise "sidekiq-7.1" do
gem "sidekiq", "~> 7.1.0"
end |
github | mattyr/sidecloq | https://github.com/mattyr/sidecloq | Rakefile | Ruby | mit | 87 | main | 1,031 | require 'bundler/gem_tasks'
require 'rake/testtask'
Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/test_*.rb']
end
task default: :test
desc 'Run the Sidekiq web interface (w/Sidecloq)'
task :web do
require 'sidekiq'
require 'sidecloq'
Sidekiq.configure... |
github | mattyr/sidecloq | https://github.com/mattyr/sidecloq | sidecloq.gemspec | Ruby | mit | 87 | main | 1,413 | # coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'sidecloq/version'
Gem::Specification.new do |spec|
spec.name = 'sidecloq'
spec.version = Sidecloq::VERSION
spec.authors = ['Matt Robinson']
spec.email = ['rob... |
github | mattyr/sidecloq | https://github.com/mattyr/sidecloq | Gemfile | Ruby | mit | 87 | main | 418 | source 'https://rubygems.org'
gemspec
platforms :mri, :rbx do
gem 'pry'
gem 'minitest-utils'
end
sidekiq_dep =
case ENV['sidekiq'].to_s.sub('sidekiq-', '')
when /(?:\d+\.)+\d+/ then "~> #{$&}#{'.0' if Gem::Version.new($&).segments.size == 2}"
else {github: 'mperham/sidekiq', branch: ENV['sidekiq']}
end
... |
github | mattyr/sidecloq | https://github.com/mattyr/sidecloq | test/helper.rb | Ruby | mit | 87 | main | 1,937 | require 'simplecov'
if ENV['CI']
require 'simplecov_json_formatter'
SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter
end
SimpleCov.start
$TESTING = true
# disable minitest/parallel threads
ENV["MT_CPU"] = "0"
ENV['N'] = '0'
ENV["BACKTRACE"] = "1"
require "bundler/setup"
Bundler.require(:default, :test)
... |
github | mattyr/sidecloq | https://github.com/mattyr/sidecloq | test/test_job_enqueuer.rb | Ruby | mit | 87 | main | 2,234 | require_relative 'helper'
require 'sidekiq/api'
class TestJobEnqueuer < Sidecloq::Test
describe 'job_enqueuer' do
before { Sidekiq.redis(&:flushdb) }
let(:enqueuer) { Sidecloq::JobEnqueuer.new(spec) }
describe 'normal job' do
let(:spec) { {'cron' => '1 * * * *', 'class' => 'DummyJob', 'args' => []... |
github | mattyr/sidecloq | https://github.com/mattyr/sidecloq | test/test_sidecloq.rb | Ruby | mit | 87 | main | 2,204 | require_relative 'helper'
class TestSidecloq < Sidecloq::Test
describe 'sidecloq' do
it 'has a version number' do
refute_nil ::Sidecloq::VERSION
end
it 'is configurable by assignment' do
Sidecloq.options[:test] = 'something'
assert_equal 'something', Sidecloq.options[:test]
Side... |
github | mattyr/sidecloq | https://github.com/mattyr/sidecloq | test/test_runner.rb | Ruby | mit | 87 | main | 618 | require_relative 'helper'
class TestRunner < Sidecloq::Test
describe 'runner' do
it 'uses locker in options' do
r = Sidecloq::Runner.new(locker: DummyLocker.new)
assert_instance_of DummyLocker, r.locker
end
it 'uses scheduler in options' do
r = Sidecloq::Runner.new(scheduler: DummySche... |
github | mattyr/sidecloq | https://github.com/mattyr/sidecloq | test/test_utils.rb | Ruby | mit | 87 | main | 671 | require_relative 'helper'
class TestUtils < Sidecloq::Test
class TestClass
include Sidecloq::Utils
end
describe 'utils' do
let(:utils) { TestClass.new }
describe 'will_never_run' do
it 'detects runnable cron lines' do
refute utils.will_never_run('* * * * *')
end
it 'detec... |
github | mattyr/sidecloq | https://github.com/mattyr/sidecloq | test/test_schedule.rb | Ruby | mit | 87 | main | 2,746 | require_relative 'helper'
class TestSchedule < Sidecloq::Test
describe 'schedule' do
let(:schedule_hash) do
{
'test_job' => {
'class' => 'JobClass',
'cron' => '0 7 * * *',
'queue' => 'default',
'args' => { 'batch' => 100 }
}
}
end
let(:r... |
github | mattyr/sidecloq | https://github.com/mattyr/sidecloq | test/test_locker.rb | Ruby | mit | 87 | main | 3,194 | require_relative 'helper'
class TestLocker < Sidecloq::Test
describe 'locker' do
before { Sidekiq.redis(&:flushdb) }
it 'obtains the lock when only locker' do
solo = Sidecloq::Locker.new(lock_key: 'lockertest1')
obtained_lock = false
solo.with_lock do
obtained_lock = true
a... |
github | mattyr/sidecloq | https://github.com/mattyr/sidecloq | test/test_scheduler.rb | Ruby | mit | 87 | main | 1,624 | require_relative 'helper'
require 'sidekiq/api'
class TestScheduler < Sidecloq::Test
describe 'scheduler' do
let(:specs) do
{test: {'cron' => '1 * * * *', 'class' => 'DummyJob', 'args' => []}}
end
let(:schedule) { Sidecloq::Schedule.new(specs) }
let(:scheduler) { Sidecloq::Scheduler.new(schedul... |
github | mattyr/sidecloq | https://github.com/mattyr/sidecloq | lib/sidecloq.rb | Ruby | mit | 87 | main | 1,725 | require 'sidekiq'
require 'concurrent'
require 'json'
require 'redlock'
require 'rufus-scheduler'
require 'yaml'
require 'sidecloq/utils'
require 'sidecloq/schedule'
require 'sidecloq/locker'
require 'sidecloq/scheduler'
require 'sidecloq/runner'
require 'sidecloq/job_enqueuer'
require 'sidecloq/version'
# Sideloq pr... |
github | mattyr/sidecloq | https://github.com/mattyr/sidecloq | lib/sidecloq/scheduler.rb | Ruby | mit | 87 | main | 1,939 | module Sidecloq
# Scheduler enqueues jobs according to the given schedule
class Scheduler
include Utils
def initialize(schedule, options = {})
@schedule = schedule
@options = options
@loaded = Concurrent::Event.new
@running = false
end
# run queues jobs per their schedules,... |
github | mattyr/sidecloq | https://github.com/mattyr/sidecloq | lib/sidecloq/web.rb | Ruby | mit | 87 | main | 911 | module Sidecloq
# Plugin for sidekiq-web
module Web
VIEW_PATH = File.expand_path('../../../web/views', __FILE__)
LOCALES = File.expand_path('../../../web/locales', __FILE__)
def self.registered(app)
app.get '/recurring' do
@schedule = Schedule.from_redis
erb File.read(File.join(V... |
github | mattyr/sidecloq | https://github.com/mattyr/sidecloq | lib/sidecloq/schedule.rb | Ruby | mit | 87 | main | 1,738 | module Sidecloq
# Schedule loads and parses recurring job specs from files, hashes, and redis
class Schedule
include Utils
REDIS_KEY = :sidecloq_schedule
attr_reader :job_specs
def initialize(specs)
@job_specs = specs
end
def self.from_yaml(filename)
from_hash(YAML.load_file(... |
github | mattyr/sidecloq | https://github.com/mattyr/sidecloq | lib/sidecloq/utils.rb | Ruby | mit | 87 | main | 1,890 | module Sidecloq
# Useful stuff
module Utils
# Sets the Sidekiq::Logging context automatically with direct calls to
# *.logger
class ContextLogger
def initialize(ctx)
@context = ctx
end
def sidekiq_logging_context_method
@sidekiq_logging_context_method ||=
beg... |
github | mattyr/sidecloq | https://github.com/mattyr/sidecloq | lib/sidecloq/runner.rb | Ruby | mit | 87 | main | 1,149 | module Sidecloq
# Runner encapsulates a locker and a scheduler, running scheduler when
# "elected" leader
class Runner
include Utils
attr_reader :locker, :scheduler
def initialize(options = {})
@locker = extract_locker(options)
@scheduler = extract_scheduler(options)
end
def run... |
github | mattyr/sidecloq | https://github.com/mattyr/sidecloq | lib/sidecloq/locker.rb | Ruby | mit | 87 | main | 2,417 | require 'redis-client'
module Sidecloq
# Locker obtains or waits for an exclusive lock on a key in redis
class Locker
include Utils
DEFAULT_LOCK_KEY = 'sidecloq_leader_lock'
def initialize(options = {})
# we keep a connection from the pool by default
@redis = options[:redis] || Sidekiq.re... |
github | mattyr/sidecloq | https://github.com/mattyr/sidecloq | lib/sidecloq/job_enqueuer.rb | Ruby | mit | 87 | main | 746 | module Sidecloq
class JobEnqueuer
attr_reader :spec
def initialize(spec)
# Dup to prevent JID reuse in subsequent enqueue's
@spec = spec.dup
@spec['class'] = Object.const_get(spec['class'])
end
def enqueue
if active_job_class?
initialize_active_job_class.enqueue(queue... |
github | joshsoftware/code-curiosity | https://github.com/joshsoftware/code-curiosity | Gemfile | Ruby | mit | 87 | master | 2,005 | source 'https://rubygems.org'
ruby '2.7.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0'
gem 'mongoid'
gem 'bootstrap-sass'
gem 'sass-rails'
gem 'uglifier'
gem 'coffee-rails'
gem 'haml'
gem 'webpacker'
# See https://github.com/sstephenson/execjs#readme for more supported runtime... |
github | joshsoftware/code-curiosity | https://github.com/joshsoftware/code-curiosity | app/serializers/transaction_serializer.rb | Ruby | mit | 87 | master | 421 | class TransactionSerializer < ActiveModel::Serializer
attributes :id, :points, :type, :transaction_type, :description, :created_at, :coupon_code, :redeem_request_retailer, :amount
def transaction_type
object.transaction_type.humanize
end
def created_at
object.created_at.strftime('%d/%b/%Y %T')
end
... |
github | joshsoftware/code-curiosity | https://github.com/joshsoftware/code-curiosity | app/controllers/users_controller.rb | Ruby | mit | 87 | master | 1,861 | class UsersController < ApplicationController
before_action :authenticate_user!, except: [:show]
def index
@users = [current_user]
end
def show
@user = User.find(params[:id])
if @user
render layout: current_user ? 'application' : 'public'
else
redirect_to root_url, alert: I18n.t('u... |
github | joshsoftware/code-curiosity | https://github.com/joshsoftware/code-curiosity | app/controllers/dashboard_controller.rb | Ruby | mit | 87 | master | 259 | class DashboardController < ApplicationController
include ContributionHelper
before_action :authenticate_user!, except: [:webhook]
def index
contribution_data
end
def webhook
# render :nothing # removed in rails 5.1
head :ok
end
end |
github | joshsoftware/code-curiosity | https://github.com/joshsoftware/code-curiosity | app/controllers/redeem_controller.rb | Ruby | mit | 87 | master | 392 | class RedeemController < ApplicationController
before_action :authenticate_user!
def create
@redeem = current_user.redeem_requests.build(redeem_params)
if @redeem.save
flash[:notice] = I18n.t('redeem.request_created')
end
end
private
def redeem_params
params.fetch(:redeem_request).per... |
github | joshsoftware/code-curiosity | https://github.com/joshsoftware/code-curiosity | app/controllers/registrations_controller.rb | Ruby | mit | 87 | master | 531 | class RegistrationsController < Devise::RegistrationsController
before_action :redirect_to_home, except: [:terms_and_conditions]
def terms_and_conditions
if params[:terms_and_conditions]
current_user.set(terms_and_conditions: params[:terms_and_conditions])
redirect_to dashboard_path
else
... |
github | joshsoftware/code-curiosity | https://github.com/joshsoftware/code-curiosity | app/controllers/application_controller.rb | Ruby | mit | 87 | master | 893 | class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :signout_old_login
protected
def signout_old_login
if current_user && current_user.auth_token... |
github | joshsoftware/code-curiosity | https://github.com/joshsoftware/code-curiosity | app/controllers/commits_controller.rb | Ruby | mit | 87 | master | 748 | class CommitsController < ApplicationController
before_action :user_commits, only: [:index, :reveal]
def index
from = params[:from].presence || Time.now.beginning_of_month
to = params[:to].presence.try(:to_date).try(:end_of_day) || Time.now
@commits = @commits.in_range(from, to)
... |
github | joshsoftware/code-curiosity | https://github.com/joshsoftware/code-curiosity | app/controllers/home_controller.rb | Ruby | mit | 87 | master | 570 | class HomeController < ApplicationController
def index
if user_signed_in?
redirect_to dashboard_path
return
else
@user_trend, @contribution_trend, @xAxis = MultiLineChart::Index.get
end
end
def leaderboard
@subscriptions = current_round.subscriptions
... |
github | joshsoftware/code-curiosity | https://github.com/joshsoftware/code-curiosity | app/controllers/repositories_controller.rb | Ruby | mit | 87 | master | 1,811 | class RepositoriesController < ApplicationController
before_action :authenticate_user!
before_action :find_repo, only: [:destroy, :sync]
def index
@repos = current_user.repositories
end
def new
@repo = Repository.new
render 'edit'
end
def create
@repo = Repository.add_new(params[:reposi... |
github | joshsoftware/code-curiosity | https://github.com/joshsoftware/code-curiosity | app/controllers/transactions_controller.rb | Ruby | mit | 87 | master | 336 | class TransactionsController < ApplicationController
before_action :authenticate_user!
respond_to :html, :js
def index
@records_per_page = Kaminari.config.default_per_page
@transactions = Transaction.where(user_id:current_user.id).order_by(:created_at => 'desc').page(params[:page]).per(@records_per_... |
github | joshsoftware/code-curiosity | https://github.com/joshsoftware/code-curiosity | app/controllers/github/repos_controller.rb | Ruby | mit | 87 | master | 241 | class Github::ReposController < ApplicationController
before_action :authenticate_user!
def sync
unless current_user.repo_syncing?
UserReposJob.perform_later(current_user.id.to_s) unless current_user.blocked
end
end
end |
github | joshsoftware/code-curiosity | https://github.com/joshsoftware/code-curiosity | app/controllers/admin/redeem_requests_controller.rb | Ruby | mit | 87 | master | 1,863 | class Admin::RedeemRequestsController < ApplicationController
include Admin::RedeemRequestsHelper
before_action :authenticate_user!
before_action :authenticate_admin!
before_action :load_redeem_request, only: [:index, :download]
def index
@redeem_requests = @redeem_requests.where(store: params[:store]) ... |
github | joshsoftware/code-curiosity | https://github.com/joshsoftware/code-curiosity | app/controllers/admin/repositories_controller.rb | Ruby | mit | 87 | master | 2,011 | class Admin::RepositoriesController < ApplicationController
before_action :authenticate_user!
before_action :authenticate_admin!
before_action :load_repository, only: :update_ignore_field
def index
status = params[:ignored] || false
@repos = Repository.parent.where(ignore: status, name: /#{params[:query... |
github | joshsoftware/code-curiosity | https://github.com/joshsoftware/code-curiosity | app/controllers/admin/sponsors_controller.rb | Ruby | mit | 87 | master | 1,428 | class Admin::SponsorsController < ApplicationController
before_action :authenticate_admin!
def index
@sponsors = Sponsor.all.page(params[:page])
end
def show
sponsor = Sponsor.find(params[:id])
@budgets = sponsor.budgets
end
def new
@sponsor = Sponsor.new
@sponsor.budgets.build
end
... |
github | joshsoftware/code-curiosity | https://github.com/joshsoftware/code-curiosity | app/controllers/admin/ignored_files_controller.rb | Ruby | mit | 87 | master | 2,000 | class Admin::IgnoredFilesController < ApplicationController
include IgnoredFileHelper
before_action :authenticate_user!
before_action :authenticate_admin!
before_action :find_ignored_file, except: [:index, :new, :create, :update_ignore_field]
def index
@status = params[:ignored] ? params[:ignored] : f... |
github | joshsoftware/code-curiosity | https://github.com/joshsoftware/code-curiosity | app/controllers/admin/commits_controller.rb | Ruby | mit | 87 | master | 425 | class Admin::CommitsController < ApplicationController
def index
from = (params[:from].presence.try(:to_date) || Date.today.beginning_of_month).beginning_of_day
to = (params[:to].presence.try(:to_date) || Date.today).end_of_day
@commits = Commit.all.in_range(from, to)
.search_by... |
github | joshsoftware/code-curiosity | https://github.com/joshsoftware/code-curiosity | app/controllers/admin/users_controller.rb | Ruby | mit | 87 | master | 1,306 | class Admin::UsersController < ApplicationController
before_action :authenticate_user!
before_action :authenticate_admin!
before_action :find_user, only: [:block_user, :destroy]
def index
@status = params[:blocked] || false
@users = User.contestants.where(blocked: @status).desc(:created_at).page(params... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.