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 | gshutler/useragent | https://github.com/gshutler/useragent | spec/browsers/webkit_user_agent_spec.rb | Ruby | mit | 187 | master | 39,658 | require 'user_agent'
shared_examples_for "Safari browser" do
it "should return 'Safari' as its browser" do
expect(@useragent.browser).to eq("Safari")
end
it "should return :strong as its security" do
expect(@useragent.security).to eq(:strong)
end
end
describe "UserAgent: Mozilla/5.0 (Macintosh; U; In... |
github | gshutler/useragent | https://github.com/gshutler/useragent | spec/browsers/internet_explorer_user_agent_spec.rb | Ruby | mit | 187 | master | 15,578 | require 'user_agent'
shared_examples_for "Internet Explorer browser" do
it "should return 'Internet Explorer' as its browser" do
expect(@useragent.browser).to eq("Internet Explorer")
end
it "should return 'Windows' as its platform" do
expect(@useragent.platform).to eq("Windows")
end
end
describe "Use... |
github | pzol/deterministic | https://github.com/pzol/deterministic | deterministic.gemspec | Ruby | mit | 186 | master | 1,130 | # coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'deterministic/version'
Gem::Specification.new do |spec|
spec.name = "deterministic"
spec.version = Deterministic::VERSION
spec.authors = ["Piotr Zolnierek"]
spec.emai... |
github | pzol/deterministic | https://github.com/pzol/deterministic | Guardfile | Ruby | mit | 186 | master | 495 | guard :bundler do
watch('Gemfile')
end
guard :bundler do
watch('Gemfile')
watch(/^.+\.gemspec/)
end
guard :rspec, cmd: 'bundle exec rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Turnip features and ste... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/spec_helper.rb | Ruby | mit | 186 | master | 907 | require 'simplecov'
SimpleCov.start
require 'deterministic'
RSpec.configure do |config|
# Limit the spec run to only specs with the focus metadata. If no specs have
# the filtering metadata and `run_all_when_everything_filtered = true` then
# all specs will run.
config.filter_run :focus
# Run all specs whe... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/readme_spec.rb | Ruby | mit | 186 | master | 1,129 | require 'spec_helper'
include Deterministic::Prelude::Result
Success(1).to_s # => "1"
Success(Success(1)) # => Success(1)
Failure(1).to_s # => "1"
Failure(Failure(1)) # => Failure(1)
Success(1).fmap { |v| v + 1} # => Succe... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/examples/controller_spec.rb | Ruby | mit | 186 | master | 1,225 | require 'spec_helper'
module Deterministic
module Procify
def py(m, *args)
args.count > 0 ? method(m).to_proc.curry[*args] : method(m)
end
end
end
class BookingController
include Deterministic::Prelude::Result
include Deterministic::Procify
Context = Struct.new(:booking, :ability, :format)
... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/examples/amount_spec.rb | Ruby | mit | 186 | master | 1,370 | require 'spec_helper'
require 'deterministic/enum'
Amount = Deterministic::enum {
Due(:amount)
Paid(:amount)
Info(:amount)
}
class Amount
def self.from_f(f)
f >= 0 ? Amount::Due.new(f) : Amount::Paid.new(-1 * f)
end
end
Deterministic::impl(Amount) {
def to_s
match {
Due() {|a| "%0.2f" % [a... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/examples/list_spec.rb | Ruby | mit | 186 | master | 5,371 | require 'spec_helper'
require_relative 'list'
describe List do
Nil = List::Nil
Cons = List::Cons
subject(:list) { List[1] }
specify { expect(list).to eq Cons.new(1, Nil.new) }
context "match" do
it "catches ignores guards with non-matching clauses" do
expect(
list.match {
Nil(... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/examples/validate_address_spec.rb | Ruby | mit | 186 | master | 1,068 | require 'spec_helper'
# A Unit of Work for validating an address
module ValidateAddress
extend Deterministic::Prelude::Result
def self.call(candidate)
errors = {}
errors[:street] = "Street cannot be empty" unless candidate.has_key? :street
errors[:city] = "Street cannot be empty" unless candidate.h... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/examples/logger_spec.rb | Ruby | mit | 186 | master | 2,646 | require 'spec_helper'
# TODO: dead code?
class Logger
alias :m :method
def initialize(repository)
@repository = repository
end
def log(item)
validate(item) >> m(:transform) >= m(:save)
end
private
attr_reader :repository
# TODO: this is never called; the matcher syntax is ... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/examples/list.rb | Ruby | mit | 186 | master | 3,439 | require 'deterministic/enum'
List = Deterministic::enum {
Cons(:head, :tail)
Nil()
}
class List
def self.[](*ary)
ary.reverse.inject(Nil.new) { |xs, x| xs.append(x) }
end
def self.empty
@empty ||= Nil.new
end
end
Deterministic::impl(List) {
class EmptyListError < StandardError; end
def appe... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/examples/config_spec.rb | Ruby | mit | 186 | master | 2,025 | require 'spec_helper'
include Deterministic
class ElasticSearchConfig
def initialize(env="development", proc_env=ENV)
@env, @proc_env = env, proc_env
end
attr_reader :env
def hosts
Option.any?(proc_env["RESFINITY_LOG_CLIENT_ES_HOST"]).match {
Some() {|s| { hosts: s.split(/, */) } }
None(... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/lib/enum_spec.rb | Ruby | mit | 186 | master | 2,635 | require 'spec_helper'
require 'deterministic/enum'
describe Deterministic::Enum do
include Deterministic
it "can't use value" do
expect { InvalidEnum = Deterministic::enum {
Unary(:value)
}}.to raise_error ArgumentError
end
context "Nullary, Unary, Binary" do
MyEnym = Deterministic::enum {... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/lib/deterministic/option_spec.rb | Ruby | mit | 186 | master | 3,637 | require 'spec_helper'
include Deterministic
describe Deterministic::Option do
include Deterministic::Prelude::Option
None = Deterministic::Prelude::Option::None
specify { expect(described_class::Some.new(0)).to be_a described_class::Some }
specify { expect(described_class::Some.new(0)).to be_a described_clas... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/lib/deterministic/result_spec.rb | Ruby | mit | 186 | master | 2,275 | require 'spec_helper'
describe Deterministic::Result do
include Deterministic::Prelude::Result
it "can't call Result#new directly" do
expect { described_class.new(1)}
.to raise_error(NoMethodError, "private method `new' called for Deterministic::Result:Class")
end
it "fmap" do
expect(Success(1).fm... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/lib/deterministic/sequencer_spec.rb | Ruby | mit | 186 | master | 16,190 | require 'spec_helper'
describe Deterministic::Sequencer do
include Deterministic::Prelude::Result
let(:test_class) { Class.new { include Deterministic::Sequencer } }
let(:test_instance) { test_class.new }
let(:arbitrary_success) { Success(double) }
# This mock method makes #arbitrary_success available with... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/lib/deterministic/currify_spec.rb | Ruby | mit | 186 | master | 1,507 | require 'spec_helper'
module Deterministic
module Currify
module ClassMethods
def currify(*names)
names.each { |name|
unbound_method = instance_method(name)
define_method(name) { |*args|
curried_method = unbound_method.bind(self).to_proc.curry
curried_me... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/lib/deterministic/null_spec.rb | Ruby | mit | 186 | master | 1,296 | require "spec_helper"
require "deterministic/null"
describe Null do
it "Null is a Singleton" do
expect(Null.instance).to be_a Null
expect { Null.new }.to raise_error(NoMethodError, "private method `new' called for Null:Class")
end
it "explicit conversions" do
expect(Null.to_s).to eq 'Null'
expec... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/lib/deterministic/either_spec.rb | Ruby | mit | 186 | master | 698 | require 'spec_helper'
describe Deterministic::Either do
include Deterministic
Either = Deterministic::Either
it "+ does not change operands" do
l = Left(1)
r = Right(2)
either = l + r
expect(l).to eq Left(1)
expect(r).to eq Right(2)
expect(either).to eq Either.new([1], [2])
end
it ... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/lib/deterministic/monad_axioms.rb | Ruby | mit | 186 | master | 1,139 | shared_examples 'a Monad' do
describe 'axioms' do
it '1st monadic law: left-identity' do
f = ->(value) { monad.new(value + 1) }
expect(
monad.new(1).bind do |value|
f.(value)
end
).to eq f.(1)
end
it '2nd monadic law: right-identy - new and bind do not change t... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/lib/deterministic/protocol_spec.rb | Ruby | mit | 186 | master | 816 | require 'spec_helper'
require 'deterministic/protocol'
module Monoid
extend Deterministic::Protocol
Deterministic::protocol(M) {
fn empty() => M
fn(append(a => M, b => M) => M) { |a, b|
a + b
}
}
Int = Deterministic::instance(Monoid, M => Integer) {
def empty()
0
end
def... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/lib/deterministic/maybe_spec.rb | Ruby | mit | 186 | master | 468 | require 'spec_helper'
require 'deterministic/maybe'
describe 'maybe' do
it "does something" do
expect(Maybe(nil).foo).to be_null
expect(Maybe(nil).foo.bar.baz).to be_null
expect(Maybe(nil).fetch(:a)).to be_null
expect(Maybe(1)).to be_some
expect(Maybe({a: 1}).fetch(:a)).to eq 1
expect(Maybe({... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/lib/deterministic/monad_spec.rb | Ruby | mit | 186 | master | 1,416 | require 'spec_helper'
require_relative 'monad_axioms'
describe Deterministic::Monad do
class Identity
include Deterministic::Monad
end
let(:monad) { Identity }
it_behaves_like 'a Monad' do
# let(:monad) { monad }
end
specify { expect(Identity.new(1).inspect).to eq 'Identity(1)' }
specify { ex... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/lib/deterministic/class_mixin_spec.rb | Ruby | mit | 186 | master | 463 | require 'spec_helper'
describe 'Class Mixin' do
describe 'try' do
module MyApp
class Thing
include Deterministic::Prelude::Result
def run
Success(11) >> method(:double)
end
def double(num)
Success(num * 2)
end
end
end
it "cleanly ... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/lib/deterministic/result/success_spec.rb | Ruby | mit | 186 | master | 1,476 | require 'spec_helper'
require_relative '../monad_axioms'
require_relative 'result_shared'
describe Deterministic::Result::Success do
include Deterministic::Prelude::Result
it_behaves_like 'a Monad' do
let(:monad) { described_class }
end
subject { described_class.new(1) }
specify { expect(subject).to b... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/lib/deterministic/result/result_shared.rb | Ruby | mit | 186 | master | 657 | shared_examples 'Result' do
let(:result_name) { described_class.name.split("::")[-1]}
specify { expect(subject.value).to eq 1 }
specify { expect(result.new(subject)).to eq result.new(1) }
it "#fmap" do
expect(result.new(1).fmap { |e| e + 1 }).to eq result.new(2)
end
it "#bind" do
expect(result.new... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/lib/deterministic/result/failure_spec.rb | Ruby | mit | 186 | master | 2,406 | require 'spec_helper'
require_relative '../monad_axioms'
require_relative 'result_shared'
describe Deterministic::Result::Failure do
include Deterministic::Prelude::Result
it_behaves_like 'a Monad' do
let(:monad) { described_class }
end
subject { described_class.new(1) }
specify { expect(subject).to b... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/lib/deterministic/result/result_map_spec.rb | Ruby | mit | 186 | master | 3,305 | require 'spec_helper'
describe Deterministic::Result do
include Deterministic::Prelude::Result
context ">> (map)" do
specify { expect(Success(0).map { |n| Success(n + 1) }).to eq Success(1) }
specify { expect(Failure(0).map { |n| Success(n + 1) }).to eq Failure(0) }
it "Failure stops execution" do
... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/lib/deterministic/core_ext/result_spec.rb | Ruby | mit | 186 | master | 656 | require "spec_helper"
require "deterministic"
require "deterministic/core_ext/result"
describe Deterministic::CoreExt::Result do
include Deterministic::Prelude::Result
it "does something" do
h = {}
h.extend(Deterministic::CoreExt::Result)
expect(h.success?).to be_falsey
expect(h.failure?).to be_fa... |
github | pzol/deterministic | https://github.com/pzol/deterministic | spec/lib/deterministic/core_ext/object/either_spec.rb | Ruby | mit | 186 | master | 295 | require "spec_helper"
require "deterministic/core_ext/object/result"
describe Deterministic::CoreExt::Result, "object", isolate: true do
it "does something" do
h = {a: 1}
expect(h.success?).to be_falsey
expect(h.failure?).to be_falsey
expect(h.result?).to be_falsey
end
end |
github | pzol/deterministic | https://github.com/pzol/deterministic | lib/deterministic.rb | Ruby | mit | 186 | master | 305 | require "deterministic/version"
module Deterministic; end
require 'deterministic/monad'
require 'deterministic/match'
require 'deterministic/enum'
require 'deterministic/result'
require 'deterministic/option'
require 'deterministic/either'
require 'deterministic/null'
require 'deterministic/sequencer' |
github | pzol/deterministic | https://github.com/pzol/deterministic | lib/deterministic/monad.rb | Ruby | mit | 186 | master | 2,319 | module Deterministic
module Monad
class NotMonadError < StandardError; end
# Basicly the `pure` function
def initialize(init)
@value = join(init)
end
# If the passed value is monad already, get the value to avoid nesting
# M[M[A]] is equivalent to M[A]
def join(other)
if othe... |
github | pzol/deterministic | https://github.com/pzol/deterministic | lib/deterministic/null.rb | Ruby | mit | 186 | master | 965 | # The simplest NullObject there can be
class Null
class << self
def method_missing(m, *args)
if m == :new
super
else
Null.instance
end
end
def instance
@instance ||= new([])
end
def null?
true
end
def some?
false
end
def mimic... |
github | pzol/deterministic | https://github.com/pzol/deterministic | lib/deterministic/sequencer.rb | Ruby | mit | 186 | master | 4,116 | require 'delegate'
module Deterministic
module Sequencer
InvalidSequenceError = Class.new(StandardError)
module Operation
Get = Struct.new(:block, :name)
Let = Struct.new(:block, :name)
AndThen = Struct.new(:block)
Observe = Struct.new(:block)
AndYield = Struct.new(:block)
... |
github | pzol/deterministic | https://github.com/pzol/deterministic | lib/deterministic/result.rb | Ruby | mit | 186 | master | 2,094 | module Deterministic
Result = Deterministic::enum {
Success(:s)
Failure(:f)
}
class Result
class << self
def try!
begin
Success.new(yield)
rescue => err
Failure.new(err)
end
end
end
end
Deterministic::impl(Result) {
def map(proc=nil... |
github | pzol/deterministic | https://github.com/pzol/deterministic | lib/deterministic/match.rb | Ruby | mit | 186 | master | 1,870 | # TODO: remove dead code
module Deterministic
module PatternMatching
def match(context=nil, &block)
context ||= block.binding.eval('self') # the instance containing the match block
match = binding.eval('self.class::Match.new(self, context)') # the class defining the Match
match.instance_eval &b... |
github | pzol/deterministic | https://github.com/pzol/deterministic | lib/deterministic/either.rb | Ruby | mit | 186 | master | 659 | module Deterministic
class Either
include Monad
class << self
public :new
end
def initialize(left=[], right=[])
@left, @right = left, right
end
attr_reader :left, :right
def +(other)
raise Deterministic::Monad::NotMonadError, "Expected an Either, got #{other.class}" un... |
github | pzol/deterministic | https://github.com/pzol/deterministic | lib/deterministic/protocol.rb | Ruby | mit | 186 | master | 2,796 | module Deterministic
class ProtocolBuilder
def initialize(typevar, block)
@typevar, @block = typevar, block
@protocol = Class.new
end
def build
instance_exec(&@block)
@protocol
end
def method_missing(m, *args)
[m, args]
end
Signature = Struct.new(:name, :p... |
github | pzol/deterministic | https://github.com/pzol/deterministic | lib/deterministic/option.rb | Ruby | mit | 186 | master | 1,533 | module Deterministic
Option = Deterministic::enum {
Some(:s)
None()
}
class Option
class << self
def some?(expr)
to_option(expr) { expr.nil? }
end
def any?(expr)
to_option(expr) { expr.nil? || (expr.respond_to?(:empty?) && expr.empty?) }
end
def to_opti... |
github | pzol/deterministic | https://github.com/pzol/deterministic | lib/deterministic/enum.rb | Ruby | mit | 186 | master | 5,839 | module Deterministic
module Enum
class MatchError < StandardError; end
end
class EnumBuilder
def initialize(parent)
@parent = parent
end
class DataType
module AnyEnum
include Deterministic::Monad
def match(&block)
parent.match(self, &block)
end
... |
github | pzol/deterministic | https://github.com/pzol/deterministic | lib/deterministic/core_ext/result.rb | Ruby | mit | 186 | master | 291 | module Deterministic
module CoreExt
module Result
def success?
self.is_a? Deterministic::Result::Success
end
def failure?
self.is_a? Deterministic::Result::Failure
end
def result?
success? || failure?
end
end
end
end |
github | wardencommunity/sinatra_warden | https://github.com/wardencommunity/sinatra_warden | sinatra_warden.gemspec | Ruby | mit | 186 | master | 1,549 | # Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-
require File.expand_path("../lib/sinatra_warden/version", __FILE__)
Gem::Specification.new do |s|
s.name = %q{sinatra_warden}
s.version = SinatraWarden::VER... |
github | wardencommunity/sinatra_warden | https://github.com/wardencommunity/sinatra_warden | Rakefile | Ruby | mit | 186 | master | 538 | require "bundler/gem_tasks"
begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new('coverage') do |spec|
spec.rspec_opts = '-I lib -I spec'
ENV['COVERAGE'] = "true"
end
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.rspec_opts = '-I lib -I spec'
end
task default: :spec
rescue LoadErr... |
github | wardencommunity/sinatra_warden | https://github.com/wardencommunity/sinatra_warden | lib/sinatra_warden.rb | Ruby | mit | 186 | master | 362 | require 'warden'
require File.join(File.dirname(__FILE__), 'sinatra_warden', 'sinatra')
Warden::Manager.before_failure do |env, opts|
# Sinatra is very sensitive to the request method
# since authentication could fail on any type of method, we need
# to set it for the failure app so it is routed to the correct b... |
github | wardencommunity/sinatra_warden | https://github.com/wardencommunity/sinatra_warden | lib/sinatra_warden/sinatra.rb | Ruby | mit | 186 | master | 4,380 | require 'sinatra/base'
module Sinatra
module Warden
module Helpers
# The main accessor to the warden middleware
def warden
request.env['warden']
end
# Return session info
#
# @param [Symbol] the scope to retrieve session info for
def session_info(scope=nil)
... |
github | wardencommunity/sinatra_warden | https://github.com/wardencommunity/sinatra_warden | spec/spec_helper.rb | Ruby | mit | 186 | master | 1,255 | $LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
ENV['RACK_ENV'] ||= 'test'
require 'sinatra_warden'
require 'rspec'
require 'dm-core'
require 'dm-migrations'
if ENV['COVERAGE']
require 'simplecov'
SimpleCov.start
end
DataMapper.setup(:default, 'sqlit... |
github | wardencommunity/sinatra_warden | https://github.com/wardencommunity/sinatra_warden | spec/sinatra_warden_spec.rb | Ruby | mit | 186 | master | 6,275 | require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "Sinatra::Warden" do
include Warden::Test::Helpers
before(:each) do
@user = User.create(:email => 'justin.smestad@gmail.com', :password => 'thedude')
end
after{ Warden.test_reset! }
def registered_user
User.first(:email => '... |
github | jaswope/rack-reverse-proxy | https://github.com/jaswope/rack-reverse-proxy | Rakefile | Ruby | mit | 186 | master | 202 | require 'rubygems'
require 'rake'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = 'spec/**/*_spec.rb'
end
task :default => :spec |
github | jaswope/rack-reverse-proxy | https://github.com/jaswope/rack-reverse-proxy | rack-reverse-proxy.gemspec | Ruby | mit | 186 | master | 981 | Gem::Specification.new do |s|
s.name = 'rack-reverse-proxy'
s.version = "0.8.1"
s.authors = ["Jon Swope", "Ian Ehlert", "Roman Ernst"]
s.description = 'A Rack based reverse proxy for basic needs. Useful for testing or in cases where webserver configuration is unavailable.'
s.email ... |
github | jaswope/rack-reverse-proxy | https://github.com/jaswope/rack-reverse-proxy | spec/spec_helper.rb | Ruby | mit | 186 | master | 995 | require 'rubygems'
require 'rack/reverse_proxy'
require 'rspec'
require 'rack/test'
require 'webmock/rspec'
# Patch HttpStreamingResponse to make rack-proxy compatible with webmocks
require 'support/http_streaming_response_patch'
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
$LOAD_PATH << File.join(File... |
github | jaswope/rack-reverse-proxy | https://github.com/jaswope/rack-reverse-proxy | spec/support/http_streaming_response_patch.rb | Ruby | mit | 186 | master | 667 | ##
# Patch HttpStreamingResponse
# in order to support webmocks and still use rack-proxy
#
# Inspired by @ehlertij commits on sportngin/rack-proxy:
# 616574e452fa731f5427d2ff2aff6823fcf28bde
# d8c377f7485997b229ced23c33cfef87d3fb8693
# 75b446a26ceb519ddc28f38b33309e9a2799074c
#
module Rack
class HttpStreamingRespons... |
github | jaswope/rack-reverse-proxy | https://github.com/jaswope/rack-reverse-proxy | spec/rack/reverse_proxy_spec.rb | Ruby | mit | 186 | master | 11,077 | require 'spec_helper'
RSpec.describe Rack::ReverseProxy do
include Rack::Test::Methods
def app
Rack::ReverseProxy.new
end
def dummy_app
lambda { |env| [200, {}, ['Dummy App']] }
end
describe "as middleware" do
def app
Rack::ReverseProxy.new(dummy_app) do
reverse_proxy '/test', ... |
github | jaswope/rack-reverse-proxy | https://github.com/jaswope/rack-reverse-proxy | lib/rack/reverse_proxy.rb | Ruby | mit | 186 | master | 4,527 | require 'net/http'
require 'net/https'
require "rack-proxy"
require "rack/reverse_proxy_matcher"
require "rack/exception"
module Rack
class ReverseProxy
include NewRelic::Agent::Instrumentation::ControllerInstrumentation if defined? NewRelic
def initialize(app = nil, &b)
@app = app || lambda {|env| [4... |
github | jaswope/rack-reverse-proxy | https://github.com/jaswope/rack-reverse-proxy | lib/rack/reverse_proxy_matcher.rb | Ruby | mit | 186 | master | 1,337 | module Rack
class ReverseProxyMatcher
def initialize(matcher,url=nil,options)
@default_url=url
@url=url
@options=options
if matcher.kind_of?(String)
@matcher = /^#{matcher.to_s}/
elsif matcher.respond_to?(:match)
@matcher = matcher
else
raise "Invalid M... |
github | jaswope/rack-reverse-proxy | https://github.com/jaswope/rack-reverse-proxy | lib/rack/exception.rb | Ruby | mit | 186 | master | 589 | module Rack
class GenericProxyURI < Exception
attr_reader :url
def intialize(url)
@url = url
end
def to_s
%Q(Your URL "#{@url}" is too generic. Did you mean "http://#{@url}"?)
end
end
class AmbiguousProxyMatch < Exception
attr_reader :path, :matches
def initialize(path, ... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | Gemfile | Ruby | mit | 186 | main | 567 | source 'http://rubygems.org'
# Declare your gem's dependencies in prawn-svg.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec
# Declare any dependencies that are still in development here instead of in
... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | Rakefile | Ruby | mit | 186 | main | 496 | #!/usr/bin/env rake
require 'bundler/gem_tasks'
begin
require 'rdoc/task'
rescue LoadError
require 'rdoc/rdoc'
require 'rake/rdoctask'
RDoc::Task = Rake::RDocTask
end
RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'prawn-svg documentation'
rdoc.options << '--line-numbers'
rdoc... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | prawn-svg.gemspec | Ruby | mit | 186 | main | 1,031 | require File.expand_path('lib/prawn/svg/version', __dir__)
Gem::Specification.new do |gem|
gem.name = 'prawn-svg'
gem.version = Prawn::SVG::VERSION
gem.summary = 'SVG renderer for Prawn PDF library'
gem.description = <<-DESC.strip
This gem allows you to render SVG directly into a PDF using the 'prawn' gem.... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn-svg.rb | Ruby | mit | 186 | main | 1,541 | require 'rexml/document'
require 'prawn'
require 'prawn/svg/version'
require 'css_parser'
require 'prawn/svg/font_registry'
require 'prawn/svg/font_metrics'
require 'prawn/svg/calculators/arc_to_bezier_curve'
require 'prawn/svg/calculators/aspect_ratio'
require 'prawn/svg/calculators/document_sizing'
require 'prawn/... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/interface.rb | Ruby | mit | 186 | main | 1,978 | #
# Prawn::SVG::Interface makes a Prawn::SVG::Document instance, uses that object to parse the supplied
# SVG into Prawn-compatible method calls, and then calls the Prawn methods.
#
module Prawn
module SVG
class Interface
VALID_OPTIONS = %i[
at position vposition width height cache_images enable_web... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/url_loader.rb | Ruby | mit | 186 | main | 1,031 | class Prawn::SVG::UrlLoader
Error = Class.new(StandardError)
attr_reader :enable_cache, :loaders
def initialize(enable_cache: false, enable_web: true, enable_file_with_root: nil)
@url_cache = {}
@enable_cache = enable_cache
@loaders = []
loaders << Prawn::SVG::Loaders::Data.new
loaders << P... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/font.rb | Ruby | mit | 186 | main | 479 | module Prawn::SVG
class Font
attr_reader :name, :weight, :style, :stretch
def initialize(name, weight, style, stretch = nil)
@name = name
@weight = weight
@style = style
@stretch = stretch
end
def subfamily
parts = []
parts << stretch if stretch && stretch != :nor... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/pdfmatrix.rb | Ruby | mit | 186 | main | 936 | module Prawn::SVG::PDFMatrix
def load_matrix(matrix)
if matrix.is_a?(Matrix) && matrix.row_count == 3 && matrix.column_count == 3
matrix
elsif matrix.is_a?(Array) && matrix.length == 6
Matrix[
[matrix[0], matrix[2], matrix[4]],
[matrix[1], matrix[3], matrix[5]],
[0.0, 0.0, ... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/elements.rb | Ruby | mit | 186 | main | 2,084 | module Prawn::SVG::Elements
COMMA_WSP_REGEXP = /(?:\s+,?\s*|,\s*)/.freeze
end
require 'prawn/svg/elements/call_duplicator'
require 'prawn/svg/elements/bbox_scaling'
%w[base direct_render_base root anchor container switch clip_path mask viewport text text_component text_node text_path line polyline polygon circle el... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/state.rb | Ruby | mit | 186 | main | 575 | class Prawn::SVG::State
attr_accessor :text, :preserve_space,
:opacity, :last_fill_opacity, :last_stroke_opacity,
:stroke_width,
:computed_properties,
:viewport_sizing,
:inside_use, :inside_clip_path, :anchor_href
def initialize
@stroke_width = 1
@opacity = 1
@last_fill_opacity = 1
... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/gradient_renderer.rb | Ruby | mit | 186 | main | 10,280 | class Prawn::SVG::GradientRenderer
include Prawn::SVG::PDFMatrix
@mutex = Mutex.new
@counter = 0
def initialize(prawn, draw_type, from:, to:, stops:, matrix: nil, r1: nil, r2: nil, wrap: :pad, bounding_box: nil)
@prawn = prawn
@draw_type = draw_type
@from = from
@to = to
@bounding_box = bo... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/document.rb | Ruby | mit | 186 | main | 5,439 | require 'tempfile'
class Prawn::SVG::Document
Error = Class.new(StandardError)
InvalidSVGData = Class.new(Error)
DEFAULT_FALLBACK_FONT_NAME = 'Times-Roman'.freeze
class << self
attr_accessor :enable_web_requests_warned
end
# An +Array+ of warnings that occurred while parsing the SVG data.
attr_rea... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/ttf.rb | Ruby | mit | 186 | main | 2,920 | class Prawn::SVG::TTF
SFNT_VERSION_STRINGS = ["\x00\x01\x00\x00", 'true', 'typ1'].freeze
LANGUAGE_IDS = [0, 0x409].freeze # English, US English
UTF_16BE_PLATFORM_IDS = [0, 3].freeze # Unicode, Microsoft
attr_reader :family, :subfamily, :weight_class
def initialize(filename)
load_data_from_file(filename)... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/font_registry.rb | Ruby | mit | 186 | main | 10,416 | module Prawn::SVG
class FontRegistry
GENERIC_CSS_FONT_MAPPING = {
'serif' => 'Times-Roman',
'sans-serif' => 'Helvetica',
'cursive' => 'Times-Roman',
'fantasy' => 'Times-Roman',
'monospace' => 'Courier'
}.freeze
FONT_WEIGHT_FALLBACKS = {
thin: :extrali... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/gradients.rb | Ruby | mit | 186 | main | 1,365 | module Prawn::SVG
class Gradients
def initialize(document)
@document = document
@gradients_by_id = {}
end
def [](id)
id &&= id.strip
return unless id && id != ''
if (element = @gradients_by_id[id])
element
elsif (raw_element = find_raw_gradient_element_by_id(i... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/paint.rb | Ruby | mit | 186 | main | 1,872 | module Prawn::SVG
Paint = Struct.new(:color, :url) do
class << self
def none
new(:none, nil)
end
def black
new(Color.black, nil)
end
def parse(value)
case CSS::ValuesParser.parse(value)
in [['url', [url]]]
# If there is no fallback color, a... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/length.rb | Ruby | mit | 186 | main | 1,041 | module Prawn::SVG
Length = Struct.new(:value, :unit)
class Length
REGEXP = /\A([+-]?\d*(?:\.\d+)?)(em|rem|ex|px|in|cm|mm|pt|pc)?\z/i.freeze
def self.parse(value, positive_only: false)
if (matches = value.match(REGEXP))
number = Float(matches[1], exception: false)
new(number, matches[... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/properties.rb | Ruby | mit | 186 | main | 12,370 | module Prawn::SVG
class Properties
Config = Struct.new(:default, :inheritable?, :valid_values, :attr, :ivar, :id)
EM = 16
STRETCH_ORDER = %w[
ultra-condensed extra-condensed condensed semi-condensed normal
semi-expanded expanded extra-expanded ultra-expanded
].freeze
FONT_SIZES = {
... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/extension.rb | Ruby | mit | 186 | main | 823 | module Prawn
module SVG
module Extension
#
# Draws an SVG document into the PDF.
#
# +options+ must contain the key :at, which takes a tuple of x and y co-ordinates.
#
# +options+ can optionally contain the key :width or :height. If both are
# specified, only :width will... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/font_metrics.rb | Ruby | mit | 186 | main | 4,287 | class Prawn::SVG::FontMetrics
class << self
# Default x-height as a fraction of font size (typical for most fonts)
DEFAULT_X_HEIGHT_RATIO = 0.5
def x_height_in_points(pdf, font_size)
x_height = cache(:x_height, pdf.font) { calculate_x_height_ratio(pdf) }
x_height * font_size
end
def ... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/funciri.rb | Ruby | mit | 186 | main | 236 | Prawn::SVG::FuncIRI = Struct.new(:url) do
def self.parse(value)
case Prawn::SVG::CSS::ValuesParser.parse(value)
in [['url', [url]]]
new(url.strip)
else
nil
end
end
def to_s
"url(#{url})"
end
end |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/pattern_renderer.rb | Ruby | mit | 186 | main | 3,423 | class Prawn::SVG::PatternRenderer
include Prawn::SVG::PDFMatrix
def initialize(prawn, draw_type, renderer, tile_x:, tile_y:, tile_width:, tile_height:, transform:, calls:)
@prawn = prawn
@draw_type = draw_type
@renderer = renderer
@tile_x = tile_x
@tile_y = tile_y
@tile_width = tile_width
... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/pathable.rb | Ruby | mit | 186 | main | 4,346 | module Prawn::SVG::Pathable
Move = Struct.new(:destination)
Close = Struct.new(:destination)
Line = Struct.new(:destination)
Curve = Struct.new(:destination, :point1, :point2)
def bounding_box
points = commands.map { |command| translate(command.destination) }
x1, x2 = points.map(&:first).minmax
y... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/link_renderer.rb | Ruby | mit | 186 | main | 903 | class Prawn::SVG::LinkRenderer
include Prawn::SVG::PDFMatrix
def initialize(href, bounding_box)
@href = href
@bounding_box = bounding_box
end
def render(prawn)
prawn.link_annotation(transformed_bounding_box(prawn), {
Border: [0, 0, 0],
A: { Type: :Action, S: :URI, URI: PDF::Core::... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/renderer.rb | Ruby | mit | 186 | main | 7,571 | module Prawn
module SVG
class Renderer
attr_reader :prawn, :document, :options
#
# Creates a Prawn::SVG object.
#
# +data+ is the SVG data to convert. +prawn+ is your Prawn::Document object.
#
# See README.md for the options that can be passed to this method.
#
... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/percentage.rb | Ruby | mit | 186 | main | 488 | Prawn::SVG::Percentage = Struct.new(:value)
class Prawn::SVG::Percentage
REGEXP = /\A([+-]?\d*(?:\.\d+)?)%\z/i.freeze
def self.parse(value, positive_only: false)
if (matches = value.match(REGEXP))
number = Float(matches[1], exception: false)
new(number) if number && (!positive_only || number >= 0)... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/color.rb | Ruby | mit | 186 | main | 7,839 | class Prawn::SVG::Color
CMYK = Struct.new(:value) do
def to_cmyk
self
end
end
RGB = Struct.new(:value) do
def to_rgb
[value[0..1], value[2..3], value[4..5]].map { |h| h.to_i(16) / 255.0 }
end
def to_cmyk
r, g, b = rgb = to_rgb
k = 1 - rgb.max
if k == 1
C... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/ttc.rb | Ruby | mit | 186 | main | 856 | class Prawn::SVG::TTC
TTC_TAG = 'ttcf'.freeze
attr_reader :fonts
def initialize(filename)
@fonts = []
load_data_from_file(filename)
end
private
def load_data_from_file(filename)
File.open(filename, 'rb') do |f|
tag = f.read(4)
next unless tag == TTC_TAG
_major, _minor = f.... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/transform_parser.rb | Ruby | mit | 186 | main | 2,309 | module Prawn::SVG::TransformParser
include Prawn::SVG::PDFMatrix
def parse_transform_attribute(transform, space: :pdf)
matrix = Matrix.identity(3)
flip = space == :svg ? 1.0 : -1.0
parse_css_method_calls(transform).each do |name, arguments|
case name
when 'translate'
x, y = argume... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/loaders/file.rb | Ruby | mit | 186 | main | 3,351 | require 'addressable/uri'
#
# Load a file from disk.
#
# WINDOWS
# =======
# Windows is supported, but must use URLs in the modern structure like:
# file:///x:/path/to/the/file.png
# or as a relative path:
# directory/file.png
# or as an absolute path from the current drive:
# /path/to/the/file.png
#
# Ruby's UR... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/loaders/web.rb | Ruby | mit | 186 | main | 437 | require 'net/http'
module Prawn::SVG::Loaders
class Web
def from_url(url)
uri = build_uri(url)
perform_request(uri) if uri && %w[http https].include?(uri.scheme)
end
private
def build_uri(url)
URI(url)
rescue URI::InvalidURIError
end
def perform_request(uri)
Ne... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/loaders/data.rb | Ruby | mit | 186 | main | 458 | module Prawn::SVG::Loaders
class Data
REGEXP = %r{\Adata:image/(png|jpeg|svg\+xml);base64(;[a-z0-9]+)*,}i.freeze
def from_url(url)
return if url[0..4].downcase != 'data:'
matches = url.match(REGEXP)
if matches.nil?
raise Prawn::SVG::UrlLoader::Error,
'prawn-svg only suppo... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/css/font_family_parser.rb | Ruby | mit | 186 | main | 877 | module Prawn::SVG::CSS
class FontFamilyParser
def self.parse(string)
in_quote = nil
in_escape = false
current = nil
fonts = []
string.each_char do |char|
if in_escape
in_escape = false
if current.nil?
current = char
fonts << curren... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/css/selector_parser.rb | Ruby | mit | 186 | main | 5,360 | module Prawn::SVG::CSS
class SelectorParser
def self.parse(selector)
tokens = tokenise_css_selector(selector) or return
result = [{}]
part = nil
tokens.each do |token|
case token
when Modifier
part = token.type
result.last[part] ||= part == :name ? +''... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/css/font_parser.rb | Ruby | mit | 186 | main | 1,121 | module Prawn::SVG::CSS
class FontParser
def self.parse(string)
in_quote = nil
in_escape = false
in_list_delimiter = false
current = nil
values = []
string.each_char do |char|
if in_escape
in_escape = false
if current.nil?
current = char
... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/css/font_face_parser.rb | Ruby | mit | 186 | main | 1,677 | module Prawn::SVG::CSS
class FontFaceParser
SUPPORTED_FORMATS = %w[truetype opentype].freeze
class << self
def parse_src(src)
split_sources(src).filter_map { |entry| parse_source_entry(entry.strip) }
end
private
def split_sources(value)
entries = []
current =... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/css/stylesheets.rb | Ruby | mit | 186 | main | 7,275 | module Prawn::SVG::CSS
class Stylesheets
attr_reader :css_parser, :root, :media, :font_face_rules
def initialize(css_parser, root, media = :all, url_loader: nil, warnings: [])
@css_parser = css_parser
@root = root
@media = media
@warnings = warnings
@font_face_rules = []
... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/css/values_parser.rb | Ruby | mit | 186 | main | 1,672 | module Prawn::SVG::CSS
class ValuesParser
class << self
def parse(values)
result = []
while values
value, remainder = parse_next(values)
break unless value
result << value
values = remainder
end
result
end
private
... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/attributes/mask.rb | Ruby | mit | 186 | main | 495 | module Prawn::SVG::Attributes::Mask
def parse_mask_attribute_and_call
return unless (mask = properties.mask)
return if mask == 'none'
mask_element = extract_element_from_url_id_reference(mask, 'mask')
if mask_element.nil?
document.warnings << 'Could not resolve mask URI to a mask element'
... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/attributes/opacity.rb | Ruby | mit | 186 | main | 1,401 | module Prawn::SVG::Attributes::Opacity
def parse_opacity_attributes_and_call
# The opacity property is not inherited, but the opacity applies to all children underneath the element.
#
# Having an opacity property on a parent, and again on a child, multiplies the parent and child's opacities
# when dra... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/attributes/stroke.rb | Ruby | mit | 186 | main | 1,660 | module Prawn::SVG::Attributes::Stroke
CAP_STYLE_TRANSLATIONS = { 'butt' => :butt, 'round' => :round, 'square' => :projecting_square }.freeze
JOIN_STYLE_TRANSLATIONS = { 'miter' => :miter, 'round' => :round, 'bevel' => :bevel }.freeze
def parse_stroke_attributes_and_call
if (width_string = properties.stroke_w... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/attributes/clip_path.rb | Ruby | mit | 186 | main | 1,769 | module Prawn::SVG::Attributes::ClipPath
def parse_clip_path_attribute_and_call
return unless (clip_path = properties.clip_path)
return if clip_path == 'none'
clip_path_element = extract_element_from_url_id_reference(clip_path, 'clipPath')
if clip_path_element.nil?
document.warnings << 'Could n... |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/attributes/space.rb | Ruby | mit | 186 | main | 228 | module Prawn::SVG::Attributes::Space
def parse_xml_space_attribute
case attributes['xml:space']
when 'preserve'
state.preserve_space = true
when 'default'
state.preserve_space = false
end
end
end |
github | mogest/prawn-svg | https://github.com/mogest/prawn-svg | lib/prawn/svg/attributes/transform.rb | Ruby | mit | 186 | main | 386 | module Prawn::SVG::Attributes::Transform
def parse_transform_attribute_and_call
# Some elements do not support transforms
return unless transformable?
return unless (transform = attributes['transform'])
matrix = matrix_for_pdf(parse_transform_attribute(transform))
add_call_and_enter 'transformati... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.