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 | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | lib/sms_on_rails/activerecord_extensions/acts_as_deliverable.rb | Ruby | mit | 93 | master | 3,380 | module SmsOnRails
module ActsAsDeliverable
def self.extended(base)#:nodoc:
base.send :class_inheritable_hash, :acts_as_deliverable_options
base.acts_as_deliverable_options = {
:retry_count => 3,
:max_messages => 30,
:fatal_exception => nil,
:locrec_options => {},
... |
github | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | lib/sms_on_rails/activerecord_extensions/has_a_sms_service_provider.rb | Ruby | mit | 93 | master | 4,086 | module SmsOnRails
module ServiceProviders
module HasASmsServiceProvider
def self.extended(base)
base.send :class_inheritable_hash, :sms_service_provider_options
base.extend ClassMethods
end
module ClassMethods
# Add an accessor to the service provider
#
... |
github | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | lib/sms_on_rails/service_providers/clickatell.rb | Ruby | mit | 93 | master | 1,518 | module SmsOnRails
module ServiceProviders
class Clickatell < Base
self.provider_id = 1
FATAL_ERROR_CODES = %w(105 114) unless defined?(FATAL_ERROR_CODES)
def initialize
begin
require 'clickatell'
rescue LoadError => exc
raise LoadError.new(exc.to_s + "... |
github | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | lib/sms_on_rails/service_providers/base.rb | Ruby | mit | 93 | master | 8,790 | # This is the base class for service providers from which all others inherit
# All service providers are singletons and can be accessed by their instance
#
# To send a message without validation
# SmsOnRails::ServiceProviders::<Provider>.instance.send_message '12065551234', 'my message', options
#
# To send a message ... |
github | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | lib/sms_on_rails/service_providers/email_gateway.rb | Ruby | mit | 93 | master | 2,578 | #Require all the email gateway support files
Dir.glob(File.dirname(__FILE__) + '/email_gateway_support/*.rb').each {|f| require f }
module SmsOnRails
module ServiceProviders
class EmailGateway < Base
self.provider_id = 3
def ping; true; end
def mailer_klass; self.class.mailer_klass; end... |
github | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | lib/sms_on_rails/service_providers/dummy.rb | Ruby | mit | 93 | master | 448 | module SmsOnRails
module ServiceProviders
class Dummy < Base
self.provider_id = 2
def ping
true
end
def send_message(phone_number, message, options={})
response = {:unique_id => "#{$$}:#{Time.now.strftime('%Y%m%d%H%M%SZ')}.#{rand(1000)}"}
response
end
... |
github | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | lib/sms_on_rails/service_providers/email_gateway_support/errors.rb | Ruby | mit | 93 | master | 716 | module SmsOnRails
module ServiceProviders
class EmailGatewayInvalidSms < SmsOnRails::SmsError
def self.phone_error(phone_number)
new(self.phone_message(phone_number))
end
def self.phone_message(phone_number)
msg = "Invalid phone number #{phone_number.human_display if phone_numbe... |
github | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | lib/sms_on_rails/service_providers/email_gateway_support/sms_mailer.rb | Ruby | mit | 93 | master | 825 | require 'action_mailer'
module SmsOnRails
module ServiceProviders
module EmailGatewaySupport
class SmsMailer < ::ActionMailer::Base
def sms_through_gateway(recipient, message, phone_options={})
recipients recipient
bcc phone_options[:bcc]
from phon... |
github | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | test/test_helper.rb | Ruby | mit | 93 | master | 538 | dir = File.dirname(__FILE__)
require dir + '/run'
require dir +'/../init'
begin
if File.exists?(sdir = File.join(dir, '/../../static_record_cache') )
require File.join(sdir, 'init.rb')
else
require 'acts_as_static_record'
end
unless ActiveRecord::Base.respond_to?(:acts_as_static_record)
raise "Need... |
github | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | test/run.rb | Ruby | mit | 93 | master | 488 | require 'rubygems'
gem 'activesupport', :version => ">= 2.0.0"
require 'active_support'
require 'active_support/test_case'
require 'active_record'
require 'test/unit'
dir = File.dirname(__FILE__)
ActiveRecord::Base.logger = Logger.new("debug.log")
config = ActiveRecord::Base.configurations['test'] = {
:adapter =>... |
github | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | test/service_providers/clickatell_test.rb | Ruby | mit | 93 | master | 1,138 | require File.dirname(__FILE__)+'/abstract_test_support.rb'
class SmsOnRails::ServiceProviders::ClickatellTest < Test::Unit::TestCase
include SmsOnRails::ServiceProviders::AbstractTestSupport
def setup
super
SmsOnRails::ServiceProviders::Base.default_service_provider = SmsOnRails::ServiceProviders::Clicka... |
github | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | test/service_providers/abstract_test_support.rb | Ruby | mit | 93 | master | 3,391 | require File.dirname(__FILE__)+'/../test_helper'
module SmsOnRails::ServiceProviders::AbstractTestSupport
mattr_accessor :test_phone_number
self.test_phone_number ||= '12065552476'
def test_ping
assert provider_klass.instance.ping
end
def test_send_sms
sms = SmsOnRails::Outbound.create_sms "some te... |
github | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | test/service_providers/email_gateway_test.rb | Ruby | mit | 93 | master | 652 | require File.dirname(__FILE__)+'/abstract_test_support.rb'
SmsOnRails::ServiceProviders::EmailGateway.config =
{
:sender => 'blythe@spongecell.com',
:subject => 'Message from SmsOnRails'
#:bcc => nil,
#:mailer_klass => nil,
}
ActionMailer::Base.delivery_method = :test
class SmsOnRails::ServiceProvid... |
github | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | test/models/outbound_test.rb | Ruby | mit | 93 | master | 2,850 | require File.dirname(__FILE__)+'/../test_helper'
#require 'ruby-debug'
class SmsOnRails::OutboundTest < Test::Unit::TestCase
def test_outbound_create_sms_simple
SmsOnRails::Outbound.delete_all
sms = SmsOnRails::Outbound.create_sms 'hi', '2065552476'
assert(sms)
assert(sms.is_a?(ActiveRecord::Base)... |
github | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | test/models/phone_number_test.rb | Ruby | mit | 93 | master | 4,532 | require File.dirname(__FILE__)+'/../test_helper'
class SmsOnRails::OutboundTest < Test::Unit::TestCase
def test_phone_number_saves_digits
SmsOnRails::PhoneNumber.delete_all
sms = SmsOnRails::PhoneNumber.create!(:number => '206.555.1234')
sms.reload
assert('12065551234', sms.number)
sms = SmsOnR... |
github | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | test/models/draft_test.rb | Ruby | mit | 93 | master | 2,441 | require File.dirname(__FILE__)+'/../test_helper'
#require 'ruby-debug'
class SmsOnRails::DraftTest < Test::Unit::TestCase
def setup
super
SmsOnRails::PhoneNumber.delete_all
end
def test_create_draft_with_nested_params_with_existing_phone
phone = SmsOnRails::PhoneNumber.create!(:number => '1206555... |
github | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | test/active_record_extensions/delivery_and_locking_test.rb | Ruby | mit | 93 | master | 2,539 | require File.dirname(__FILE__)+'/../test_helper'
#require 'ruby-debug'
class SmsOnRails::Outbound < ActiveRecord::Base
def deliver_message_with_exception(options={})
raise Exception.new('asdf')
end
end
class SmsOnRails::DeliveryAndLockingTest < Test::Unit::TestCase
def setup
super
SmsOnRails::Ser... |
github | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | config/routes.rb | Ruby | mit | 93 | master | 1,122 | ActionController::Routing::Routes.draw do |map|
#Resources for sms on rails admin routes
#url: localhost:3000/admin/sms/drafts goes to the app/controllers/admin/sms_on_rails/draft_controller.rb
map.resources :sms_drafts, :new => {:send_sms => :any}, :as => 'admin/sms/drafts', :controller => 'adm... |
github | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | db/seed_data.rb | Ruby | mit | 93 | master | 494 | require 'active_record/fixtures'
unless defined?(SmsOnRails::PhoneCarrier)
require 'sms_on_rails/phone_carrier'
end
fixture_class_names = {
:sms_phone_carriers => 'SmsOnRails::PhoneCarrier',
}
fixture_path = File.dirname(__FILE__) + '/data/fixtures'
fixture_files = Dir.glob(fixture_path + '/*.yml').collect{|f| ... |
github | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | db/migrate/sms_on_rails_model_tables.rb | Ruby | mit | 93 | master | 2,634 | use_fk = respond_to?(:add_foreign_key)
puts "#{use_fk ? '': 'NOT'} USING FOREIGN KEYS"
create_table :sms_drafts, :force => true do |t|
t.column :message, :string, :default => nil
t.column :header, :string, :default => nil
t.column :footer, :string, :default => nil
t.column :status, ... |
github | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | db/migrate/sms_on_rails_phone_number_tables.rb | Ruby | mit | 93 | master | 618 | create_table :phone_numbers, :force => true do |t|
t.string :number, :length => 20, :null => false
t.integer :carrier_id, :default => nil
t.integer :owner_id, :default => nil
t.boolean :white_list, :n... |
github | blythedunham/smsonrails | https://github.com/blythedunham/smsonrails | db/migrate/sms_on_rails_carrier_tables.rb | Ruby | mit | 93 | master | 420 | create_table :sms_phone_carriers, :force => true do |t|
t.string :name, :length => 100, :null => false
t.string :email_domain, :length => 100, :default => nil
t.string :notes, :default => nil
t.string :options, :default => nil
end
... |
github | sosedoff/slack-notify | https://github.com/sosedoff/slack-notify | slack-notify.gemspec | Ruby | mit | 93 | master | 1,169 | # coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'slack-notify/version'
Gem::Specification.new do |spec|
spec.name = "slack-notify"
spec.version = SlackNotify::VERSION
spec.authors = ["Dan Sosedoff"]
spec.email ... |
github | sosedoff/slack-notify | https://github.com/sosedoff/slack-notify | Rakefile | Ruby | mit | 93 | master | 339 | require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:test) do |t|
t.pattern = "spec/**/*_spec.rb"
t.verbose = false
end
task :console do
$LOAD_PATH << "./lib"
require "irb"
require "irb/completion"
require "pp"
require "slack-notify"
ARGV.clear
IRB.start
end
tas... |
github | sosedoff/slack-notify | https://github.com/sosedoff/slack-notify | lib/slack-notify.rb | Ruby | mit | 93 | master | 250 | require "slack-notify/version"
require "slack-notify/error"
require "slack-notify/connection"
require "slack-notify/payload"
require "slack-notify/client"
module SlackNotify
def self.new(options = {})
SlackNotify::Client.new(options)
end
end |
github | sosedoff/slack-notify | https://github.com/sosedoff/slack-notify | lib/slack-notify/payload.rb | Ruby | mit | 93 | master | 1,013 | module SlackNotify
class Payload
attr_accessor :username,
:text,
:channel,
:icon_url,
:icon_emoji,
:link_names,
:unfurl_links
def initialize(options = {})
@username = options[:username] || "w... |
github | sosedoff/slack-notify | https://github.com/sosedoff/slack-notify | lib/slack-notify/client.rb | Ruby | mit | 93 | master | 1,163 | require "json"
require "faraday"
module SlackNotify
class Client
include SlackNotify::Connection
def initialize(options = {})
@webhook_url = options[:webhook_url]
@username = options[:username]
@channel = options[:channel]
@icon_url = options[:icon_url]
@icon_emoj... |
github | sosedoff/slack-notify | https://github.com/sosedoff/slack-notify | lib/slack-notify/connection.rb | Ruby | mit | 93 | master | 664 | module SlackNotify
module Connection
def send_payload(payload)
conn = Faraday.new(@webhook_url) do |c|
c.use(Faraday::Request::UrlEncoded)
c.adapter(Faraday.default_adapter)
c.options.timeout = 5
c.options.open_timeout = 5
end
response = conn.post do |req|
... |
github | sosedoff/slack-notify | https://github.com/sosedoff/slack-notify | spec/spec_helper.rb | Ruby | mit | 93 | master | 353 | require "simplecov"
SimpleCov.start
$:.unshift File.expand_path("../..", __FILE__)
require "webmock"
require "webmock/rspec"
require "slack-notify"
def fixture_path(filename=nil)
path = File.expand_path("../fixtures", __FILE__)
filename.nil? ? path : File.join(path, filename)
end
def fixture(file)
File.read(F... |
github | sosedoff/slack-notify | https://github.com/sosedoff/slack-notify | spec/slack_notify_spec.rb | Ruby | mit | 93 | master | 204 | require "spec_helper"
describe SlackNotify do
describe ".new" do
it "returns a client instance" do
expect(SlackNotify.new(webhook_url: "foobar")).to be_a SlackNotify::Client
end
end
end |
github | sosedoff/slack-notify | https://github.com/sosedoff/slack-notify | spec/slack-notify/payload_spec.rb | Ruby | mit | 93 | master | 2,653 | require "spec_helper"
describe SlackNotify::Payload do
let(:options) do
{
username: "foo",
channel: "#bar",
text: "hola",
icon_url: "http://domain.com/image.png",
icon_emoji: ":chart_with_upwards_trend:",
link_names: 1
}
end
describe "#initialize" do
let(:payload)... |
github | sosedoff/slack-notify | https://github.com/sosedoff/slack-notify | spec/slack-notify/client_spec.rb | Ruby | mit | 93 | master | 5,967 | require "spec_helper"
describe SlackNotify::Client do
describe "#initialize" do
it "requires webhook_url" do
expect { described_class.new }.to raise_error ArgumentError, "Webhook URL required"
end
it "does not raise error when webhook_url is set" do
expect { described_class.new(webhook_url: ... |
github | garethr/prodder | https://github.com/garethr/prodder | Rakefile | Ruby | mit | 93 | master | 307 | require 'cucumber/rake/task'
namespace :prod do
Cucumber::Rake::Task.new("all", "Run all probes")
["ssl", "ports", "headers"].each do |tag|
Cucumber::Rake::Task.new(tag, "Only run the #{tag} probes") do |t|
t.cucumber_opts = "--tags @#{tag}"
end
end
end
task :default => "prod:all" |
github | garethr/prodder | https://github.com/garethr/prodder | features/step_definitions/benchmarking_steps.rb | Ruby | mit | 93 | master | 205 | Given /^I am benchmarking$/ do
@scenario_start_time = Time.now
end
Then /^the elapsed time should be less than (\d+) seconds?$/ do |time|
(@scenario_start_time - Time.now).should > time.to_i * -1
end |
github | kovyrin/loops | https://github.com/kovyrin/loops | loops.gemspec | Ruby | mit | 93 | master | 1,189 | # -*- encoding: utf-8 -*-
$:.push File.expand_path('../lib', __FILE__)
require 'loops/version'
Gem::Specification.new do |s|
s.name = 'loops'
s.version = Loops::Version::STRING
s.platform = Gem::Platform::RUBY
s.authors = [ 'Oleksiy Kovyrin', 'Dmytro Shteflyuk' ]
s.email = %q{ale... |
github | kovyrin/loops | https://github.com/kovyrin/loops | Rakefile | Ruby | mit | 93 | master | 438 | require 'bundler'
Bundler::GemHelper.install_tasks
require 'rspec/core/rake_task'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :test => :spec
task :default => :spec
require 'yard'
YARD::Rake::YardocTask.new(:yard) do |t|
t.options = ['--title', 'Loops Documentation']
if ENV['PRIVATE']
... |
github | kovyrin/loops | https://github.com/kovyrin/loops | generators/loops/loops_generator.rb | Ruby | mit | 93 | master | 828 | # This generator bootstraps a Rails project for use with loops
class LoopsGenerator < Rails::Generator::Base
def manifest
record do |m|
# Generate app/loops directory and an example loop files
m.directory 'app'
m.directory 'app/loops'
m.file 'app/loops/APP_README', 'app/loops/READ... |
github | kovyrin/loops | https://github.com/kovyrin/loops | generators/loops/templates/app/loops/simple_loop.rb | Ruby | mit | 93 | master | 252 | # Simple loop with its own custom run method
#
# Does nothing aside from printing loop's name, pid and current time every second
#
class SimpleLoop < Loops::Base
def run
with_period_of(1) do
debug(Time.now)
sleep(5)
end
end
end |
github | kovyrin/loops | https://github.com/kovyrin/loops | spec/loop_lock_spec.rb | Ruby | mit | 93 | master | 1,608 | require 'spec_helper'
describe LoopLock do
before :each do
@lock = { :entity_id => 1, :loop => 'test' }
LoopLock.reset!
end
describe '.lock' do
it 'should lock unlocked entities' do
expect(LoopLock.lock(@lock)).to be(true)
end
it 'should create a lock record for unlocked entities' do
... |
github | kovyrin/loops | https://github.com/kovyrin/loops | spec/loops_spec.rb | Ruby | mit | 93 | master | 572 | require 'spec_helper'
describe Loops do
describe '.load_config' do
before :each do
Loops.root = RAILS_ROOT
@engine = Loops::Engine.new
end
it 'should load and parse Loops configuration file' do
expect(@engine.config).to be_an_instance_of(Hash)
expect(@engine.global_config).to be_... |
github | kovyrin/loops | https://github.com/kovyrin/loops | spec/spec_helper.rb | Ruby | mit | 93 | master | 837 | SPEC_ROOT = File.dirname(__FILE__)
PROJECT_ROOT = File.dirname(SPEC_ROOT)
RAILS_ROOT = File.expand_path(File.join(SPEC_ROOT, 'rails'))
# Load loops library
require File.join(PROJECT_ROOT, 'lib', 'loops')
# Load loops testing harness
require File.join(PROJECT_ROOT, 'lib', 'loops', 'testing')
# Requires supporting rub... |
github | kovyrin/loops | https://github.com/kovyrin/loops | spec/loops/cli_spec.rb | Ruby | mit | 93 | master | 6,532 | require 'spec_helper'
describe Loops::CLI do
before :each do
ENV['LOOPS_ENV'] = nil
end
it 'should include Loops::CLI::Options' do
expect(Loops::CLI.included_modules).to include(Loops::CLI::Options)
end
it 'should include Loops::CLI::Commands' do
expect(Loops::CLI.included_modules).to include(L... |
github | kovyrin/loops | https://github.com/kovyrin/loops | spec/loops/base_spec.rb | Ruby | mit | 93 | master | 717 | require 'spec_helper'
require 'active_support/core_ext/numeric/time'
describe Loops::Base do
let(:logger) { double('Logger').as_null_object }
context "default #run method" do
it "should raise an exception requiring descendants to override it" do
expect { subject.run }.to raise_error(NotImplementedError)... |
github | kovyrin/loops | https://github.com/kovyrin/loops | spec/loops/commands/list_command_spec.rb | Ruby | mit | 93 | master | 1,371 | require "spec_helper"
describe Loops::Commands::ListCommand do
let(:command) { described_class.new }
context "(private) is_disabled? method" do
it "should return true if the loop is disabled in config" do
expect(command.send(:is_disabled?, { :disabled => true })).to be(true)
end
it "should retu... |
github | kovyrin/loops | https://github.com/kovyrin/loops | spec/loops/base/config_option_spec.rb | Ruby | mit | 93 | master | 3,238 | require 'spec_helper'
describe Loops::Base, ".config_option method" do
class OptionTestLoop < Loops::Base
end
it "should define an accessor method with the given name" do
OptionTestLoop.config_option(:foo)
expect(create_loop(OptionTestLoop)).to respond_to(:foo)
end
context "auto-generated accessor ... |
github | kovyrin/loops | https://github.com/kovyrin/loops | spec/loops/base/with_lock_spec.rb | Ruby | mit | 93 | master | 2,553 | require 'spec_helper'
describe Loops::Base, '#with_lock' do
before :each do
@logger = double('Logger').as_null_object
@loop = Loops::Base.new(@logger, 'simple', {})
end
context 'when an entity is not locked' do
it 'should create lock on an item' do
called = false
@loop.with_lock(1, 'rspe... |
github | kovyrin/loops | https://github.com/kovyrin/loops | spec/support/loop_lock.rb | Ruby | mit | 93 | master | 3,516 | # Represents a lock object for a specific item.
#
# Usually you should use only {lock} and {unlock} methods to get
# entity locked or unlocked correspondingly. Method {locked?} could
# be used in test to verify lock status.
#
# @example Create a lock on an entity
# LoopLock.lock(:loop => 'upload', :entity_id => 15)
#... |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops.rb | Ruby | mit | 93 | master | 4,802 | require 'yaml'
require 'erb'
require 'pathname'
module Loops
# @return [String]
# a full path to the loops "lib" directory.
LIB_ROOT = File.expand_path(File.dirname(__FILE__)) unless const_defined?('LIB_ROOT')
# @return [String]
# a full path to the loops binary file.
BINARY = File.expand_path(File.... |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops/testing.rb | Ruby | mit | 93 | master | 2,050 | require "active_support/concern"
require "active_support/core_ext/string"
require "active_support/core_ext/hash"
module Loops
module Testing
extend ActiveSupport::Concern
# Dumb worker stub
class Worker
attr_reader :name, :pm
def initialize(name, pm)
@name = name
@pm = pm
... |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops/version.rb | Ruby | mit | 93 | master | 280 | # Contains information about currently used Loops version.
#
# @example
# puts "Loops #{Loops::Version::STRING}"
#
module Loops
module Version
MAJOR = 2
MINOR = 1
PATCH = 0
BUILD = 'dev'
STRING = [ MAJOR, MINOR, PATCH, BUILD ].compact.join('.')
end
end |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops/logger.rb | Ruby | mit | 93 | master | 6,313 | require 'logger'
require 'delegate'
require 'fileutils'
class Loops::Logger < ::Delegator
# @return [Boolean]
# A value indicating whether all logging output should be
# also duplicated to the console.
attr_reader :write_to_console
# @return [Boolean]
# A value inidicating whether critical errors sh... |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops/cli.rb | Ruby | mit | 93 | master | 863 | %w(commands options).each { |p| require File.join(Loops::LIB_ROOT, 'loops/cli', p) }
module Loops
# Command line interface for the Loops system.
#
# Used to parse command line options, initialize engine, and
# execute command requested.
#
# @example
# Loops::CLI.execute
#
class CLI
include Comm... |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops/autoload.rb | Ruby | mit | 93 | master | 635 | module Loops
# @private
def self.__p(*path) File.join(Loops::LIB_ROOT, 'loops', *path) end
autoload :Base, __p('base')
autoload :CLI, __p('cli')
autoload :Command, __p('command')
autoload :Commands, __p('command')
autoload :Daemonize, __p('daemonize')
autoload :En... |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops/daemonize.rb | Ruby | mit | 93 | master | 1,700 | module Loops
module Daemonize
def self.read_pid(pid_file)
File.open(pid_file) do |f|
f.gets.to_i
end
rescue Errno::ENOENT
0
end
def self.check_pid(pid_file)
pid = read_pid(pid_file)
return false if pid.zero?
if defined?(::JRuby)
system "kill -0 #{pi... |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops/queue.rb | Ruby | mit | 93 | master | 2,206 | begin
require 'stomp'
rescue LoadError
puts "Can't load stomp gem - all queue loops will be disabled!"
end
require 'timeout'
module Loops
class Queue < Base
def self.check_dependencies
raise "No stomp gem installed!" unless defined?(Stomp::Client)
end
def run
create_client
config... |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops/worker.rb | Ruby | mit | 93 | master | 3,425 | module Loops
class Worker
attr_reader :name
attr_reader :pid
attr_reader :pm
attr_reader :index
def initialize(name, pm, engine, index, &blk)
raise ArgumentError, "Need a worker block!" unless block_given?
@name = name
@pm = pm
@engine = engine
@index = index
... |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops/base.rb | Ruby | mit | 93 | master | 6,039 | # Base class for all loop processes.
#
# To create a new loop just inherit this class and override the
# {#run} method (see example below).
#
# In most cases it's a good idea to re-run your loop periodically.
# In this case your process will free all unused memory to the system,
# and all leaked resources (yes, it's re... |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops/command.rb | Ruby | mit | 93 | master | 1,107 | # Represents a Loops command.
class Loops::Command
# @return [Engine]
# The instance of {Engine} to execute command in.
attr_reader :engine
# @return [Hash<String, Object>]
# The hash of (parsed) command-line options.
attr_reader :options
# Initializes a new {Command} instance.
def initialize
en... |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops/engine.rb | Ruby | mit | 93 | master | 7,895 | class Loops::Engine
attr_reader :config
attr_reader :loops_config
attr_reader :global_config
def initialize
load_config
end
#-------------------------------------------------------------------------------------------------
def load_config
# load and parse with erb
raw_config = File.read(Lo... |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops/process_manager.rb | Ruby | mit | 93 | master | 3,694 | module Loops
class ProcessManager
attr_reader :logger
#-----------------------------------------------------------------------------------------------
def initialize(config, logger)
@config = {
'poll_period' => 1,
'wait_period' => 10,
'workers_engine' => 'fork',
}.merg... |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops/worker_pool.rb | Ruby | mit | 93 | master | 1,232 | module Loops
class WorkerPool
attr_reader :name
def initialize(name, pm, engine, &blk)
@name = name
@pm = pm
@worker_block = blk
@engine = engine
@workers = []
end
def logger
@pm.logger
end
def shutdown?
@pm.shutdown?
end
def start_workers(... |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops/commands/start_command.rb | Ruby | mit | 93 | master | 779 | class Loops::Commands::StartCommand < Loops::Command
def execute
# Pid file check
if Loops::Daemonize.check_pid(Loops.pid_file)
puts "Can't start, another process exists!"
exit(1)
end
# Daemonization
if options[:daemonize]
app_name = "loops monitor: #{options[:args].join(' ') re... |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops/commands/stop_command.rb | Ruby | mit | 93 | master | 565 | class Loops::Commands::StopCommand < Loops::Command
def execute
STDOUT.sync = true
unless Loops::Daemonize.check_pid(Loops.pid_file)
puts "WARNING: No pid file or a stale pid file found! Exiting."
exit(0)
end
pid = Loops::Daemonize.read_pid(Loops.pid_file)
print "Killing the process:... |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops/commands/list_command.rb | Ruby | mit | 93 | master | 582 | class Loops::Commands::ListCommand < Loops::Command
def execute
puts "Available loops (current environment: #{Loops.environment}):"
engine.loops_config.each do |name, config|
disabled = is_disabled?(config)
puts " Loop: #{name}" + (disabled ? ' (disabled)' : '')
config.each do |k, v|
... |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops/commands/monitor_command.rb | Ruby | mit | 93 | master | 442 | class Loops::Commands::MonitorCommand < Loops::Command
def execute
# Mirror logging to console
Loops.logger.write_to_console = true
# Set process name
$0 = "loops monitor: #{options[:args].join(' ') rescue 'all'}\0"
# Start loops and let the monitor process take over
puts "Starting loops in ... |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops/commands/debug_command.rb | Ruby | mit | 93 | master | 242 | class Loops::Commands::DebugCommand < Loops::Command
def execute
Loops.logger.write_to_console = true
puts "Starting one loop in debug mode: #{options[:args].first}"
engine.debug_loop!(options[:args].first)
exit(0)
end
end |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops/cli/options.rb | Ruby | mit | 93 | master | 10,750 | require 'pathname'
require 'optparse'
module Loops
class CLI
# Contains methods to parse startup options, bootstrap application,
# and prepare #{CLI} class to run.
#
# @example
# Loops::CLI.parse(ARGV)
#
module Options
# @private
def self.included(base)
base.extend(C... |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops/cli/commands.rb | Ruby | mit | 93 | master | 3,925 | module Loops
class CLI
# Contains methods related to Loops commands: retrieving, instantiating,
# executing.
#
# @example
# Loops::CLI.execute(ARGV)
#
module Commands
# @private
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
... |
github | kovyrin/loops | https://github.com/kovyrin/loops | lib/loops/base_concerns/config_option.rb | Ruby | mit | 93 | master | 2,692 | require "active_support/concern"
require "loops/exceptions"
module Loops
module BaseConcerns
module ConfigOption
extend ActiveSupport::Concern
# Backend for configuration options accessor methods
def read_config_option(name)
options = self.class.loops_config_options[name] || {}
... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | matrix-sdk.gemspec | Ruby | mit | 93 | master | 888 | # frozen_string_literal: true
require File.join File.expand_path('lib', __dir__), 'matrix_sdk/version'
Gem::Specification.new do |spec|
spec.name = 'matrix_sdk'
spec.version = MatrixSdk::VERSION
spec.authors = ['Alexander Olofsson']
spec.email = ['ace@haxalot.com']
... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | Rakefile | Ruby | mit | 93 | master | 315 | 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
if ENV['GENERATE_REPORTS'] == 'true'
require 'ci/reporter/rake/test_unit'
task :test => 'ci:setup:testunit'
end
task :default => :test |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | test/client_test.rb | Ruby | mit | 93 | master | 14,764 | require 'test_helper'
class ClientTest < Test::Unit::TestCase
def setup
::Net::HTTP.any_instance.expects(:request).never
end
def test_creation
client = MatrixSdk::Client.new 'https://example.com'
assert !client.api.nil?
assert_equal client.api.homeserver, URI('https://example.com')
end
def... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | test/bot_test.rb | Ruby | mit | 93 | master | 7,672 | require 'test_helper'
class BotTest < Test::Unit::TestCase
class ExampleBot < MatrixSdk::Bot::Base
set :testing, true
command :test do |arg, arg2 = nil|
# ARG [ARG2]
bot.send :test_executed
end
command :test_arr do |*args|
# [ARGS...]
bot.send :test_arr_executed
end
... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | test/uri_test.rb | Ruby | mit | 93 | master | 3,899 | # frozen_string_literal: true
require 'test_helper'
class URITest < Test::Unit::TestCase
def test_creation
uri = URI('matrix:u/her:example.org')
assert_equal MatrixSdk::MXID.new('@her:example.org'), uri.mxid
uri = URI('matrix:u/her:example.org?action=chat')
assert_equal MatrixSdk::MXID.new('@her:... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | test/api_creation_test.rb | Ruby | mit | 93 | master | 8,901 | require 'test_helper'
require 'net/http'
require 'resolv'
class ApiTest < Test::Unit::TestCase
def test_creation
api = MatrixSdk::Api.new 'https://matrix.example.com/_matrix/'
assert_equal URI('https://matrix.example.com'), api.homeserver
api = MatrixSdk::Api.new 'matrix.com'
assert_equal URI('http... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | test/api_ss_protocol_test.rb | Ruby | mit | 93 | master | 747 | require 'test_helper'
class ApiSSTest < Test::Unit::TestCase
def setup
@http = mock
@http.stubs(:active?).returns(true)
@api = MatrixSdk::Api.new 'https://example.com', protocols: :SS, threadsafe: false
@api.instance_variable_set :@http, @http
@api.stubs(:print_http)
end
def mock_success(bo... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | test/room_test.rb | Ruby | mit | 93 | master | 11,791 | require 'test_helper'
class RoomTest < Test::Unit::TestCase
def setup
# Silence debugging output
::MatrixSdk.logger.level = :error
@http = mock
@http.stubs(:active?).returns(true)
@api = MatrixSdk::Api.new 'https://example.com', protocols: :CS
@api.instance_variable_set :@http, @http
@a... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | test/matrix_sdk_test.rb | Ruby | mit | 93 | master | 612 | require 'test_helper'
class MatrixSdkTest < Test::Unit::TestCase
def test_that_it_has_a_version_number
refute_nil ::MatrixSdk::VERSION
end
def test_debugging
::MatrixSdk.debug!
assert_equal 0, ::MatrixSdk.logger.level
end
def test_response
api = mock
test1 = { a: 5, b: 6 }
MatrixS... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | test/api_cs_protocol_test.rb | Ruby | mit | 93 | master | 7,830 | require 'test_helper'
class ApiTest < Test::Unit::TestCase
def setup
@http = mock
@http.stubs(:active?).returns(true)
@api = MatrixSdk::Api.new 'https://example.com', protocols: :CS, threadsafe: false
@api.instance_variable_set :@http, @http
@api.stubs(:print_http)
matrixsdk_add_api_stub
... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | test/api_cs_protocol_verification_test.rb | Ruby | mit | 93 | master | 3,234 | require 'test_helper'
class ApiCSVerificationTest < Test::Unit::TestCase
def setup
@http = mock
@http.stubs(:active?).returns(true)
@api = MatrixSdk::Api.new 'https://example.com', protocols: :CS, autoretry: false, threadsafe: false
@api.instance_variable_set :@http, @http
@api.stubs(:print_http... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | test/response_test.rb | Ruby | mit | 93 | master | 629 | # frozen_string_literal: true
require 'test_helper'
class ResponseTest < Test::Unit::TestCase
def setup
@http = mock
@http.stubs(:active?).returns(true)
@api = MatrixSdk::Api.new 'https://example.com'
@api.instance_variable_set :@http, @http
@api.stubs(:print_http)
end
def test_creation
... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | test/tinycache_custom_test.rb | Ruby | mit | 93 | master | 950 | # frozen_string_literal: true
require 'test_helper'
class TinycacheCustomTest < Test::Unit::TestCase
class CustomAdapter
def fetch(key, **_); end
end
class TestClass
extend MatrixSdk::Util::Tinycache
attr_accessor :client
cached :permanent
cached :temporary, expires_in: 1
cached :very... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | test/tinycache_test.rb | Ruby | mit | 93 | master | 3,159 | # frozen_string_literal: true
require 'test_helper'
class TinycacheTest < Test::Unit::TestCase
class TestClass
extend MatrixSdk::Util::Tinycache
attr_accessor :client
cached :permanent
cached :temporary, expires_in: 1
cached :very_temporary, expires_in: 0.1
cached :level_all, cache_level:... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | test/mxid_test.rb | Ruby | mit | 93 | master | 2,595 | require 'test_helper'
class MXIDTest < Test::Unit::TestCase
def test_creation
user = MatrixSdk::MXID.new '@user:example.com'
room_id = MatrixSdk::MXID.new '!opaque:example.com'
event = MatrixSdk::MXID.new '$opaque:example.com'
event3 = MatrixSdk::MXID.new '$0paqu3+strin6+w1th+special/chars'
group... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | test/user_test.rb | Ruby | mit | 93 | master | 1,753 | require 'test_helper'
class UserTest < Test::Unit::TestCase
def setup
# Silence debugging output
::MatrixSdk.logger.level = :error
@http = mock
@http.stubs(:active?).returns(true)
@api = MatrixSdk::Api.new 'https://example.com', protocols: :CS
@api.instance_variable_set :@http, @http
@a... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | test/test_helper.rb | Ruby | mit | 93 | master | 613 | require 'simplecov'
SimpleCov.start do
add_filter '/test/'
add_filter '/vendor/'
end
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
require 'matrix_sdk'
require 'test/unit'
require 'mocha/test_unit'
RUBY_MAJOR_MINOR_VERSION = RUBY_VERSION[0..2].freeze
OLDER_RUBY = %w[2.5 2.6].include?(RUBY_MAJOR_MINOR_VE... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | examples/simple_client.rb | Ruby | mit | 93 | master | 4,026 | #!/usr/bin/env ruby
# frozen_string_literal: true
require 'io/console'
require 'matrix_sdk'
# A filter to only discover joined rooms
ROOM_DISCOVERY_FILTER = {
event_fields: %w[sender membership],
presence: { senders: [], types: [] },
account_data: { senders: [], types: [] },
room: {
ephemeral: { senders: ... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | examples/simple_bot.rb | Ruby | mit | 93 | master | 5,423 | #!/usr/bin/env ruby
# frozen_string_literal: true
require 'matrix_sdk'
# A filter to simplify syncs
BOT_FILTER = {
presence: { types: [] },
account_data: { types: [] },
room: {
ephemeral: { types: [] },
state: {
types: ['m.room.*'],
lazy_load_members: true
},
timeline: {
types:... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | examples/bot_api.rb | Ruby | mit | 93 | master | 3,789 | #!/usr/bin/env ruby
# frozen_string_literal: true
# An example of a lightweight bot using the bot DSL
#
# This bot will implement a subset of the maubot ping/echo module
# It showcases required and optional parameters, as well as limitations on commands
require 'matrix_sdk/bot'
# Util methods added at end of class, ... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | lib/matrix_sdk.rb | Ruby | mit | 93 | master | 2,119 | # frozen_string_literal: true
require 'matrix_sdk/util/extensions'
require 'matrix_sdk/util/uri'
require 'matrix_sdk/version'
require 'json'
autoload :Logging, 'logging'
module MatrixSdk
autoload :Api, 'matrix_sdk/api'
# autoload :ApplicationService, 'matrix_sdk/application_service'
autoload :Client, 'matrix_... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | lib/matrix_sdk/client.rb | Ruby | mit | 93 | master | 25,347 | # frozen_string_literal: true
require 'matrix_sdk'
require 'matrix_sdk/util/events'
require 'English'
require 'forwardable'
module MatrixSdk
class Client
extend MatrixSdk::Extensions
include MatrixSdk::Logging
extend Forwardable
# @!attribute api [r] The underlying API connection
# @return [... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | lib/matrix_sdk/room.rb | Ruby | mit | 93 | master | 36,399 | # frozen_string_literal: true
require 'matrix_sdk'
require 'matrix_sdk/util/events'
require 'matrix_sdk/util/tinycache'
module MatrixSdk
# A class for tracking the information about a room on Matrix
class Room
extend MatrixSdk::Extensions
extend MatrixSdk::Util::Tinycache
include MatrixSdk::Logging
... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | lib/matrix_sdk/errors.rb | Ruby | mit | 93 | master | 1,779 | # frozen_string_literal: true
module MatrixSdk
# A generic error raised for issues in the MatrixSdk
class MatrixError < StandardError
end
# An error specialized and raised for failed requests
class MatrixRequestError < MatrixError
attr_reader :code, :data, :httpstatus, :message
alias error message
... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | lib/matrix_sdk/response.rb | Ruby | mit | 93 | master | 1,608 | # frozen_string_literal: true
module MatrixSdk
# An usability wrapper for API responses as an extended [Hash]
# All results can be read as both hash keys and as read-only methods on the key
#
# @example Simple usage of the response wrapper to get the avatar URL
# resp = api.get_avatar_url(api.whoami?.user_... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | lib/matrix_sdk/mxid.rb | Ruby | mit | 93 | master | 4,180 | # frozen_string_literal: true
module MatrixSdk
class MXID
attr_accessor :sigil, :localpart, :domain, :port
# @param identifier [String] The Matrix ID string in the format of '&<localpart>:<domain>' where '&' is the sigil
def initialize(identifier)
raise ArgumentError, 'Identifier must be a String'... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | lib/matrix_sdk/user.rb | Ruby | mit | 93 | master | 5,173 | # frozen_string_literal: true
require 'matrix_sdk'
module MatrixSdk
# A class for tracking information about a user on Matrix
class User
extend MatrixSdk::Extensions
attr_reader :id, :client
alias user_id :id
# @!method inspect
# An inspect method that skips a handful of instance variables... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | lib/matrix_sdk/api.rb | Ruby | mit | 93 | master | 17,946 | # frozen_string_literal: true
require 'matrix_sdk'
require 'erb'
require 'net/http'
require 'openssl'
require 'uri'
module MatrixSdk
class Api
extend MatrixSdk::Extensions
include MatrixSdk::Logging
USER_AGENT = "Ruby Matrix SDK v#{MatrixSdk::VERSION}"
DEFAULT_HEADERS = {
'accept' => 'applic... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | lib/matrix_sdk/rooms/space.rb | Ruby | mit | 93 | master | 2,151 | # frozen_string_literal: true
module MatrixSdk::Rooms
class Space < MatrixSdk::Room
TYPE = 'm.space'
def tree(suggested_only: nil, max_rooms: nil)
begin
data = client.api.request :get, :client_r0, "/rooms/#{id}/spaces", query: {
suggested_only: suggested_only,
max_rooms_per... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | lib/matrix_sdk/util/tinycache.rb | Ruby | mit | 93 | master | 4,448 | # frozen_string_literal: true
require 'matrix_sdk/util/tinycache_adapter'
module MatrixSdk::Util
module Tinycache
CACHE_LEVELS = {
none: 0,
some: 1,
all: 2
}.freeze
def self.adapter
@adapter ||= TinycacheAdapter
end
def self.adapter=(adapter)
@adapter = adapter
... |
github | ananace/ruby-matrix-sdk | https://github.com/ananace/ruby-matrix-sdk | lib/matrix_sdk/util/events.rb | Ruby | mit | 93 | master | 2,130 | # frozen_string_literal: true
module MatrixSdk
class EventHandlerArray < Hash
include MatrixSdk::Logging
attr_accessor :reraise_exceptions
def initialize(*args)
@reraise_exceptions = false
super(*args)
end
def add_handler(filter = nil, id = nil, &block)
id ||= block.hash
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.