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
project-eutopia/keisan
https://github.com/project-eutopia/keisan
spec/keisan/ast/time_spec.rb
Ruby
mit
87
master
5,710
require "spec_helper" RSpec.describe Keisan::AST::Time do describe "is_constant?" do it "is true" do time = Keisan::AST.parse("time(2018)").evaluate expect(time.is_constant?).to eq true end end describe "evaluate" do it "reduces to a time when adding numbers" do ast = Keisan::AST.p...
github
project-eutopia/keisan
https://github.com/project-eutopia/keisan
spec/keisan/ast/plus_spec.rb
Ruby
mit
87
master
515
require "spec_helper" RSpec.describe Keisan::AST::Plus do it "is left associative" do ast = Keisan::AST.parse("x + 5 + f(y) + (1+2) + zzz") expect(ast.to_s).to eq ("(((x+5)+f(y))+(1+2))+zzz") simple = ast.simplified expect(simple).to be_a(Keisan::AST::Plus) expect(simple.children.map(&:class)).t...
github
project-eutopia/keisan
https://github.com/project-eutopia/keisan
spec/keisan/ast/string_spec.rb
Ruby
mit
87
master
2,858
require "spec_helper" RSpec.describe Keisan::AST::String do describe "is_constant?" do it "is true" do expect(Keisan::AST::String.new('foo').is_constant?).to eq true end end describe "evaluate" do it "reduces to a single string when using plus to concatenate" do ast = Keisan::AST.parse("...
github
project-eutopia/keisan
https://github.com/project-eutopia/keisan
spec/keisan/ast/list_spec.rb
Ruby
mit
87
master
1,665
require "spec_helper" RSpec.describe Keisan::AST::List do describe "is_constant?" do it "is true when all elements are constant" do list = [[1,"x"],[2,"y",true]].to_node expect(list.is_constant?).to eq true end it "is false if one element is not constant" do list = described_class.new(...
github
project-eutopia/keisan
https://github.com/project-eutopia/keisan
spec/keisan/ast/assignment_spec.rb
Ruby
mit
87
master
18,630
require "spec_helper" RSpec.describe Keisan::AST::Assignment do describe "evaluate" do context "nested groups" do it "evaluates to right hand side of assignment" do context = Keisan::Context.new ast = Keisan::AST.parse("5 + (x = 3)") expect(context.has_variable?("x")).to eq false ...
github
project-eutopia/keisan
https://github.com/project-eutopia/keisan
spec/keisan/ast/number_spec.rb
Ruby
mit
87
master
8,230
require "spec_helper" RSpec.describe Keisan::AST::Number do describe "is_constant?" do it "is true" do expect(Keisan::AST::Number.new(1).is_constant?).to eq true end end describe "evaluate" do it "reduces to a single number when using arithmetic operators" do ast = Keisan::AST.parse("1+2...
github
project-eutopia/keisan
https://github.com/project-eutopia/keisan
spec/keisan/ast/null_spec.rb
Ruby
mit
87
master
1,027
require "spec_helper" RSpec.describe Keisan::AST::Null do describe "is_constant?" do it "is true" do expect(Keisan::AST::Null.new.is_constant?).to eq true end end describe "logical operations" do it "can do == and != checks" do positive_equal = described_class.new.equal described...
github
project-eutopia/keisan
https://github.com/project-eutopia/keisan
spec/keisan/ast/cache_spec.rb
Ruby
mit
87
master
2,275
require "spec_helper" RSpec.describe Keisan::AST::Cache do describe "caching" do context "not frozen" do it "adds to the cache when calling #fetch_or_build" do cache = described_class.new expect(cache.instance_variable_get(:@cache)).to eq({}) expect(cache.has_key?("x+1")).to eq fal...
github
project-eutopia/keisan
https://github.com/project-eutopia/keisan
spec/keisan/ast/indexing_spec.rb
Ruby
mit
87
master
1,491
require "spec_helper" RSpec.describe Keisan::AST::Indexing do describe "evaluate" do it "reduces to the element when operating on list" do ast = Keisan::AST.parse("[2,4,6]") expect(ast.evaluate).to be_a(Keisan::AST::List) expect(ast.evaluate.value).to eq [2, 4, 6] ast = Keisan::AST.parse...
github
project-eutopia/keisan
https://github.com/project-eutopia/keisan
spec/keisan/ast/hash_spec.rb
Ruby
mit
87
master
1,689
require "spec_helper" RSpec.describe Keisan::AST::Hash do describe "is_constant?" do it "is true when all elements are constant" do hash = {"foo" => {"a" => 1, "b" => 2}, "bar" => {"c" => 3, "d" => 4}}.to_node expect(hash.is_constant?).to eq true end it "is false if one element is not consta...
github
project-eutopia/keisan
https://github.com/project-eutopia/keisan
spec/keisan/ast/cell_spec.rb
Ruby
mit
87
master
1,203
require "spec_helper" RSpec.describe Keisan::AST::Cell do let(:node) { Keisan::AST::Node.new } let(:cell) { described_class.new(node) } describe "delegation of methods" do %i(unbound_variables unbound_functions value evaluate simplify evaluate_assignments to_s).each do |method| it "delegates #{method}...
github
project-eutopia/keisan
https://github.com/project-eutopia/keisan
spec/keisan/ast/date_spec.rb
Ruby
mit
87
master
4,738
require "spec_helper" RSpec.describe Keisan::AST::Date do describe "is_constant?" do it "is true" do date = Keisan::AST.parse("date(2018, 11, 20)").evaluate expect(date.is_constant?).to eq true end end describe "evaluate" do it "reduces to a date when adding numbers" do ast = Keisa...
github
project-eutopia/keisan
https://github.com/project-eutopia/keisan
spec/keisan/ast/logical_spec.rb
Ruby
mit
87
master
3,640
require "spec_helper" RSpec.describe Keisan::AST::LogicalOperator do let(:calculator) { Keisan::Calculator.new } describe "evaluate" do it "raises error on base class" do expect{described_class.new(1).evaluate}.to raise_error(Keisan::Exceptions::NotImplementedError) expect{described_class.new(1).v...
github
project-eutopia/keisan
https://github.com/project-eutopia/keisan
spec/keisan/ast/multi_line_spec.rb
Ruby
mit
87
master
1,780
require "spec_helper" RSpec.describe Keisan::AST::MultiLine do describe "unbound_variables" do let(:context) { Keisan::Context.new } context "with empty context" do it "binds assigned variables" do ast = Keisan::AST.parse("x = 1; y = 2; x + y") expect(ast.unbound_variables(context)).to...
github
ankane/archer
https://github.com/ankane/archer
archer-rails.gemspec
Ruby
mit
87
master
595
require_relative "lib/archer/version" Gem::Specification.new do |spec| spec.name = "archer-rails" spec.version = Archer::VERSION spec.summary = "Rails console history for Heroku, Docker, and more" spec.homepage = "https://github.com/ankane/archer" spec.license = "MIT" spec....
github
ankane/archer
https://github.com/ankane/archer
lib/archer.rb
Ruby
mit
87
master
1,519
# dependencies require "active_support/core_ext/module/attribute_accessors" # modules require_relative "archer/engine" if defined?(Rails) require_relative "archer/irb" require_relative "archer/storage" require_relative "archer/version" module Archer autoload :Coder, "archer/coder" autoload :History, "archer/histo...
github
ankane/archer
https://github.com/ankane/archer
lib/archer/storage.rb
Ruby
mit
87
master
647
module Archer class Storage def load(user:) quietly do Archer::History.find_by(user: user)&.commands end rescue ActiveRecord::StatementInvalid raise "Create table to enable history" end def save(commands, user:) quietly do history = Archer::History.where(user: ...
github
ankane/archer
https://github.com/ankane/archer
lib/archer/coder.rb
Ruby
mit
87
master
286
require "json" module Archer module Coder def self.dump(value) JSON.generate(value) end def self.load(value) JSON.parse(value, {max_nesting: 1}) unless value.nil? rescue JSON::ParserError # previous format value.split("\n") end end end
github
ankane/archer
https://github.com/ankane/archer
lib/generators/archer/install_generator.rb
Ruby
mit
87
master
517
require "rails/generators/active_record" module Archer module Generators class InstallGenerator < Rails::Generators::Base include ActiveRecord::Generators::Migration source_root File.join(__dir__, "templates") def copy_migration migration_template "migration.rb", "db/migrate/create_arc...
github
ankane/archer
https://github.com/ankane/archer
test/test_helper.rb
Ruby
mit
87
master
634
require "bundler/setup" require "combustion" Bundler.require(:default) require "minitest/autorun" require "rails/command" require "rails/commands/console/console_command" require "irb" puts "Testing with IRB #{IRB::VERSION}" logger = ActiveSupport::Logger.new(ENV["VERBOSE"] ? STDOUT : nil) Combustion.path = "test/in...
github
ankane/archer
https://github.com/ankane/archer
test/archer_test.rb
Ruby
mit
87
master
1,485
require_relative "test_helper" class ArcherTest < Minitest::Test def setup Archer::History.delete_all end def test_tty stub_method(STDIN, :tty?, true) { setup_irb } assert_equal true, Archer.clear assert_equal 0, Archer::History.count run_commands(["1 + 2", "2 * 3"]) assert_equal tru...
github
ankane/archer
https://github.com/ankane/archer
test/install_generator_test.rb
Ruby
mit
87
master
418
require_relative "test_helper" require "rails/generators/test_case" require "generators/archer/install_generator" class InstallGeneratorTest < Rails::Generators::TestCase tests Archer::Generators::InstallGenerator destination File.expand_path("../tmp", __dir__) setup :prepare_destination def test_works r...
github
monterail/grape-rails-cache
https://github.com/monterail/grape-rails-cache
grape-rails-cache.gemspec
Ruby
mit
87
master
1,042
# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'grape/rails/cache/version' Gem::Specification.new do |spec| spec.name = "grape-rails-cache" spec.version = Grape::Rails::Cache::VERSION spec.authors = ["Tymon Tobolski"...
github
monterail/grape-rails-cache
https://github.com/monterail/grape-rails-cache
lib/grape/rails/cache.rb
Ruby
mit
87
master
2,237
require "grape/rails/cache/version" require "grape/rails/cache/formatter" module Grape module Rails module Cache extend ActiveSupport::Concern included do formatter :json, Grape::Rails::Cache::JsonFormatter helpers do def compare_etag(etag) etag = Digest::SHA1....
github
monterail/grape-rails-cache
https://github.com/monterail/grape-rails-cache
lib/grape/rails/cache/formatter.rb
Ruby
mit
87
master
317
module Grape module Rails module Cache # For maximum performance we are fetching string from redis and return them with no parsing at all module JsonFormatter def self.call(object, env) object.is_a?(String) ? object : MultiJson.dump(object) end end end end end
github
zverok/magic_cloud
https://github.com/zverok/magic_cloud
magic_cloud.gemspec
Ruby
mit
87
master
1,150
require './lib/magic_cloud/version' Gem::Specification.new do |s| s.name = 'magic_cloud' s.version = MagicCloud::VERSION s.authors = ['Victor Shepelev'] s.email = 'zverok.offline@gmail.com' s.description = <<-EOF Simple, pure-ruby library for making pretty Wordle-like clouds. It uses RMagick as grap...
github
zverok/magic_cloud
https://github.com/zverok/magic_cloud
lib/magic_cloud/cloud.rb
Ruby
mit
87
master
3,967
# frozen_string_literal: true require_relative 'rect' require_relative 'canvas' require_relative 'palettes' require_relative 'word' require_relative 'layouter' require_relative 'spriter' require_relative 'debug' module MagicCloud # Main word-cloud class. Takes words with sizes, returns image class Cloud # rubo...
github
zverok/magic_cloud
https://github.com/zverok/magic_cloud
lib/magic_cloud/layouter.rb
Ruby
mit
87
master
1,303
# frozen_string_literal: true require_relative 'collision_board' module MagicCloud # Main magic of magic cloud - layouting shapes without collisions. # Also, alongside with CollisionBoard - the slowest and # algorithmically trickiest part. class Layouter def initialize(w, h, options = {}) @board = ...
github
zverok/magic_cloud
https://github.com/zverok/magic_cloud
lib/magic_cloud/bit_matrix.rb
Ruby
mit
87
master
883
# frozen_string_literal: true module MagicCloud # Dead simple 2-dimensional "bit matrix", storing 1s and 0s. # Not memory effectife at all, but the fastest pure-Ruby solution # I've tried. class BitMatrix def initialize(width, height) @width, @height = width, height @bits = [0] * height*width ...
github
zverok/magic_cloud
https://github.com/zverok/magic_cloud
lib/magic_cloud/palettes.rb
Ruby
mit
87
master
952
# frozen_string_literal: true module MagicCloud PALETTES = { # Categorical colors from d3 # Source: https://github.com/d3/d3-scale/blob/master/README.md#category-scales category10: %w[ #1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf ], category20: %w[...
github
zverok/magic_cloud
https://github.com/zverok/magic_cloud
lib/magic_cloud/spriter.rb
Ruby
mit
87
master
2,393
# frozen_string_literal: true require_relative 'bit_matrix' module MagicCloud # Incapsulates sprite maker for any Shape, able to draw itself. class Spriter # Sprite is basically a 2-dimensional matrix of 1s and 0s, # representing "filled" and "empty" pixeslf of the shape to layout. class Sprite < BitM...
github
zverok/magic_cloud
https://github.com/zverok/magic_cloud
lib/magic_cloud/rect.rb
Ruby
mit
87
master
2,381
# frozen_string_literal: true module MagicCloud # Utility geometrical rectangle, implementing arithmetic interactions # with other rectangles # (not to be confused with drawable shapes) class Rect def initialize(x0, y0, x1, y1) @x0, @y0, @x1, @y1 = x0, y0, x1, y1 end attr_accessor :x0, :y0, ...
github
zverok/magic_cloud
https://github.com/zverok/magic_cloud
lib/magic_cloud/shape.rb
Ruby
mit
87
master
1,014
# frozen_string_literal: true module MagicCloud # Basic "abstract shape" class, with all primitive functionality # necessary for use it in Spriter and Layouter. # # Word for wordcloud is inherited from it, and its potentially # possible to inherit other types of shapes and layout them also. class Shape ...
github
zverok/magic_cloud
https://github.com/zverok/magic_cloud
lib/magic_cloud/debug.rb
Ruby
mit
87
master
581
# frozen_string_literal: true require 'forwardable' require 'logger' module MagicCloud # Debugging utilities class for cloud development itself class Debug class << self def instance @instance ||= new end extend Forwardable def_delegators :instance, :logger, :stats, :reset! ...
github
zverok/magic_cloud
https://github.com/zverok/magic_cloud
lib/magic_cloud/word.rb
Ruby
mit
87
master
601
# frozen_string_literal: true require_relative 'shape' module MagicCloud # Class representing individual word in word cloud class Word < Shape def initialize(text, options) super() @text, @options = text.to_s, options end attr_reader :text, :options def size options[:font_size]...
github
zverok/magic_cloud
https://github.com/zverok/magic_cloud
lib/magic_cloud/collision_board.rb
Ruby
mit
87
master
3,021
# frozen_string_literal: true require_relative 'bit_matrix' module MagicCloud # Pixel-by-pixel collision board # # Providen by width and height of the board, allows to check if given # shape (array of zero and non-zero pixels) "collides" with any of # previosly placed shapes class CollisionBoard < BitMatr...
github
zverok/magic_cloud
https://github.com/zverok/magic_cloud
lib/magic_cloud/canvas.rb
Ruby
mit
87
master
2,639
# frozen_string_literal: true require 'rmagick' module MagicCloud # Thin wrapper around RMagick, incapsulating ALL the real drawing. # As it's only class that "knows" about underlying graphics library, # it should be possible to replace it with another canvas with same # interface, not using RMagick. class ...
github
zverok/magic_cloud
https://github.com/zverok/magic_cloud
lib/magic_cloud/layouter/place.rb
Ruby
mit
87
master
2,813
# frozen_string_literal: true module MagicCloud class Layouter class PlaceNotFound < RuntimeError end # Incapsulating place lookup process # 1. find initial random place # 2. at each step, shift in spiral from the previous place # 3. always knows, if the place "ready" for shape (empty and in...
github
robertsosinski/retryable
https://github.com/robertsosinski/retryable
retryable-rb.gemspec
Ruby
mit
87
master
1,442
# -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = %q{retryable-rb} s.version = "1.1.0" s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version= s.authors = ["Robert Sosinski"] s.date = %q{2011-04-17} s.description = %q{Easy to use DSL to retr...
github
robertsosinski/retryable
https://github.com/robertsosinski/retryable
Rakefile
Ruby
mit
87
master
435
require 'rake' require 'rake/testtask' require 'echoe' Rake::TestTask.new do |t| t.libs << "test" end Echoe.new("retryable-rb") do |p| p.author = "Robert Sosinski" p.email = "email@robertsosinski.com" p.url = "http://github.com/robertsosinski/retryable" p.description = p.summary = "Easy to use DSL to retry ...
github
robertsosinski/retryable
https://github.com/robertsosinski/retryable
test/retryable_test.rb
Ruby
mit
87
master
1,525
$:.unshift(File.dirname(__FILE__) + "../lib") require 'test/unit' require 'retryable' class RetryableTest < Test::Unit::TestCase def test_without_arguments i = 0 Retryable.retryable do i += 1 raise Exception.new end rescue Exception assert_equal i, 2 end def test_wit...
github
robertsosinski/retryable
https://github.com/robertsosinski/retryable
lib/retryable.rb
Ruby
mit
87
master
879
module Retryable extend self def retryable(options = {}) opts = {:on => Exception, :times => 1}.merge(options) handler = {} retry_exception = opts[:on].is_a?(Array) ? opts[:on] : [opts[:on]] times = retries = opts[:times] attempts = 0 begin attempts += 1 ...
github
fabiopelosin/motion-live
https://github.com/fabiopelosin/motion-live
Rakefile
Ruby
mit
87
master
281
desc "Build the gem" task :gem do sh "bundle exec gem build motion-live.gemspec" sh "mkdir -p pkg" sh "mv *.gem pkg/" end task :clean do FileUtils.rm_rf 'pkg' end desc "Install the gem" task :install => %w[ clean gem ] do sh "sudo gem install pkg/motion-live*.gem" end
github
fabiopelosin/motion-live
https://github.com/fabiopelosin/motion-live
motion-live.gemspec
Ruby
mit
87
master
672
Gem::Specification.new do |s| s.name = 'motion-live' s.version = '0.1' s.date = Date.today s.summary = 'Live coding for RubyMotion projects.' s.description = 'Write you code in a scratch pad file and have the changes reflected in your application running in the simulator. Suited for prot...
github
fabiopelosin/motion-live
https://github.com/fabiopelosin/motion-live
lib/motion-live.rb
Ruby
mit
87
master
1,129
# Copyright (c) 2012 Fabio Angelo Pelosin # # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish...
github
fabiopelosin/motion-live
https://github.com/fabiopelosin/motion-live
lib/motion/project/live.rb
Ruby
mit
87
master
3,939
# Copyright (c) 2012 Fabio Angelo Pelosin # # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish...
github
chicks/aes
https://github.com/chicks/aes
Gemfile
Ruby
mit
87
master
347
source "http://rubygems.org" # Add dependencies required to use your gem here. # Example: # gem "activesupport", ">= 2.3.5" # Add dependencies to develop your gem here. # Include everything needed to run rake, tests, features, etc. group :development do gem "test-unit" gem "shoulda" gem "bundler" gem "jewel...
github
chicks/aes
https://github.com/chicks/aes
aes.gemspec
Ruby
mit
87
master
1,889
# Generated by jeweler # DO NOT EDIT THIS FILE DIRECTLY # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = "aes" s.version = "0.5.1" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_ver...
github
chicks/aes
https://github.com/chicks/aes
Rakefile
Ruby
mit
87
master
1,592
require 'rubygems' require 'bundler' begin Bundler.setup(:default, :development) rescue Bundler::BundlerError => e $stderr.puts e.message $stderr.puts "Run `bundle install` to install missing gems" exit e.status_code end require 'rake' require 'jeweler' Jeweler::Tasks.new do |gem| # gem is a Gem::Specificati...
github
chicks/aes
https://github.com/chicks/aes
lib/aes/aes.rb
Ruby
mit
87
master
3,946
module AES class << self # Encrypts the plain_text with the provided key def encrypt(plain_text, key, opts={}) ::AES::AES.new(key, opts).encrypt(plain_text) end # Decrypts the cipher_text with the provided key def decrypt(cipher_text, key, opts={}) ::AES::AES.new(key, opts).decrypt(cip...
github
chicks/aes
https://github.com/chicks/aes
test/test_aes.rb
Ruby
mit
87
master
1,305
require 'helper' class TestAES < Test::Unit::TestCase should "encrypt and decrypt a string" do key = "01234567890123456789012345678901" msg = "This is a message that nobody should ever see" enc = AES.encrypt(msg, key) assert_equal msg, AES.decrypt(enc, key) enc = AES.encrypt(msg, key, {:form...
github
chicks/aes
https://github.com/chicks/aes
test/helper.rb
Ruby
mit
87
master
424
require 'rubygems' require 'bundler' begin Bundler.setup(:default, :development) rescue Bundler::BundlerError => e $stderr.puts e.message $stderr.puts "Run `bundle install` to install missing gems" exit e.status_code end require 'test/unit' require 'shoulda' $LOAD_PATH.unshift(File.join(File.dirname(__FILE__),...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
Gemfile
Ruby
mit
87
master
253
source 'https://rubygems.org' gemspec gem 'munson', :require=>false, :git=>'https://github.com/mwpastore/munson.git', :branch=>'develop' gem 'sinja-sequel', :require=>false, :git=>'https://github.com/mwpastore/sinja-sequel.git', :branch=>'master'
github
mwpastore/sinja
https://github.com/mwpastore/sinja
sinja.gemspec
Ruby
mit
87
master
2,575
# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'sinja/version' Gem::Specification.new do |spec| spec.name = 'sinja' spec.version = Sinja::VERSION spec.authors = ['Mike Pastore'] spec.email = ['mike@oobak.or...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
Rakefile
Ruby
mit
87
master
228
# frozen_string_literal: true require 'bundler/gem_tasks' require 'rake/testtask' Rake::TestTask.new do |t| t.test_files = FileList[File.expand_path('test/**/*_test.rb', __dir__)] t.warning = false end task default: :test
github
mwpastore/sinja
https://github.com/mwpastore/sinja
test/test_helper.rb
Ruby
mit
87
master
1,649
# frozen_string_literal: true ENV['RACK_ENV'] = ENV['APP_ENV'] = 'test' require 'bundler/setup' require 'minitest/autorun' require 'rack/test' # TODO: Don't do this. Bundler.require :default Bundler.require Sinatra::Base.environment Bundler.require :development if Sinatra::Base.test? module MyAppTest def setup ...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
test/utility_classes/errors_test.rb
Ruby
mit
87
master
5,235
# frozen_string_literal: true require_relative '../test_helper' require 'sinja/errors' require 'json' class TestHttpError < Minitest::Test def setup @error = Sinja::HttpError.new(418, "I'm a little teapot!") end def test_it_is_an_error assert_kind_of StandardError, @error end def test_it_has_attri...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
test/utility_classes/roles_config_test.rb
Ruby
mit
87
master
1,194
# frozen_string_literal: true require_relative '../test_helper' require 'sinja/config' class TestRolesConfig < Minitest::Test def setup @config = Sinja::RolesConfig.new([:create]) end def test_it_inits_and_delegates assert_kind_of Sinja::Roles, @config[:create] assert_empty @config[:create] ass...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
test/utility_classes/roles_test.rb
Ruby
mit
87
master
463
# frozen_string_literal: true require_relative '../test_helper' require 'sinatra/base' require 'sinja/config' class TestRoles < Minitest::Test def setup @roles = Sinja::Roles[:a, :a, :b] end def test_it_is_setlike assert_equal [:a, :b], @roles.to_a end def test_it_is_switchable assert_respond_...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
test/utility_classes/config_test.rb
Ruby
mit
87
master
9,152
# frozen_string_literal: true require_relative '../test_helper' require 'sinja/config' class TestConfig < Minitest::Test def setup @config = Sinja::Config.new end def test_it_sets_sane_defaults assert_kind_of Hash, @config.query_params assert_respond_to @config.error_logger, :call assert_kind_...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
test/integration/tag_test.rb
Ruby
mit
87
master
3,575
# frozen_string_literal: true require_relative 'test_helper' require_relative '../../demo-app/app' class TagTest < SequelTest include MyAppTest include Rack::Test::Methods def app Sinatra::Application.new end def test_uncoalesced_find_options options '/tags' assert_ok assert_equal 'GET,POST...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
test/integration/post_test.rb
Ruby
mit
87
master
7,633
# frozen_string_literal: true require_relative 'test_helper' require_relative '../../demo-app/app' class PostTest < SequelTest include MyAppTest include Rack::Test::Methods def app Sinatra::Application.new end def test_missing_client_id login 'all@yourbase.com' post '/posts', JSON.generate(:dat...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
test/integration/author_test.rb
Ruby
mit
87
master
7,099
# frozen_string_literal: true require_relative 'test_helper' require_relative '../../demo-app/app' class AuthorTest < SequelTest include MyAppTest include Rack::Test::Methods def app Rack::Lint.new(Sinatra::Application.new) end def test_uncoalesced_find_options options '/authors' assert_ok ...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
test/integration/test_client.rb
Ruby
mit
87
master
459
# frozen_string_literal: true require_relative '../../demo-app/app' require 'munson' Munson.configure \ adapter: [:rack, Sinatra::Application], response_key_format: :dasherize module TestClient class Author < Munson::Resource self.type = :authors end class Comment < Munson::Resource self.type = :co...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
test/integration/weird_test.rb
Ruby
mit
87
master
621
# frozen_string_literal: true require_relative 'test_helper' class MyWeirdApp < Sinatra::Base register Sinja get '/' do not_found end resource :foos do get '/bar' do content_type :text 'hello' end end end class MyWeirdAppTest < Minitest::Test include MyAppTest include Rack::Tes...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
test/integration/munson_test.rb
Ruby
mit
87
master
412
# frozen_string_literal: true require_relative 'test_helper' require_relative 'test_client' class DemoAppTest < SequelTest def before_all super # foo end def after_all # bar super end def test_it_checks_accept_header posts = TestClient::Post.fetch refute posts.any? end def test...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
test/integration/test_helper.rb
Ruby
mit
87
master
370
# frozen_string_literal: true require_relative '../test_helper' require 'minitest/hooks/test' class SequelTest < Minitest::Test include Minitest::Hooks def around Sequel::Model.db.transaction(:rollback=>:always, :savepoint=>true, :auto_savepoint=>true) { super } end def around_all Sequel::Model.db.tr...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
test/integration/rack_test.rb
Ruby
mit
87
master
3,552
# frozen_string_literal: true require_relative 'test_helper' require_relative '../../demo-app/app' # Munson doesn't support error-handling (yet) so let's poke at the demo app # until it breaks and examine the pieces. class DemoAppTest1 < Minitest::Test include MyAppTest include Rack::Test::Methods def app ...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
test/middleware/method_override_test.rb
Ruby
mit
87
master
1,165
# frozen_string_literal: true require_relative '../test_helper' require 'rack/test' require 'sinatra/base' require 'sinja/method_override' class MyPatchlessApp < Sinatra::Base use Sinja::MethodOverride %i[get post patch].each do |meth| send(meth, '/') { "#{meth} called" } end end class TestMyPatchlessApp ...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
test/helpers/serializers_test.rb
Ruby
mit
87
master
5,116
# frozen_string_literal: true require_relative 'test_helper' class SerializersApp < MyAppBase before do env['sinja.passthru'] = true # let exceptions propagate end configure_jsonapi do |c| %i[str sym _include _exclude].each do |sym| c.query_params[sym] = nil end end get '/dedasherize' do ...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
test/helpers/core_test.rb
Ruby
mit
87
master
2,919
# frozen_string_literal: true require_relative 'test_helper' class HelpersApp < MyAppBase before do env['sinja.passthru'] = true # let exceptions propagate end configure_jsonapi do |c| %i[code body roles].each do |sym| c.query_params[sym] = nil end end post '/attributes' do attributes...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
test/helpers/test_helper.rb
Ruby
mit
87
master
306
# frozen_string_literal: true require_relative '../test_helper' # It's somewhat challenging to isolate Sinatra helpers for testing. We'll # create a "shell" application with some custom routes to get at them. class MyAppBase < Sinatra::Base register Sinja before do content_type :json end end
github
mwpastore/sinja
https://github.com/mwpastore/sinja
demo-app/database.rb
Ruby
mit
87
master
365
# frozen_string_literal: true require 'logger' require_relative 'boot' Sequel.single_threaded = true # WEBrick is single-threaded DB = Sequel.connect ENV.fetch 'DATABASE_URL', defined?(JRUBY_VERSION) ? 'jdbc:sqlite::memory:' : 'sqlite:/' DB.extension(:freeze_datasets) DB.extension(:pagination) DB.loggers << Logge...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
demo-app/Rakefile
Ruby
mit
87
master
834
# frozen_string_literal: true namespace :docker do require 'securerandom' IMAGE = 'mwpastore/sinja-demo-app' NAME = SecureRandom.hex(6) PORT = 4567 def port %x{ docker inspect --format '{{ (index ( index .NetworkSettings.Ports "#{PORT}/tcp") 0).HostPort }}' #{NAME} }.chomp end task :build...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
demo-app/Gemfile
Ruby
mit
87
master
434
source 'https://rubygems.org' gem 'jdbc-sqlite3', '~> 3.8', :platform=>:jruby gem 'json', '~> 2.0' gem 'sequel', '~> 4.46' gem 'sinatra', '>= 2.0.0.beta2', '< 3' gem 'sinatra-contrib', '>= 2.0.0.beta2', '< 3' gem 'sinja', git: 'https://github.com/mwpastore/sinja.git', branch: 'master' gem 'sinja-sequel', git: 'htt...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
demo-app/app.rb
Ruby
mit
87
master
1,084
# frozen_string_literal: true require 'sinatra' require 'sinatra/jsonapi' # Load the Sequel helpers without registering the extension. require 'sinja/sequel/helpers' require_relative 'classes/author' require_relative 'classes/comment' require_relative 'classes/post' require_relative 'classes/tag' [Author, Comment, P...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
demo-app/classes/base.rb
Ruby
mit
87
master
273
# require_string_literal: true require_relative '../boot' require_relative '../database' class BaseSerializer include JSONAPI::Serializer end Sequel::Model.plugin :tactical_eager_loading Sequel::Model.plugin :validation_helpers Sequel::Model.plugin :whitelist_security
github
mwpastore/sinja
https://github.com/mwpastore/sinja
demo-app/classes/post.rb
Ruby
mit
87
master
2,805
# frozen_string_literal: true require_relative 'base' DB.create_table?(:posts) do String :slug, primary_key: true foreign_key :author_id, :authors, index: true, on_delete: :cascade String :title, null: false String :body, text: true, null: false Float :created_at Float :updated_at end class Post < Sequel:...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
demo-app/classes/comment.rb
Ruby
mit
87
master
1,930
# frozen_string_literal: true require_relative 'base' DB.create_table?(:comments) do primary_key :id foreign_key :author_id, :authors, index: true, on_delete: :cascade foreign_key :post_slug, :posts, type: String, index: true, on_delete: :cascade, on_update: :cascade String :body, text: true, null: false Flo...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
demo-app/classes/author.rb
Ruby
mit
87
master
1,888
# frozen_string_literal: true require_relative 'base' DB.create_table?(:authors) do primary_key :id String :email, null: false, unique: true String :real_name String :display_name TrueClass :admin, default: false Float :created_at Float :updated_at end class Author < Sequel::Model plugin :auto_validat...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
demo-app/classes/tag.rb
Ruby
mit
87
master
1,727
# frozen_string_literal: true require_relative 'base' require_relative 'post' # make sure we create the posts table before the join table DB.create_table?(:tags) do primary_key :id String :name, null: false, unique: true String :description end DB.create_table?(:posts_tags) do foreign_key :post_slug, :posts, ...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
lib/sinja.rb
Ruby
mit
87
master
11,524
# frozen_string_literal: true require 'set' require 'active_support/inflector' require 'sinatra/base' require 'sinatra/namespace' require 'sinja/config' require 'sinja/errors' require 'sinja/helpers/serializers' require 'sinja/resource' require 'sinja/version' module Sinja DEFER_CODE = 357 MIME_TYPE = 'applicati...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
lib/jsonapi/ember_serializer.rb
Ruby
mit
87
master
886
# frozen_string_literal: true require 'jsonapi-serializers' module JSONAPI module EmberSerializer def self.included(base) base.class_eval do include Serializer alias type_for_link type alias format_name_for_link format_name include InstanceMethods end end mo...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
lib/sinja/errors.rb
Ruby
mit
87
master
1,750
# frozen_string_literal: true require 'json' module Sinja class SinjaError < StandardError end class ActionHelperError < SinjaError end class HttpError < SinjaError attr_reader :http_status def initialize(http_status, message=nil) @http_status = http_status super(message) end end...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
lib/sinja/method_override.rb
Ruby
mit
87
master
415
# frozen_string_literal: true module Sinja class MethodOverride def initialize(app) @app = app end def call(env) env['REQUEST_METHOD'] = env['HTTP_X_HTTP_METHOD_OVERRIDE'] \ if env.key?('HTTP_X_HTTP_METHOD_OVERRIDE') \ && env['REQUEST_METHOD'] == 'POST' \ && env['H...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
lib/sinja/resource.rb
Ruby
mit
87
master
3,606
# frozen_string_literal: true require 'set' require 'active_support/inflector' require 'sinatra/base' require 'sinatra/namespace' require 'sinja/helpers/nested' require 'sinja/helpers/relationships' require 'sinja/relationship_routes/has_many' require 'sinja/relationship_routes/has_one' require 'sinja/resource_routes...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
lib/sinja/config.rb
Ruby
mit
87
master
5,442
# frozen_string_literal: true require 'forwardable' require 'set' require 'sinatra/base' require 'sinja/resource' require 'sinja/relationship_routes/has_many' require 'sinja/relationship_routes/has_one' require 'sinja/resource_routes' module Sinja module ConfigUtils def deep_copy(c) Marshal.load(Marshal....
github
mwpastore/sinja
https://github.com/mwpastore/sinja
lib/sinja/resource_routes.rb
Ruby
mit
87
master
3,621
# frozen_string_literal: true module Sinja module ResourceRoutes def self.registered(app) app.def_action_helper(app, :show, :roles) app.def_action_helper(app, :show_many) app.def_action_helper(app, :index, %i[roles filter_by sort_by]) app.def_action_helper(app, :create, :roles) app.d...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
lib/sinja/relationship_routes/has_one.rb
Ruby
mit
87
master
968
# frozen_string_literal: true module Sinja module RelationshipRoutes module HasOne def self.registered(app) app.def_action_helper(app, :pluck, :roles) app.def_action_helper(app, :prune, %i[roles sideload_on]) app.def_action_helper(app, :graft, %i[roles sideload_on]) app.opti...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
lib/sinja/relationship_routes/has_many.rb
Ruby
mit
87
master
1,562
# frozen_string_literal: true module Sinja module RelationshipRoutes module HasMany def self.registered(app) app.def_action_helper(app, :fetch, %i[roles filter_by sort_by]) app.def_action_helper(app, :clear, %i[roles sideload_on]) app.def_action_helper(app, :replace, %i[roles sideloa...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
lib/sinja/helpers/nested.rb
Ruby
mit
87
master
225
# frozen_string_literal: true module Sinja module Helpers module Nested def defer(msg=nil) halt DEFER_CODE, msg end def relationship_link? !params[:r].nil? end end end end
github
mwpastore/sinja
https://github.com/mwpastore/sinja
lib/sinja/helpers/relationships.rb
Ruby
mit
87
master
1,552
# frozen_string_literal: true require 'json' module Sinja module Helpers module Relationships def dispatch_relationship_request(id, path, **opts) path_info = request.path_info.dup path_info << "/#{id}" unless path_info.end_with?("/#{id}") path_info << "/relationships/#{path}" ...
github
mwpastore/sinja
https://github.com/mwpastore/sinja
lib/sinja/helpers/serializers.rb
Ruby
mit
87
master
9,755
# frozen_string_literal: true require 'set' require 'active_support/inflector' require 'json' require 'jsonapi-serializers' module Sinja module Helpers module Serializers VALID_PAGINATION_KEYS = Set.new(%i[self first prev next last]).freeze def dedasherize(s=nil) s.to_s.underscore.send(s.in...
github
flyerhzm/resque-restriction
https://github.com/flyerhzm/resque-restriction
resque-restriction.gemspec
Ruby
mit
86
master
1,230
lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'resque/restriction/version' Gem::Specification.new do |spec| spec.name = 'resque-restriction' spec.version = Resque::Restriction::VERSION spec.authors = ['Richard Huang'] spec.email ...
github
flyerhzm/resque-restriction
https://github.com/flyerhzm/resque-restriction
spec/spec_helper.rb
Ruby
mit
86
master
2,495
require 'bundler/setup' require 'resque/restriction' RSpec.configure do |config| # Enable flags like --only-failures and --next-failure config.example_status_persistence_file_path = ".rspec_status" # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching! config.expec...
github
flyerhzm/resque-restriction
https://github.com/flyerhzm/resque-restriction
spec/resque/job_spec.rb
Ruby
mit
86
master
1,946
require File.expand_path('../spec_helper', File.dirname(__FILE__)) RSpec.describe Resque::Job do before(:example) do Resque.redis.redis.flushall end it "should repush restriction queue when reserve" do Resque.push('restriction_normal', :class => 'OneHourRestrictionJob', :args => ['any args']) expect...
github
flyerhzm/resque-restriction
https://github.com/flyerhzm/resque-restriction
spec/resque/plugins/restriction_spec.rb
Ruby
mit
86
master
9,324
require 'spec_helper' RSpec.describe Resque::Plugins::Restriction do it "should follow the convention" do Resque::Plugin.lint(Resque::Plugins::Restriction) end context "resque_restriction_redis_key" do it "should get resque_restriction_redis_key with different period" do expect(MyJob.resque_restri...
github
flyerhzm/resque-restriction
https://github.com/flyerhzm/resque-restriction
spec/resque/restriction/config_spec.rb
Ruby
mit
86
master
1,569
require 'spec_helper' module Resque module Restriction RSpec.describe Config do it 'has a default of nil for max_queue_peek (disabled)' do expect(Restriction.config.max_queue_peek('restriction_queue1')).to be_nil end it 'can be configured with new values' do Restriction.configu...
github
flyerhzm/resque-restriction
https://github.com/flyerhzm/resque-restriction
lib/resque/plugins/restriction.rb
Ruby
mit
86
master
4,518
module Resque module Plugins module Restriction SECONDS = { :per_second => 1, :per_minute => 60, :per_hour => 60*60, :per_day => 24*60*60, :per_week => 7*24*60*60, :per_month => 31*24*60*60, :per_year => 366*24*60*60 } RESTRICTION_QUEUE_PRE...
github
flyerhzm/resque-restriction
https://github.com/flyerhzm/resque-restriction
lib/resque/plugins/job.rb
Ruby
mit
86
master
1,120
module Resque class Job class <<self alias_method :origin_reserve, :reserve def reserve(queue) if queue =~ /^#{Plugins::Restriction::RESTRICTION_QUEUE_PREFIX}/ # If processing the restriction queue, when poping and pushing to end, # we can't tell when we reach the original...