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
ryanfelton/textile-editor-helper
https://github.com/ryanfelton/textile-editor-helper
test/abstract_unit.rb
Ruby
mit
96
master
458
$:.unshift(File.dirname(__FILE__) + '/../lib') require 'yaml' require 'test/unit' require 'rubygems' require 'action_controller' require 'action_controller/cgi_ext' require 'action_controller/test_process' # Show backtraces for deprecated behavior for quicker cleanup. ActiveSupport::Deprecation.debug = true ActionC...
github
ryanfelton/textile-editor-helper
https://github.com/ryanfelton/textile-editor-helper
test/textile_editor_helper_test.rb
Ruby
mit
96
master
6,514
require File.dirname(__FILE__) + '/abstract_unit' require File.dirname(__FILE__) + '/../lib/textile_editor_helper' require 'ostruct' class TextileEditorHelperTest < Test::Unit::TestCase include ActionView::Helpers::TextHelper include ActionView::Helpers::AssetTagHelper include ActionView::Helpers::TagHelper in...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
faulty.gemspec
Ruby
mit
96
master
1,323
# frozen_string_literal: true lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'faulty/version' Gem::Specification.new do |spec| spec.name = 'faulty' spec.version = Faulty.version spec.authors = ['Justin Howard'] spec.email = ['jmhoward0@gmail.com'] spec...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
Gemfile
Ruby
mit
96
master
1,143
# frozen_string_literal: true source 'https://rubygems.org' gemspec # We add non-essential gems like debugging tools and CI dependencies # here. This also allows us to use conditional dependencies that depend on the # platform not_jruby = %i[ruby mingw x64_mingw].freeze gem 'activesupport', '>= 4.2' gem 'byebug', ...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty.rb
Ruby
mit
96
master
8,964
# frozen_string_literal: true require 'securerandom' require 'forwardable' require 'concurrent' require 'faulty/deprecation' require 'faulty/immutable_options' require 'faulty/cache' require 'faulty/circuit' require 'faulty/error' require 'faulty/events' require 'faulty/patch' require 'faulty/circuit_registry' requir...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/cache.rb
Ruby
mit
96
master
337
# frozen_string_literal: true class Faulty # The namespace for Faulty caching module Cache end end require 'faulty/cache/auto_wire' require 'faulty/cache/default' require 'faulty/cache/circuit_proxy' require 'faulty/cache/fault_tolerant_proxy' require 'faulty/cache/mock' require 'faulty/cache/null' require 'fau...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/events.rb
Ruby
mit
96
master
690
# frozen_string_literal: true class Faulty # The namespace for Faulty events and event listeners module Events # All possible events that can be raised by Faulty EVENTS = %i[ cache_failure circuit_cache_hit circuit_cache_miss circuit_cache_write circuit_closed circuit_fa...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/deprecation.rb
Ruby
mit
96
master
981
# frozen_string_literal: true class Faulty # Support deprecating Faulty features module Deprecation class << self # Call to raise errors instead of logging warnings for Faulty deprecations def raise_errors!(enabled = true) # rubocop:disable Style/OptionalBooleanParameter @raise_errors = (en...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/immutable_options.rb
Ruby
mit
96
master
1,201
# frozen_string_literal: true class Faulty # A struct that cannot be modified after initialization module ImmutableOptions # @param hash [Hash] A hash of attributes to initialize with # @yield [self] Yields itself to the block to set options before freezing def initialize(hash, &block) setup(defa...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/error.rb
Ruby
mit
96
master
2,733
# frozen_string_literal: true class Faulty # The base error for all Faulty errors class FaultyError < StandardError; end # Raised if using the global Faulty object without initializing it class UninitializedError < FaultyError def initialize(message = nil) message ||= 'Faulty is not initialized' ...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/circuit_registry.rb
Ruby
mit
96
master
1,834
# frozen_string_literal: true class Faulty # Used by Faulty instances to track and memoize Circuits # # Whenever a circuit is requested by `Faulty#circuit`, it calls # `#retrieve`. That will return a resolved circuit if there is one, or # otherwise, it will create a new circuit instance. # # Once any cir...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/storage.rb
Ruby
mit
96
master
362
# frozen_string_literal: true class Faulty # The namespace for Faulty storage module Storage end end require 'faulty/storage/auto_wire' require 'faulty/storage/circuit_proxy' require 'faulty/storage/fallback_chain' require 'faulty/storage/fault_tolerant_proxy' require 'faulty/storage/null' require 'faulty/stora...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/circuit.rb
Ruby
mit
96
master
19,436
# frozen_string_literal: true class Faulty # Runs code protected by a circuit breaker # # https://www.martinfowler.com/bliki/CircuitBreaker.html # # A circuit is intended to protect against repeated calls to a failing # external dependency. For example, a vendor API may be failing continuously. # In that...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/patch.rb
Ruby
mit
96
master
6,131
# frozen_string_literal: true require 'faulty/patch/base' class Faulty # Automatic wrappers for common core dependencies like database connections # or caches module Patch class << self # Create a circuit from a configuration hash # # This is intended to be used in contexts where the user ...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/result.rb
Ruby
mit
96
master
4,154
# frozen_string_literal: true class Faulty # An approximation of the `Result` type from some strongly-typed languages. # # F#: https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/results # # Rust: https://doc.rust-lang.org/std/result/enum.Result.html # # Since we can't enforce the type at c...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/status.rb
Ruby
mit
96
master
5,048
# frozen_string_literal: true class Faulty # The status of a circuit # # Includes information like the state and locks. Also calculates # whether a circuit can be run, or if it has failed a threshold. # # @!attribute [r] state # @return [:open, :closed] The stored circuit state. This is always open #...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/events/listener_interface.rb
Ruby
mit
96
master
488
# frozen_string_literal: true class Faulty module Events # The interface required to implement a event listener # # This is for documentation only and is not loaded class ListenerInterface # Handle an event raised by Faulty # # @param event [Symbol] The event name. Will be a member ...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/events/honeybadger_listener.rb
Ruby
mit
96
master
1,355
# frozen_string_literal: true class Faulty module Events # Reports circuit errors to Honeybadger # # https://www.honeybadger.io/ # # The honeybadger gem must be available. class HoneybadgerListener HONEYBADGER_EVENTS = Set[ :circuit_failure, :circuit_opened, :cir...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/events/log_listener.rb
Ruby
mit
96
master
2,612
# frozen_string_literal: true class Faulty module Events # A default listener that logs Faulty events class LogListener attr_reader :logger # @param logger A logger similar to stdlib `Logger`. Uses the Rails logger # by default if available, otherwise it creates a new `Logger` to #...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/events/notifier.rb
Ruby
mit
96
master
1,078
# frozen_string_literal: true class Faulty module Events # The default event dispatcher for Faulty class Notifier # @param listeners [Array<ListenerInterface>] An array of event listeners def initialize(listeners = []) @listeners = listeners.freeze end # Notify all listeners ...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/events/filter_notifier.rb
Ruby
mit
96
master
1,015
# frozen_string_literal: true class Faulty module Events # Wraps a Notifier and filters events by name class FilterNotifier # @param notifier [Notifier] The internal notifier to filter events for # @param events [Array, nil] An array of events to allow. If nil, all # {EVENTS} will be used...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/events/callback_listener.rb
Ruby
mit
96
master
1,088
# frozen_string_literal: true class Faulty module Events # A simple listener implementation that uses callback blocks as handlers # # Each event in {EVENTS} has a method on this class that can be used # to register a callback for that event. # # @example # listener = CallbackListener.ne...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/patch/elasticsearch.rb
Ruby
mit
96
master
3,468
# frozen_string_literal: true class Faulty module Patch # Patch Elasticsearch to run requests in a circuit # # This module is not required by default # # Pass a `:faulty` key into your Elasticsearch client options to enable # circuit protection. See {Patch.circuit_from_hash} for the available...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/patch/redis.rb
Ruby
mit
96
master
1,332
# frozen_string_literal: true require 'redis' class Faulty module Patch # Patch Redis to run all network IO in a circuit # # This module is not required by default # # Redis <= 4 # --------------------- # Pass a `:faulty` key into your Redis connection options to enable # circuit pro...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/patch/base.rb
Ruby
mit
96
master
1,275
# frozen_string_literal: true class Faulty module Patch # Can be included in patch modules to provide common functionality # # The patch needs to set `@faulty_circuit` # # @example # module ThingPatch # include Faulty::Patch::Base # # def initialize(options = {}) # ...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/patch/mysql2.rb
Ruby
mit
96
master
2,448
# frozen_string_literal: true require 'mysql2' if Gem::Version.new(Mysql2::VERSION) < Gem::Version.new('0.5.0') raise NotImplementedError, 'The faulty mysql2 patch requires mysql2 0.5.0 or later' end class Faulty module Patch # Patch Mysql2 to run connections and queries in a circuit # # This module ...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/patch/redis/patch.rb
Ruby
mit
96
master
1,733
# frozen_string_literal: true require 'redis' class Faulty module Patch module Redis include Base Patch.define_circuit_errors(self, ::Redis::BaseConnectionError) class BusyError < ::Redis::CommandError end # Patches Redis to add the `:faulty` key def initialize(options = {...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/patch/redis/middleware.rb
Ruby
mit
96
master
1,177
# frozen_string_literal: true class Faulty module Patch module Redis Patch.define_circuit_errors(self, ::RedisClient::ConnectionError) class BusyError < ::RedisClient::CommandError end module Middleware include Base def initialize(client) @faulty_circuit = Pat...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/cache/mock.rb
Ruby
mit
96
master
962
# frozen_string_literal: true class Faulty module Cache # A mock cache for testing # # This never clears expired values from memory, and should not be used # in production applications. Instead, use a more robust implementation like # `ActiveSupport::Cache::MemoryStore`. class Mock def ...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/cache/circuit_proxy.rb
Ruby
mit
96
master
1,957
# frozen_string_literal: true class Faulty module Cache # A circuit wrapper for cache backends # # This class uses an internal {Circuit} to prevent the cache backend from # causing application issues. If the backend fails continuously, this # circuit will trip to prevent cascading failures. This ...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/cache/rails.rb
Ruby
mit
96
master
1,104
# frozen_string_literal: true class Faulty module Cache # A wrapper for a Rails or ActiveSupport cache # class Rails extend Forwardable # @param cache The Rails cache to wrap # @param fault_tolerant [Boolean] Whether the Rails cache is # fault_tolerant. See {#fault_tolerant?} f...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/cache/fault_tolerant_proxy.rb
Ruby
mit
96
master
2,502
# frozen_string_literal: true class Faulty module Cache # A wrapper for cache backends that may raise errors # # {Faulty#initialize} automatically wraps all non-fault-tolerant cache backends with # this class. # # If the cache backend raises a `StandardError`, it will be captured and # se...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/cache/default.rb
Ruby
mit
96
master
1,143
# frozen_string_literal: true class Faulty module Cache # The default cache implementation # # It tries to make a logical decision of what cache implementation to use # based on the current environment. # # - If Rails is loaded, it will use Rails.cache # - If ActiveSupport is available, i...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/cache/auto_wire.rb
Ruby
mit
96
master
1,712
# frozen_string_literal: true class Faulty module Cache # Automatically configure a cache backend # # Used by {Faulty#initialize} to setup sensible cache defaults class AutoWire # Options for {AutoWire} # # @!attribute [r] circuit # @return [Circuit] A circuit for {CircuitPr...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/cache/interface.rb
Ruby
mit
96
master
1,462
# frozen_string_literal: true class Faulty module Cache # The interface required for a cache backend implementation # # This is for documentation only and is not loaded class Interface # Retrieve a value from the cache if available # # @param key [String] The cache key # @rais...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
lib/faulty/cache/null.rb
Ruby
mit
96
master
391
# frozen_string_literal: true class Faulty module Cache # A cache backend that does nothing # # All methods are stubs and do no caching class Null # @return [nil] def read(_key) end # @return [void] def write(_key, _value, expires_in: nil) end # @return [tr...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/circuit_spec.rb
Ruby
mit
96
master
10,976
# frozen_string_literal: true require 'redis' RSpec.context :circuits do let(:circuit) { Faulty::Circuit.new('test', **options) } let(:open_circuit) do circuit = Faulty::Circuit.new('test', **options.merge(rate_threshold: 0, sample_threshold: 0)) circuit.try_run { raise 'failed' } circuit end le...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/spec_helper.rb
Ruby
mit
96
master
1,297
# frozen_string_literal: true require 'byebug' if Gem.loaded_specs['byebug'] if Gem.loaded_specs['simplecov'] && (ENV.fetch('COVERAGE', nil) || ENV.fetch('CI', nil)) require 'simplecov' if ENV['CI'] require 'simplecov-cobertura' SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter end Simpl...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/patch_spec.rb
Ruby
mit
96
master
5,085
# frozen_string_literal: true RSpec.describe Faulty::Patch do let(:error_base) do stub_const('TestErrorBase', Class.new(RuntimeError)) end describe '.circuit_from_hash' do let(:faulty) { Faulty.new(listeners: []) } let(:error_mapper) do stub_const('TestErrors', Module.new) described_cla...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/faulty_spec.rb
Ruby
mit
96
master
6,710
# frozen_string_literal: true RSpec.describe Faulty do subject(:instance) { described_class.new(listeners: []) } after do # Reset the global Faulty instance # We don't want to expose a public method to do this # because it could cause concurrency errors, and confusion about what # exactly gets res...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/immutable_options_spec.rb
Ruby
mit
96
master
1,662
# frozen_string_literal: true RSpec.describe Faulty::ImmutableOptions do let(:example_class) do Struct.new(:name, :cache, :storage) do include Faulty::ImmutableOptions def defaults { cache: 'default_cache' } end def required %i[name] end def finalize ...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/result_spec.rb
Ruby
mit
96
master
1,650
# frozen_string_literal: true RSpec.describe Faulty::Result do let(:ok) { described_class.new(ok: 'foo') } let(:error) { described_class.new(error: StandardError.new) } it 'can be constructed with an ok' do expect(ok.ok?).to be(true) end it 'can be constructed with an error' do expect(error.error?)...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/deprecation_spec.rb
Ruby
mit
96
master
1,249
# frozen_string_literal: true RSpec.describe Faulty::Deprecation do it 'prints note and sunset version' do expect(Kernel).to receive(:warn) .with('DEPRECATION: foo is deprecated and will be removed in 1.0 (Use bar)') described_class.deprecate(:foo, note: 'Use bar', sunset: '1.0') end it 'prints on...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/status_spec.rb
Ruby
mit
96
master
3,698
# frozen_string_literal: true RSpec.describe Faulty::Status do let(:options) { Faulty::Circuit::Options.new({}) } it 'is closed by default' do expect(described_class.new(options: options)).to be_closed end context 'when state is closed' do subject(:status) { described_class.new(options: options, stat...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/events/filter_notifier_spec.rb
Ruby
mit
96
master
1,182
# frozen_string_literal: true RSpec.describe Faulty::Events::FilterNotifier do let(:backend) { Faulty::Events::Notifier.new } it 'forwards all events by default' do filter = described_class.new(backend) expect(backend).to receive(:notify).with(:circuit_success, {}) filter.notify(:circuit_success, {}) ...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/events/log_listener_spec.rb
Ruby
mit
96
master
3,741
# frozen_string_literal: true RSpec.describe Faulty::Events::LogListener do subject(:listener) { described_class.new(logger) } let(:logger) do logger = ::Logger.new(io) logger.level = :debug logger end let(:io) { StringIO.new } let(:circuit) { Faulty::Circuit.new('test', notifier: notifier, cach...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/events/honeybadger_listener_spec.rb
Ruby
mit
96
master
2,040
# frozen_string_literal: true RSpec.describe Faulty::Events::HoneybadgerListener do let(:circuit) { Faulty::Circuit.new('test_circuit') } let(:error) { StandardError.new('fail') } let(:notice) do Honeybadger.flush Honeybadger::Backend::Test.notifications[:notices].first end before do skip 'Honey...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/events/callback_listener_spec.rb
Ruby
mit
96
master
1,172
# frozen_string_literal: true RSpec.describe Faulty::Events::CallbackListener do subject(:listener) { described_class.new } it 'calls handler with event payload' do result = nil listener.circuit_opened { |payload| result = payload } listener.handle(:circuit_opened, circuit: 'test') expect(result[:...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/events/notifier_spec.rb
Ruby
mit
96
master
1,164
# frozen_string_literal: true RSpec.describe Faulty::Events::Notifier do let(:listener_class) do Class.new do attr_reader :events def initialize @events = [] end def handle(event, payload) @events << [event, payload] end end end let(:failing_class) do ...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/patch/redis_spec.rb
Ruby
mit
96
master
3,642
# frozen_string_literal: true RSpec.describe Faulty::Patch::Redis do let(:faulty) { Faulty.new(listeners: []) } let(:bad_url) { 'redis://127.0.0.1:9876' } let(:bad_redis) { ::Redis.new(opts(url: bad_url, faulty: { instance: faulty })) } let(:good_redis) { ::Redis.new(opts(faulty: { instance: faulty })) } le...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/patch/mysql2_spec.rb
Ruby
mit
96
master
3,381
# frozen_string_literal: true RSpec.describe 'Faulty::Patch::Mysql2', if: defined?(Mysql2) do def new_client(opts = {}) Mysql2::Client.new({ username: ENV.fetch('MYSQL_USER', nil), password: ENV.fetch('MYSQL_PASSWORD', nil), host: ENV.fetch('MYSQL_HOST', nil), port: ENV.fetch('MYSQL_PORT'...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/patch/base_spec.rb
Ruby
mit
96
master
681
# frozen_string_literal: true RSpec.describe Faulty::Patch::Base do include described_class let(:circuit) { Faulty::Circuit.new('test', **options) } let(:options) { { cache: cache, storage: storage } } let(:storage) { Faulty::Storage::Memory.new } let(:cache) { Faulty::Cache::Mock.new } before { @faulty_...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/patch/elasticsearch_spec.rb
Ruby
mit
96
master
3,521
# frozen_string_literal: true RSpec.describe Faulty::Patch::Elasticsearch do let(:faulty) { Faulty.new(listeners: []) } let(:patched_module) { Faulty::Patch::Elasticsearch::PATCHED_MODULE } let(:good_url) { ENV.fetch('ELASTICSEARCH_URL', nil) } let(:bad_url) { 'localhost:9876' } let(:patched_good_client) { ...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/support/concurrency.rb
Ruby
mit
96
master
929
# frozen_string_literal: true class Faulty module Specs module Concurrency def concurrent_warmup(&block) @concurrent_warmup = block end def concurrently(times = 100, timeout: 3) barrier = Concurrent::CyclicBarrier.new(times) execute = lambda do @concurrent_wa...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/cache/null_spec.rb
Ruby
mit
96
master
311
# frozen_string_literal: true RSpec.describe Faulty::Cache::Null do subject(:cache) { described_class.new } it 'reads nothing after writing' do cache.write('foo', 'bar') expect(cache.read('foo')).to be_nil end it 'is fault_tolerant' do expect(cache.fault_tolerant?).to be(true) end end
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/cache/default_spec.rb
Ruby
mit
96
master
1,283
# frozen_string_literal: true RSpec.describe Faulty::Cache::Default do subject(:cache) { described_class.new } it 'creates Null when neither Rails nor ActiveSupport is defined' do expect(cache.instance_variable_get(:@cache)).to be_a(Faulty::Cache::Null) end context 'when ActiveSupport is defined' do ...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/cache/auto_wire_spec.rb
Ruby
mit
96
master
1,145
# frozen_string_literal: true RSpec.describe Faulty::Cache::AutoWire do subject(:auto_wire) { described_class.wrap(backend, circuit: circuit, notifier: notifier) } let(:circuit) { Faulty::Circuit.new('test') } let(:notifier) { Faulty::Events::Notifier.new } let(:backend) { nil } context 'with a fault-toler...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/cache/circuit_proxy_spec.rb
Ruby
mit
96
master
1,265
# frozen_string_literal: true RSpec.describe Faulty::Cache::CircuitProxy do let(:notifier) { Faulty::Events::Notifier.new } let(:circuit) { Faulty::Circuit.new('test', sample_threshold: 2) } let(:failing_cache) do Class.new do def method_missing(*_args) raise 'fail' end def respon...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/cache/fault_tolerant_proxy_spec.rb
Ruby
mit
96
master
1,854
# frozen_string_literal: true RSpec.describe Faulty::Cache::FaultTolerantProxy do let(:notifier) { Faulty::Events::Notifier.new } let(:failing_cache_class) do Class.new do def method_missing(*_args) raise 'fail' end def respond_to_missing?(*_args) true end end en...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/cache/mock_spec.rb
Ruby
mit
96
master
574
# frozen_string_literal: true RSpec.describe Faulty::Cache::Mock do subject(:cache) { described_class.new } it 'writes and reads a value' do cache.write('a key', 'a value') expect(cache.read('a key')).to eq('a value') end it 'expires values after expires_in' do cache.write('a key', 'a value', exp...
github
ParentSquare/faulty
https://github.com/ParentSquare/faulty
spec/cache/rails_spec.rb
Ruby
mit
96
master
766
# frozen_string_literal: true RSpec.describe Faulty::Cache::Rails do before do stub_const( 'Rails', Class.new do def self.cache @cache ||= Object.new end end ) end it 'uses global Rails.cache by default' do cache = described_class.new expect(cache.inst...
github
logandk/mongoid_denormalize
https://github.com/logandk/mongoid_denormalize
perf.rb
Ruby
mit
96
master
842
require "benchmark" require 'rubygems' require 'mongoid' Mongoid.configure do |config| config.master = Mongo::Connection.new.db("mongoid_denormalize_development") end def bm(context = "") print("#{context}\t") Benchmark.bm do |bm| [10, 100, 1000, 10000].each do |i| @user = User.create i.times do...
github
logandk/mongoid_denormalize
https://github.com/logandk/mongoid_denormalize
mongoid_denormalize.gemspec
Ruby
mit
96
master
1,634
# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'mongoid_denormalize/version' Gem::Specification.new do |s| s.name = 'mongoid_denormalize' s.version = Mongoid::Denormalize::VERSION s.required_rubygems_version = Gem::Requirement.new('>= 0...
github
logandk/mongoid_denormalize
https://github.com/logandk/mongoid_denormalize
Gemfile
Ruby
mit
96
master
201
source "http://rubygems.org" gemspec group :development do gem 'guard-rspec' gem 'wdm', '>= 0.1.0' if Gem.win_platform? gem 'rake' end group :test do gem 'rspec' gem 'database_cleaner' end
github
logandk/mongoid_denormalize
https://github.com/logandk/mongoid_denormalize
Guardfile
Ruby
mit
96
master
300
# vim:set filetype=ruby: # A sample Guardfile # More info at https://github.com/guard/guard#readme guard :rspec, all_after_pass: false, cli: "--fail-fast --tty --format documentation --colour" do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |match| "spec/#{match[1]}_spec.rb" } end
github
logandk/mongoid_denormalize
https://github.com/logandk/mongoid_denormalize
lib/mongoid_denormalize.rb
Ruby
mit
96
master
3,850
require 'mongoid_denormalize/version' require File.dirname(__FILE__) + '/railties/railtie' if defined?(Rails::Railtie) # = Mongoid::Denormalize # # Helper module for denormalizing association attributes in Mongoid models. module Mongoid::Denormalize extend ActiveSupport::Concern included do cattr_accessor :de...
github
logandk/mongoid_denormalize
https://github.com/logandk/mongoid_denormalize
lib/railties/denormalize.rake
Ruby
mit
96
master
1,216
namespace :db do desc "Verify all denormalizations and repair any inconsistencies" task :denormalize => :environment do get_denormalizable_models.each do |klass| if klass.embedded? reflection = klass.reflect_on_all_associations(:embedded_in).first parent = reflection.class_name.to_s.cl...
github
logandk/mongoid_denormalize
https://github.com/logandk/mongoid_denormalize
spec/mongoid_denormalize_spec.rb
Ruby
mit
96
master
5,182
require "spec_helper" describe Mongoid::Denormalize do before(:each) do @post = Post.create!(:title => "Blog post", :body => "Lorem ipsum...", :created_at => Time.parse("Jan 1 2010 12:00")) @user = User.create!(:name => "John Doe", :email => "john@doe.com", :post => @post, :location => [1, 1], :nickname => "...
github
logandk/mongoid_denormalize
https://github.com/logandk/mongoid_denormalize
spec/spec_helper.rb
Ruby
mit
96
master
750
require 'rubygems' require 'mongoid' require 'rake' require 'database_cleaner' require 'mongoid/version' # necessary for older versions of Mongoid (< ~3) # Load rake tasks load File.expand_path("../../lib/railties/denormalize.rake", __FILE__) task :environment do Dir.chdir(File.dirname(__FILE__)) end Mongoid.load!(...
github
logandk/mongoid_denormalize
https://github.com/logandk/mongoid_denormalize
spec/app/models/post.rb
Ruby
mit
96
master
330
class Post include Mongoid::Document include Mongoid::Denormalize field :title field :body field :created_at, :type => Time belongs_to :user has_many :comments denormalize :location, :type => Array, :from => :user denormalize :name, :email, :from => :user denormalize :created_at, :to => :co...
github
logandk/mongoid_denormalize
https://github.com/logandk/mongoid_denormalize
spec/app/models/comment.rb
Ruby
mit
96
master
516
class Comment include Mongoid::Document include Mongoid::Denormalize field :body belongs_to :post, :inverse_of => :comments belongs_to :user, :inverse_of => :comments belongs_to :moderator, :class_name => "User", :inverse_of => :moderated_comments denormalize :location, :type => Array, :from => :...
github
logandk/mongoid_denormalize
https://github.com/logandk/mongoid_denormalize
spec/app/models/user.rb
Ruby
mit
96
master
525
class User include Mongoid::Document include Mongoid::Denormalize field :name field :email field :nickname field :location, :type => Array has_one :post has_many :comments, :inverse_of => :user has_many :moderated_comments, :class_name => "Comment", :inverse_of => :moderator has_many :articles, ...
github
logandk/mongoid_denormalize
https://github.com/logandk/mongoid_denormalize
spec/app/models/article.rb
Ruby
mit
96
master
234
class Article include Mongoid::Document include Mongoid::Denormalize field :title field :body field :created_at, :type => Time belongs_to :author, :class_name => 'User' denormalize :name, :email, :from => :author end
github
maccman/sinatra-pubsub
https://github.com/maccman/sinatra-pubsub
sinatra-pubsub.gemspec
Ruby
mit
96
master
1,001
# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'sinatra/pubsub/version' Gem::Specification.new do |spec| spec.name = "sinatra-pubsub" spec.version = Sinatra::PubSub::VERSION spec.authors = ["Alex MacCaw"] spec.emai...
github
maccman/sinatra-pubsub
https://github.com/maccman/sinatra-pubsub
examples/tick/app.rb
Ruby
mit
96
master
461
require 'rubygems' require 'bundler' Bundler.require register Sinatra::PubSub Sinatra::PubSub.set( cors: false ) EventMachine.next_tick do EventMachine::PeriodicTimer.new(1) do Sinatra::PubSub.publish('tick', type: 'tick') end end get '/' do erb :stream end __END__ @@ stream <pre id="log"> </pre> <s...
github
maccman/sinatra-pubsub
https://github.com/maccman/sinatra-pubsub
lib/sinatra/pubsub.rb
Ruby
mit
96
master
425
require 'sinatra/pubsub/version' module Sinatra module PubSub autoload :Stream, 'sinatra/pubsub/stream' autoload :Redis, 'sinatra/pubsub/redis' autoload :App, 'sinatra/pubsub/app' autoload :Helpers, 'sinatra/pubsub/helpers' extend Helpers def self.registered(app) app.use App app...
github
maccman/sinatra-pubsub
https://github.com/maccman/sinatra-pubsub
lib/sinatra/pubsub/redis.rb
Ruby
mit
96
master
652
require 'redis' module Sinatra module PubSub module Redis extend self def subscribe redis = ::Redis.connect redis.psubscribe('pubsub', 'pubsub.*') do |on| on.pmessage do |match, channel, message| channel = channel.sub(/\Apubsub\.?/, '') channel = channel.e...
github
maccman/sinatra-pubsub
https://github.com/maccman/sinatra-pubsub
lib/sinatra/pubsub/helpers.rb
Ruby
mit
96
master
574
require 'json' require 'redis' require 'eventmachine' module Sinatra module PubSub module Helpers extend self def publish(channel, message) Redis.publish(channel, message.to_json) end def publish_all(message) publish(:all, message) end def subscribe Thread....
github
maccman/sinatra-pubsub
https://github.com/maccman/sinatra-pubsub
lib/sinatra/pubsub/app.rb
Ruby
mit
96
master
1,094
module Sinatra module PubSub class App < Sinatra::Base configure do set :cors, true set :origin, '*' set :server, 'thin' end helpers do def http_origin env['HTTP_ORIGIN'] end end before '/subscribe/?*' do return unless setti...
github
maccman/sinatra-pubsub
https://github.com/maccman/sinatra-pubsub
lib/sinatra/pubsub/stream.rb
Ruby
mit
96
master
1,852
module Sinatra module PubSub class Stream def self.streams @streams ||= Hash.new { |hash, key| hash[key] = [] } end def self.enabled? unless defined? @enabled @enabled = true end @enabled end def self.disable! @enabled = false ...
github
rwz/redis-gcra
https://github.com/rwz/redis-gcra
redis-gcra.gemspec
Ruby
mit
96
master
584
require File.expand_path("../lib/redis-gcra/version", __FILE__) Gem::Specification.new do |spec| spec.name = "redis-gcra" spec.version = RedisGCRA::VERSION spec.authors = ["Pavel Pravosud"] spec.email = ["pavel@pravosud.com"] spec.summary = "Rate limiting based on Generic Cell R...
github
rwz/redis-gcra
https://github.com/rwz/redis-gcra
lib/redis-gcra.rb
Ruby
mit
96
master
1,470
require "digest/sha1" require "thread" module RedisGCRA extend self autoload :Result, "redis-gcra/result" def limit(redis:, key:, burst:, rate:, period:, cost: 1) call(redis, :perform_gcra_ratelimit, key, burst, rate, period, cost) end def peek(redis:, key:, burst:, rate:, period:) call(redis, :in...
github
rwz/redis-gcra
https://github.com/rwz/redis-gcra
lib/redis-gcra/result.rb
Ruby
mit
96
master
338
module RedisGCRA class Result attr_reader :remaining, :reset_after, :retry_after def initialize(limited:, remaining:, reset_after:, retry_after:) @limited = limited @remaining = remaining @reset_after = reset_after @retry_after = retry_after end def limited? !!@limited ...
github
rwz/redis-gcra
https://github.com/rwz/redis-gcra
spec/redis_gcra_spec.rb
Ruby
mit
96
master
5,742
require "spec_helper" describe RedisGCRA do let(:redis) { RedisConnection } context "#limit" do def call(key: "foo", cost: 1, burst: 300, rate: 60, period: 60) described_class.limit( redis: redis, key: key, burst: burst, rate: rate, period: period, cost: c...
github
denisdefreyne/adsf
https://github.com/denisdefreyne/adsf
Rakefile
Ruby
mit
96
main
846
# frozen_string_literal: true require 'rubocop/rake_task' RuboCop::RakeTask.new(:rubocop) # TODO: Replace this with Bundler.with_unbundled_env def with_unbundled_env if Bundler.respond_to?(:with_unbundled_env) Bundler.with_unbundled_env { yield } else Bundler.with_clean_env { yield } end end def sub_s...
github
denisdefreyne/adsf
https://github.com/denisdefreyne/adsf
Gemfile
Ruby
mit
96
main
352
# frozen_string_literal: true source 'https://rubygems.org' gemspec path: 'adsf' gemspec path: 'adsf-live' group :development do gem 'faye-websocket' gem 'm' gem 'minitest' gem 'netrc', '~> 0.11.0' gem 'octokit', '~> 10.0' gem 'rack-test' gem 'rake' gem 'rubocop', '~> 1.7' gem 'simplecov', '~> 0.21...
github
denisdefreyne/adsf
https://github.com/denisdefreyne/adsf
adsf/adsf.gemspec
Ruby
mit
96
main
937
# frozen_string_literal: true require_relative 'lib/adsf/version' Gem::Specification.new do |s| s.name = 'adsf' s.version = Adsf::VERSION s.platform = Gem::Platform::RUBY s.summary = 'a tiny static file server' s.description = 'A web server...
github
denisdefreyne/adsf
https://github.com/denisdefreyne/adsf
adsf/Rakefile
Ruby
mit
96
main
357
# frozen_string_literal: true require 'rake/testtask' Rake::TestTask.new(:test) do |t| t.test_files = Dir[__dir__ + '/test/**/test_*.rb'] t.libs << 'test' t.verbose = false end file 'README.md' => '../README.md' do |task| cp task.prerequisites.first, task.name end task gem: ['README.md'] do sh('gem build ...
github
denisdefreyne/adsf
https://github.com/denisdefreyne/adsf
adsf/test/helper.rb
Ruby
mit
96
main
617
# frozen_string_literal: true require 'simplecov' SimpleCov.start SimpleCov.command_name 'test:adsf' require 'faye/websocket' require 'rack/test' require 'minitest/autorun' require 'net/http' require 'adsf' module Adsf::Test module Rack; end end module Adsf::Test::Helpers def setup # Clean up GC.start ...
github
denisdefreyne/adsf
https://github.com/denisdefreyne/adsf
adsf/test/test_server.rb
Ruby
mit
96
main
6,390
# frozen_string_literal: true require 'helper' class Adsf::Test::Server < Minitest::Test include Rack::Test::Methods include Adsf::Test::Helpers def run_server(opts = {}) opts = { root: 'output', port: 50_386 }.merge(opts) server = Adsf::Server.new(**opts) thread = Thread.new do Thread.curren...
github
denisdefreyne/adsf
https://github.com/denisdefreyne/adsf
adsf/test/test_manifest.rb
Ruby
mit
96
main
521
# frozen_string_literal: true require 'helper' class Adsf::ManifestTest < Minitest::Test def test_has_correct_manifest manifest_lines = File.readlines('adsf.manifest').map(&:chomp).reject(&:empty?) gemspec = eval(File.read('adsf.gemspec'), binding, 'adsf.gemspec') gemspec_lines = gemspec.files ...
github
denisdefreyne/adsf
https://github.com/denisdefreyne/adsf
adsf/test/rack/test_auto_file_extensions.rb
Ruby
mit
96
main
2,200
# frozen_string_literal: true require 'helper' require 'rack/helper' class Adsf::Test::Rack::AutoFileExtensions < Minitest::Test include Rack::Test::Methods include Adsf::Test::Helpers include Adsf::Test::Rack::Helpers def app ::Adsf::Rack::AutoFileExtensions.new( stub_app, **app_options, ...
github
denisdefreyne/adsf
https://github.com/denisdefreyne/adsf
adsf/test/rack/test_index_file_finder.rb
Ruby
mit
96
main
2,541
# frozen_string_literal: true require 'helper' require 'rack/helper' class Adsf::Test::Rack::IndexFileFinder < Minitest::Test include Rack::Test::Methods include Adsf::Test::Helpers include Adsf::Test::Rack::Helpers def app ::Adsf::Rack::IndexFileFinder.new( stub_app, **app_options, ) e...
github
denisdefreyne/adsf
https://github.com/denisdefreyne/adsf
adsf/lib/adsf/server.rb
Ruby
mit
96
main
2,074
# frozen_string_literal: true module Adsf class Server def initialize( root:, live: false, host: '127.0.0.1', port: 3000, index_filenames: ['index.html'], auto_extensions: [], handler: nil ) @root = root @live = live @index_filenames = index_filenam...
github
denisdefreyne/adsf
https://github.com/denisdefreyne/adsf
adsf/lib/adsf/rack.rb
Ruby
mit
96
main
200
# frozen_string_literal: true module Adsf module Rack end end require 'adsf/rack/index_file_finder' require 'adsf/rack/caching' require 'adsf/rack/cors' require 'adsf/rack/auto_file_extensions'
github
denisdefreyne/adsf
https://github.com/denisdefreyne/adsf
adsf/lib/adsf/rack/index_file_finder.rb
Ruby
mit
96
main
1,160
# frozen_string_literal: true module Adsf::Rack class IndexFileFinder def initialize(app, root:, index_filenames: ['index.html']) @app = app @root = root @index_filenames = index_filenames end def call(env) # Get path path_info = ::Rack::Utils.unescape(env['PATH_INFO']) ...
github
denisdefreyne/adsf
https://github.com/denisdefreyne/adsf
adsf/lib/adsf/rack/caching.rb
Ruby
mit
96
main
370
# frozen_string_literal: true module Adsf::Rack class Caching DEFAULT_HEADERS = { 'cache-control' => 'max-age=0, stale-if-error=0', }.freeze def initialize(app) @app = app end def call(env) status, headers, body = *@app.call(env) headers = DEFAULT_HEADERS.merge(headers)...
github
denisdefreyne/adsf
https://github.com/denisdefreyne/adsf
adsf/lib/adsf/rack/auto_file_extensions.rb
Ruby
mit
96
main
731
# frozen_string_literal: true module Adsf::Rack class AutoFileExtensions def initialize(app, root:, extensions:) @app = app @root = root # Search list starts with '' so that we first look for file as requested @search_suffixes = [''] + Array(extensions).map { |ext| ".#{ext}" } end ...
github
denisdefreyne/adsf
https://github.com/denisdefreyne/adsf
adsf/lib/adsf/rack/cors.rb
Ruby
mit
96
main
432
# frozen_string_literal: true module Adsf::Rack class CORS def initialize(app) @app = app end def call(env) status, headers, body = *@app.call(env) new_headers = headers.merge( 'access-control-allow-origin' => '*', 'access-control-allow-headers' => 'Origin,...
github
denisdefreyne/adsf
https://github.com/denisdefreyne/adsf
adsf-live/Rakefile
Ruby
mit
96
main
252
# frozen_string_literal: true require 'rake/testtask' Rake::TestTask.new(:test) do |t| t.test_files = Dir[__dir__ + '/test/**/test_*.rb'] t.libs << 'test' t.verbose = false end task :gem do sh('gem build *.gemspec') end task default: :test