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 | ddnexus/pagy | https://github.com/ddnexus/pagy | gem/lib/pagy/toolbox/paginators/typesense_rails.rb | Ruby | mit | 4,963 | master | 995 | # frozen_string_literal: true
require_relative '../../modules/searcher'
class Pagy
module TypesenseRailsPaginator
module_function
def paginate(search, options)
if search.is_a?(Search::Arguments) # Active mode
Searcher.wrap(search, options) do
model, arguments, search_options = sear... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | gem/lib/pagy/toolbox/paginators/countish.rb | Ruby | mit | 4,963 | master | 1,168 | # frozen_string_literal: true
require_relative '../../modules/abilities/countable'
class Pagy
module CountishPaginator
module_function
def paginate(collection, options)
options[:page] ||= options[:request].resolve_page(force_integer: false)
if options[:page].is_a?(String)
page, count, ... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | gem/lib/pagy/toolbox/paginators/meilisearch.rb | Ruby | mit | 4,963 | master | 986 | # frozen_string_literal: true
require_relative '../../modules/searcher'
class Pagy
module MeilisearchPaginator
module_function
def paginate(search, options)
if search.is_a?(Search::Arguments) # Active mode
Searcher.wrap(search, options) do
model, arguments, search_options = search
... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | gem/lib/pagy/toolbox/paginators/searchkick.rb | Ruby | mit | 4,963 | master | 1,067 | # frozen_string_literal: true
require_relative '../../modules/searcher'
class Pagy
module SearchkickPaginator
module_function
def paginate(search, options)
if search.is_a?(Search::Arguments) # Active mode
Searcher.wrap(search, options) do
model, arguments, search_options, block = s... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | gem/lib/pagy/toolbox/paginators/method.rb | Ruby | mit | 4,963 | master | 1,668 | # frozen_string_literal: true
require_relative '../../classes/request'
class Pagy
paginators = { offset: :OffsetPaginator,
countless: :CountlessPaginator,
countish: :CountishPaginator,
keyset: :KeysetPaginator,
... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | gem/lib/pagy/toolbox/paginators/calendar.rb | Ruby | mit | 4,963 | master | 1,114 | # frozen_string_literal: true
class Pagy
module CalendarPaginator
module_function
# Take a collection and a config Hash and return [calendar, pagy, results]
def paginate(context, collection, config)
context.instance_eval do
allowed_options = Calendar::UNITS + %i[offset disabled request]
... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | gem/lib/pagy/toolbox/paginators/elasticsearch_rails.rb | Ruby | mit | 4,963 | master | 1,931 | # frozen_string_literal: true
require_relative '../../modules/searcher'
class Pagy
module ElasticsearchRailsPaginator
module_function
def paginate(search, options)
if search.is_a?(Search::Arguments) # Active mode
Searcher.wrap(search, options) do
model, arguments, search_options =... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | gem/lib/pagy/toolbox/paginators/countless.rb | Ruby | mit | 4,963 | master | 645 | # frozen_string_literal: true
class Pagy
module CountlessPaginator
module_function
def paginate(collection, options)
options[:page] ||= options[:request].resolve_page(force_integer: false) # accept nil and strings
if options[:page].is_a?(String)
page, last = options[:page].split.map... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | gem/apps/keynav.ru | Ruby | mit | 4,963 | master | 7,151 | # frozen_string_literal: true
# DESCRIPTION
# Showcase the Keynav pagination (ActiveRecord example)
#
# DOC
# https://ddnexus.github.io/pagy/playground/#keyset-apps
#
# BIN HELP
# pagy -h
#
# DEV USAGE
# pagy clone keynav
# pagy ./keynav.ru
#
# URL
# http://127.0.0.1:8000
VERSION = '43.5.3'
if VERS... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | gem/apps/rails.ru | Ruby | mit | 4,963 | master | 5,733 | # frozen_string_literal: true
# DESCRIPTION
# Reproduce rails related issues
#
# DOC
# https://ddnexus.github.io/pagy/playground/#rails-app
#
# BIN HELP
# pagy -h
#
# DEV USAGE
# pagy clone rails
# pagy ./rails.ru
#
# URL
# http://127.0.0.1:8000
VERSION = '43.5.3'
if VERSION != Pagy::VERSION
Warn... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | gem/apps/index.rb | Ruby | mit | 4,963 | master | 215 | # frozen_string_literal: true
# PagyApps module
module PagyApps
# Return the hash of app name/path
INDEX = Dir[File.expand_path('./*.ru', __dir__)].to_h do |f|
[File.basename(f, '.ru'), f]
end.freeze
end |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | gem/apps/enable_rails_page_segment.rb | Ruby | mit | 4,963 | master | 1,665 | # frozen_string_literal: true
# ################# IMPORTANT WARNING #################
# This setup forces Pagy to use the Rails `url_for` method,
# which is significantly slower (~20x) than Pagy's native URL generation.
# Use this file ONLY if you absolutely want to support the page param as a dynamic segment.
# (e.g... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | gem/apps/keyset_sequel.ru | Ruby | mit | 4,963 | master | 5,732 | # frozen_string_literal: true
# DESCRIPTION
# Showcase the Keyset pagination (Sequel example)
#
# DOC
# https://ddnexus.github.io/pagy/playground/#keyset-apps
#
# BIN HELP
# pagy -h
#
# DEV USAGE
# pagy clone keyset_sequel
# pagy ./keyset_sequel.ru
#
# URL
# http://127.0.0.1:8000
VERSION = '43.5.3'
... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | gem/apps/keynav+root_key.ru | Ruby | mit | 4,963 | master | 9,779 | # frozen_string_literal: true
# DESCRIPTION
# Showcase the Keynav pagination with independent instances
#
# DOC
# https://ddnexus.github.io/pagy/playground/#keyset-apps
#
# BIN HELP
# pagy -h
#
# DEV USAGE
# pagy clone keynav
# pagy ./keynav.ru
#
# URL
# http://127.0.0.1:8000
VERSION = '43.5.3'
if ... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | gem/apps/calendar.ru | Ruby | mit | 4,963 | master | 18,894 | # frozen_string_literal: true
# DESCRIPTION
# Showcase the calendar; reproduce related issues
#
# DOC
# https://ddnexus.github.io/pagy/playground/#5-calendar-app
#
# BIN HELP
# pagy -h
#
# DEV USAGE
# pagy clone calendar
# pagy ./calendar.ru
#
# URL
# http://127.0.0.1:8000
VERSION = '43.5.3'
if VER... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | gem/apps/demo.ru | Ruby | mit | 4,963 | master | 15,786 | # frozen_string_literal: true
# DESCRIPTION
# Showcase all the helpers and styles
#
# DOC
# https://ddnexus.github.io/pagy/playground/#demo-app
#
# BIN HELP
# pagy -h
#
# DEMO USAGE
# pagy demo
#
# DEV USAGE
# pagy clone demo
# pagy ./demo.ru
#
# URL
# http://127.0.0.1:8000
VERSION = '43.5.3'
if... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | gem/apps/keyset.ru | Ruby | mit | 4,963 | master | 5,957 | # frozen_string_literal: true
# DESCRIPTION
# Showcase the Keyset pagination (ActiveRecord example)
#
# DOC
# https://ddnexus.github.io/pagy/playground/#keyset-apps
#
# BIN HELP
# pagy -h
#
# DEV USAGE
# pagy clone keyset
# pagy ./keyset.ru
#
# URL
# http://127.0.0.1:8000
VERSION = '43.5.3'
if VERS... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | gem/apps/repro.ru | Ruby | mit | 4,963 | master | 4,922 | # frozen_string_literal: true
# DESCRIPTION
# Reproduce generic/simple issues
#
# DOC
# https://ddnexus.github.io/pagy/playground/#repro-app
#
# BIN HELP
# pagy -h
#
# DEV USAGE
# pagy clone repro
# pagy ./repro.ru
#
# URL
# http://127.0.0.1:8000
VERSION = '43.5.3'
if VERSION != Pagy::VERSION
War... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | scripts/scripty.rb | Ruby | mit | 4,963 | master | 2,971 | # frozen_string_literal: true
require 'pathname'
# A few functions useful in scripts
module Scripty
ROOT = Pathname.new(`git rev-parse --show-toplevel`.chomp)
if ENV['RM_INFO'] || ENV['RUBYLIB']&.include?('rubymine')
require 'io/console'
$stdin.echo = false if $stdin.tty?
end
module_function
# As... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | scripts/runapp.rb | Ruby | mit | 4,963 | master | 439 | # frozen_string_literal: true
# Run a pagy app using the local bin/pagy and watchexec for auto-reloading.
# Usage: ruby scripts/runapp.rb APP [options].
require 'shellwords'
abort 'Error: "watchexec" is not installed.' unless system('command -v watchexec > /dev/null')
# Ensure we run from the repo root
root = File.... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | scripts/update_top100.rb | Ruby | mit | 4,963 | master | 1,036 | #!/usr/bin/env ruby
# frozen_string_literal: true
require 'json'
require 'net/http'
require_relative 'scripty'
include Scripty # rubocop:disable Style/MixinUsage
USERS_URL_FMT = 'https://api.github.com/repos/ddnexus/pagy/contributors?page=%s'
COMMITS_URL_FMT = 'https://github.com/ddnexus/pagy/commits?author=%s'
IM... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | scripts/bump.rb | Ruby | mit | 4,963 | master | 3,748 | #!/usr/bin/env ruby
# frozen_string_literal: true
# Update the files related to version changes
require 'tempfile'
require_relative 'scripty'
require_relative '../gem/apps/index'
include Scripty # rubocop:disable Style/MixinUsage
# Abort if the working tree is dirty
abort('Working tree dirty!') unless `git status --... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | scripts/update_retype_head.rb | Ruby | mit | 4,963 | master | 448 | #!/usr/bin/env ruby
# frozen_string_literal: true
require_relative 'scripty'
include Scripty # rubocop:disable Style/MixinUsage
# Prompt for the old version tag.
require_relative '../gem/lib/pagy'
# Insert the latest ai-widget in the retype head.
replace_section_in_file('docs/_includes/head.html', 'ai_widget', <<~H... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | scripts/docshots/docshots.ru | Ruby | mit | 4,963 | master | 6,997 | # frozen_string_literal: true
# DESCRIPTION
# Screenshot tool for the pagy docs.
#
# DEV USAGE
# pagy docshots
# Bundle
require 'bundler/inline'
gemfile(false) do
source 'https://rubygems.org'
gem 'oj'
gem 'puma'
gem 'sinatra'
end
# Edit this section adding the legacy as needed
# Pagy initializer
Pagy:... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | scripts/docshots/docshot.rb | Ruby | mit | 4,963 | master | 738 | #!/usr/bin/env ruby
# frozen_string_literal: true
require_relative '../../gem/lib/pagy/cli'
require 'net/http'
port = 8088
app_url = "http://localhost:#{port}"
app_path = "#{Pagy::ROOT}/../scripts/docshots/docshots.ru"
# Run the app in a sub process
pid = spawn("#{Pagy::ROOT}/bin/pagy #{app_path} -p #{port}")
... |
github | ddnexus/pagy | https://github.com/ddnexus/pagy | tasks/release_pagy.rake | Ruby | mit | 4,963 | master | 625 | # frozen_string_literal: true
# Gem release cycle
require 'bundler/gem_helper'
Bundler::GemHelper.install_tasks(dir: 'gem', name: 'pagy')
module VersionTagOverride
def version_tag = "#{@tag_prefix}#{version}"
end
Bundler::GemHelper.prepend VersionTagOverride
desc 'Checks-build-release-tag-cleanup cycle'
task :rele... |
github | opal/opal | https://github.com/opal/opal | config.ru | Ruby | mit | 4,915 | master | 263 | require 'bundler'
Bundler.require
require 'mspec/opal/rake_task'
::Opal::Config.arity_check_enabled = true
::Opal::Config.dynamic_require_severity = :error
use Rack::ShowExceptions
use Rack::ShowStatus
use MSpec::Opal::Index
run MSpec::Opal::Environment.new |
github | opal/opal | https://github.com/opal/opal | Rakefile | Ruby | mit | 4,915 | master | 326 | # FIXME: there must be a better way
Encoding.default_external = 'utf-8'
import 'tasks/github.rake'
import 'tasks/testing.rake'
import 'tasks/building.rake'
import 'tasks/linting.rake'
import 'tasks/benchmarking.rake'
import 'tasks/releasing.rake'
import 'tasks/performance.rake'
task :default => [:rspec, :mspec, :mini... |
github | opal/opal | https://github.com/opal/opal | Guardfile | Ruby | mit | 4,915 | master | 1,882 | require 'guard/plugin'
class ::Guard::Opal < Plugin
def mspec *paths
command = ['bundle', 'exec', './bin/opal-mspec', *paths.flatten]
result = time(:mspec, *paths) { system *command }
notify 'MSpec', result
end
def rspec *paths
command = ['bundle', 'exec', 'rspec', *paths.flatten]
result = t... |
github | opal/opal | https://github.com/opal/opal | opal.gemspec | Ruby | mit | 4,915 | master | 2,930 | require_relative 'lib/opal/version'
Gem::Specification.new do |spec|
spec.name = 'opal'
spec.version = Opal::VERSION
spec.author = ['Elia Schito', 'meh.', 'Adam Beynon']
spec.email = ['elia@schito.me', 'meh@schizofreni.co']
spec.summary = %{Ruby runtime and core library for Ja... |
github | opal/opal | https://github.com/opal/opal | Gemfile | Ruby | mit | 4,915 | master | 1,501 | source 'https://rubygems.org'
gemspec
v = -> version { Gem::Version.new(version) if version }
ruby_version = v[RUBY_VERSION]
tilt_version = ENV['TILT_VERSION']
rack_version = ENV['RACK_VERSION']
sprockets_version = ENV['SPROCKETS_VERSION']
gem 'json', '< 1.8.1', platform: :ruby if ruby_version < v['... |
github | opal/opal | https://github.com/opal/opal | test/opal/test_matrix.rb | Ruby | mit | 4,915 | master | 21,583 | # frozen_string_literal: false
require 'test/unit'
require 'matrix'
class SubMatrix < Matrix
end
class TestMatrix < Test::Unit::TestCase
def setup
@m1 = Matrix[[1,2,3], [4,5,6]]
@m2 = Matrix[[1,2,3], [4,5,6]]
@m3 = @m1.clone
@m4 = Matrix[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]
@n1 = Matrix[[2,3,4], [5... |
github | opal/opal | https://github.com/opal/opal | test/opal/unsupported_and_bugs.rb | Ruby | mit | 4,915 | master | 1,574 | class Test::Unit::TestCase
#
# @example
# class TestBase64
# unsupported :test_urlsafe_encode64
# unsupported :test_strict_encode64
# end
#
def self.unsupported name, message = 'unsupported'
define_method name do
skip message
end
end
#
# @example
# class TestBase64
... |
github | opal/opal | https://github.com/opal/opal | test/opal/test_base64.rb | Ruby | mit | 4,915 | master | 5,370 | # coding: ascii-8bit
# frozen_string_literal: false
require "test/unit"
require "base64"
class TestBase64 < Test::Unit::TestCase
def test_sample
assert_equal("U2VuZCByZWluZm9yY2VtZW50cw==\n", Base64.encode64('Send reinforcements'))
assert_equal('Send reinforcements', Base64.decode64("U2VuZCByZWluZm9yY2VtZW50... |
github | opal/opal | https://github.com/opal/opal | test/opal/test_keyword.rb | Ruby | mit | 4,915 | master | 19,333 | # Copied from cruby and modified to skip unsupported syntaxes
require 'test/unit'
class TestKeywordArguments < Test::Unit::TestCase
def f1(str: "foo", num: 424242)
[str, num]
end
def test_f1
skip %{TypeError: no implicit conversion of NilClass into String}
assert_equal(["foo", 424242], f1)
asse... |
github | opal/opal | https://github.com/opal/opal | test/opal/http_server.rb | Ruby | mit | 4,915 | master | 1,251 | require 'sinatra'
cat_image = File.open(File.join(File.dirname(__FILE__), 'cat.png'), 'rb').read
get '/' do
headers \
'Access-Control-Allow-Origin' => '*'
'Ready!'
end
get '/plain_text' do
status 200
headers(
'Content-Type' => 'text/plain',
'Access-Control-Allow-Origin' => '*' )
body 'plain tex... |
github | opal/opal | https://github.com/opal/opal | test/opal/test_uri.rb | Ruby | mit | 4,915 | master | 1,905 | # frozen_string_literal: false
require 'uri'
module URI
class TestCommon < Test::Unit::TestCase
def test_decode_www_form
assert_equal([%w[a 1], %w[a 2]], URI.decode_www_form("a=1&a=2"))
assert_equal([%w[a 1;a=2]], URI.decode_www_form("a=1;a=2"))
assert_equal([%w[a 1], ['', ''], %w[a 2]], URI.d... |
github | opal/opal | https://github.com/opal/opal | test/opal/test_openuri.rb | Ruby | mit | 4,915 | master | 1,496 | # frozen_string_literal: false
require "test/unit"
require "open-uri"
class TestOpenURI < Test::Unit::TestCase
def test_open_http_plain_text
open("http://localhost:4567/plain_text") {|f|
assert_match(/plain text/, f.read)
assert_equal('text/plain', f.content_type)
}
end
def test_open_http_ht... |
github | opal/opal | https://github.com/opal/opal | test/opal/test_io_buffer.rb | Ruby | mit | 4,915 | master | 15,116 | # frozen_string_literal: false
require 'tempfile'
require 'corelib/io/buffer'
class TestIOBuffer < Test::Unit::TestCase
def assert_negative(value)
assert(value < 0, "Expected #{value} to be negative!")
end
def assert_positive(value)
assert(value > 0, "Expected #{value} to be positive!")
end
def te... |
github | opal/opal | https://github.com/opal/opal | test/opal/promisev2/test_when.rb | Ruby | mit | 4,915 | master | 566 | require 'test/unit'
require 'promise/v2'
class TestPromiseWhen < Test::Unit::TestCase
def test_calls_the_block_with_all_promises_results
a = PromiseV2.new
b = PromiseV2.new
x = 42
p = PromiseV2.when(a, b).then {|y, z|
x = y + z
}
a.resolve(1)
b.resolve(2)
p.always { assert_e... |
github | opal/opal | https://github.com/opal/opal | test/opal/promisev2/test_then.rb | Ruby | mit | 4,915 | master | 1,874 | require 'test/unit'
require 'promise/v2'
class TestPromiseThen < Test::Unit::TestCase
def test_calls_the_block_when_the_promise_has_already_been_resolved
x = 42
PromiseV2.value(23)
.then { |v| x = v }
.always { assert_equal(x, 23) }
end
def test_calls_the_block_when_the_promise_is_resolved
... |
github | opal/opal | https://github.com/opal/opal | test/opal/promisev2/test_trace.rb | Ruby | mit | 4,915 | master | 1,084 | require 'test/unit'
require 'promise/v2'
class TestPromiseTrace < Test::Unit::TestCase
def test_calls_the_block_with_all_the_previous_results
x = 42
PromiseV2.value(1)
.then { 2 }
.then { 3 }
.trace {|a, b, c| x = a + b + c }
.always { assert_equal(x, 6) }
end
def test_calls_the... |
github | opal/opal | https://github.com/opal/opal | test/opal/promisev2/test_error.rb | Ruby | mit | 4,915 | master | 604 | require 'test/unit'
require 'promise/v2'
class TestPromiseError < Test::Unit::TestCase
def test_rejects_the_promise_with_the_given_error
prom = PromiseV2.error(23)
assert_equal(prom.error, 23)
prom.rescue{} # Needed, otherwise we have an uncaught exception
end
def test_marks_the_promise_as_realized
... |
github | opal/opal | https://github.com/opal/opal | test/opal/promisev2/test_rescue.rb | Ruby | mit | 4,915 | master | 1,290 | require 'test/unit'
require 'promise/v2'
class TestPromiseRescue < Test::Unit::TestCase
def test_calls_the_block_when_the_promise_has_already_been_rejected
x = 42
PromiseV2.error(23)
.rescue { |v| x = v }
.always { assert_equal(x, 23) }
end
def test_calls_the_block_when_the_promise_is_reject... |
github | opal/opal | https://github.com/opal/opal | test/opal/promisev2/test_always.rb | Ruby | mit | 4,915 | master | 1,703 | require 'test/unit'
require 'promise/v2'
class TestPromiseAlways < Test::Unit::TestCase
def test_calls_the_block_when_it_was_resolved
x = 42
PromiseV2.value(23)
.then { |v| x = v }
.always { |v| x = 2 }
.then { assert_equal(x, 2) }
end
def test_calls_the_block_when_it_was_rejected
... |
github | opal/opal | https://github.com/opal/opal | test/opal/promisev2/test_value.rb | Ruby | mit | 4,915 | master | 403 | require 'test/unit'
require 'promise/v2'
class TestPromiseValue < Test::Unit::TestCase
def test_resolves_the_promise_with_the_given_value
assert_equal(PromiseV2.value(23).value, 23)
end
def test_marks_the_promise_as_realized
assert_equal(PromiseV2.value(23).realized?, true)
end
def test_marks_the_p... |
github | opal/opal | https://github.com/opal/opal | test/nodejs/test_dir.rb | Ruby | mit | 4,915 | master | 4,462 | # backtick_javascript: true
# Copied from cruby and modified to skip unsupported syntaxes
require 'test/unit'
require 'nodejs'
require 'nodejs/dir'
class TestNodejsDir < Test::Unit::TestCase
def glob_base_test_dir
tmpdir + "/testing_nodejs_dir_glob_implementation_#{Time.now.to_i}"
end
def tmpdir
`requ... |
github | opal/opal | https://github.com/opal/opal | test/nodejs/test_yaml.rb | Ruby | mit | 4,915 | master | 341 | require 'test/unit'
require 'nodejs'
require 'nodejs/yaml'
class TestYAML < Test::Unit::TestCase
YAMLDOC = <<~YAML
---
string: hello world
array: [1,2,3]
YAML
YAMLSTRUCT = {
"string" => "hello world",
"array" => [1,2,3]
}
def test_should_parse_yaml
assert_equal(YAML.load(YAMLDOC), Y... |
github | opal/opal | https://github.com/opal/opal | test/nodejs/test_string.rb | Ruby | mit | 4,915 | master | 820 | # backtick_javascript: true
require 'test/unit'
require 'nodejs'
class TestString < Test::Unit::TestCase
def test_should_get_bytes
assert_equal('foo'.bytesize, 3)
assert_equal('foo'.each_byte.to_a, [102, 111, 111])
assert_equal('foo'.bytes, [102, 111, 111])
assert_equal('foo'.bytes, [102, 111, 111])... |
github | opal/opal | https://github.com/opal/opal | test/nodejs/test_env.rb | Ruby | mit | 4,915 | master | 1,265 | require 'test/unit'
require 'nodejs/env'
class TestNodejsEnv < Test::Unit::TestCase
def shared_test_env_has_key(method)
assert_equal(false, ENV.send(method, 'should_never_be_set'))
ENV['foo'] = 'bar'
assert_equal(true, ENV.send(method, 'foo'))
assert_equal(false, ENV.send(method, 'bar'))
ENV.del... |
github | opal/opal | https://github.com/opal/opal | test/nodejs/test_await.rb | Ruby | mit | 4,915 | master | 5,271 | # frozen_string_literal: true
# await: true
require "test/unit"
class TestAwait < Test::Unit::TestCase
stdheader = <<~RUBY
# await: true
require "await"
RUBY
autoawaitheader = <<~RUBY
# await: *await*
require "await"
RUBY
tests = {
test_await_in_top: [<<~RUBY, 6],
#{stdheader}
... |
github | opal/opal | https://github.com/opal/opal | test/nodejs/test_opal_builder.rb | Ruby | mit | 4,915 | master | 349 | require 'test/unit'
require 'nodejs'
require 'opal-builder'
class TestNodejsOpalBuilder < Test::Unit::TestCase
def test_should_build_simple_ruby_file
builder = Opal::Builder.new
builder.append_paths('.')
result = builder.build('test/nodejs/fixtures/hello.rb')
assert(/self\.\$puts\("Hello world"\)/.m... |
github | opal/opal | https://github.com/opal/opal | test/nodejs/test_error.rb | Ruby | mit | 4,915 | master | 893 | # backtick_javascript: true
require 'test/unit'
require 'nodejs'
class TestNodejsError < Test::Unit::TestCase
def test_should_preserve_stack
raise ArgumentError.new('oops')
rescue => ex
backtrace_line = " from nodejs/test_error.rb:#{__LINE__ - 2}"
wrapped_ex = ex.exception %(context - #{ex.message})
... |
github | opal/opal | https://github.com/opal/opal | test/nodejs/test_pathname.rb | Ruby | mit | 4,915 | master | 508 | require 'test/unit'
require 'nodejs'
class TestNodejsPathname < Test::Unit::TestCase
def self.windows_platform?
`process.platform`.start_with?('win')
end
def test_windows_pathname_absolute
assert_equal(true, Pathname.new('c:/foo').absolute?)
assert_equal(true, Pathname.new('/foo').absolute?)
ass... |
github | opal/opal | https://github.com/opal/opal | test/nodejs/test_io.rb | Ruby | mit | 4,915 | master | 403 | # Copied from cruby and modified to skip unsupported syntaxes
require 'test/unit'
require 'nodejs'
require 'nodejs/io'
class TestNodejsIO < Test::Unit::TestCase
def test_binread
File.write('tmp/foo', 'bar')
assert_equal("bar", IO.binread('tmp/foo'))
end
def test_binread_noexistent_should_raise_io_error... |
github | opal/opal | https://github.com/opal/opal | test/nodejs/test_file.rb | Ruby | mit | 4,915 | master | 9,035 | # backtick_javascript: true
# Copied from cruby and modified to skip unsupported syntaxes
require 'test/unit'
require 'nodejs'
require 'nodejs/file'
class TestNodejsFile < Test::Unit::TestCase
def tmpdir
`require('os').tmpdir()`
end
def self.windows_platform?
`process.platform`.start_with?('win')
end... |
github | opal/opal | https://github.com/opal/opal | test/nodejs/test_file_encoding.rb | Ruby | mit | 4,915 | master | 564 | require 'test/unit'
require 'nodejs'
require 'nodejs/file'
class TestNodejsFileEncoding < Test::Unit::TestCase
def test_force_encoding_raw_text_to_utf8
raw_text = 'çéà'
assert_equal(raw_text.encoding, Encoding::UTF_8)
utf8_text = raw_text.force_encoding('utf-8')
assert_equal("çéà", utf8_text)
end
... |
github | opal/opal | https://github.com/opal/opal | test/nodejs/test_tracepoint_end.rb | Ruby | mit | 4,915 | master | 2,139 | # frozen_string_literal: true
# await: *await
require "test/unit"
require "corelib/trace_point"
class TestTracePointEnd < Test::Unit::TestCase
HEADER = <<~RUBY
# await: true
require "await"
RUBY
def eval_and_await(code)
eval(code).__await__
end
def test_end_after_class_body_sync
code = <<~... |
github | opal/opal | https://github.com/opal/opal | examples/rack/config.ru | Ruby | mit | 4,915 | master | 737 | require 'bundler'
Bundler.require
# Instructions: bundle in this directory
# then run `bundle exec rackup` to start the server
# and browse to http://localhost:9292
# a very small application that just tries to authenticate a user and fails
# it just writes to the console in the browser (no visible html)
# with gems... |
github | opal/opal | https://github.com/opal/opal | examples/rack/app/application.rb | Ruby | mit | 4,915 | master | 433 | require 'opal'
require 'user'
require 'opal/platform'
module MyApp
class Application
def initialize
@user = User.new('Bob')
end
def title
"#{@user.name} is #{:not unless @user.authenticated?} authenticated"
end
end
end
$app = MyApp::Application.new
require 'native'
$$[:document][:ti... |
github | opal/opal | https://github.com/opal/opal | examples/rack/app/user.rb | Ruby | mit | 4,915 | master | 304 | class User
def initialize(name)
puts "wow"
@name = name
end
attr_reader :name
def authenticated?
if admin? or special_permission?
true
else
raise "not authenticated"
end
end
def admin?
@name == 'Bob'
end
def special_permission?
false
end
end |
github | opal/opal | https://github.com/opal/opal | examples/rack-esm/config.ru | Ruby | mit | 4,915 | master | 775 | require 'bundler'
Bundler.require
# Instructions: bundle in this directory
# then run `bundle exec rackup` to start the server
# and browse to http://localhost:9292
# a very small application that just tries to authenticate a user and fails
# it just writes to the console in the browser (no visible html)
# with gems... |
github | opal/opal | https://github.com/opal/opal | examples/sinatra/config.ru | Ruby | mit | 4,915 | master | 500 | require 'opal/sprockets'
require 'sinatra'
opal = Opal::Sprockets::Server.new {|s|
s.append_path 'app'
s.main = 'application'
}
sprockets = opal.sprockets
prefix = '/assets'
map prefix do
run sprockets
end
get '/' do
<<-HTML
<!doctype html>
<html>
<head>
<meta charset="utf-8">
... |
github | opal/opal | https://github.com/opal/opal | benchmark-ips/bm_u_string.rb | Ruby | mit | 4,915 | master | 28,865 | # helpers: coerce_to, opal32_init, opal32_add
# backtick_javascript: true
require 'benchmark/ips'
class String
%x{
function find_index(str, search_s, search_l, search) {
let search_f = search_s[0];
return str.findIndex((c, i, s) => {
return (c === search_f && (search_l === 1 || s.slice(i, i +... |
github | opal/opal | https://github.com/opal/opal | benchmark-ips/bm_symbol_to_proc.rb | Ruby | mit | 4,915 | master | 274 | # https://github.com/opal/opal/issues/1659#issuecomment-298222232
Benchmark.ips do |x|
a = []
50.times do |i|
a << %(#{i}\n)
end
x.report('map block') do
a.map {|it| it.chomp }
end
x.report('map symbol') do
a.map(&:chomp)
end
x.compare!
end |
github | opal/opal | https://github.com/opal/opal | benchmark-ips/bm_block_vs_yield.rb | Ruby | mit | 4,915 | master | 306 | module BmBlockVsYield
def self._block(&block)
block.call
end
def self._yield
yield
end
end
Benchmark.ips do |x|
x.warmup = 10
x.time = 60
x.report('block') do
BmBlockVsYield._block { 1+1 }
end
x.report('yield') do
BmBlockVsYield._yield { 1+1 }
end
x.compare!
end |
github | opal/opal | https://github.com/opal/opal | benchmark-ips/bm_array_shift.rb | Ruby | mit | 4,915 | master | 8,103 | Benchmark.ips do |x|
x.report("shift no arg") do
a = ['4768', '4964', '4266', '4872', '4231', '4017', '4565', '4793', '4298', '4135', '4639', '4780', '4237', '4548', '4655', '4153', '4654', '4922', '4563', '4042', '4329', '4699', '4352', '4127', '4544', '4906', '4814', '4948', '4977', '4830', '4405', '4642', '466... |
github | opal/opal | https://github.com/opal/opal | benchmark-ips/bm_is_number.rb | Ruby | mit | 4,915 | master | 1,210 | # Why .$$is_number is better than isNaN:
#
#
# Warming up --------------------------------------
# .$$is_number 106.722k i/100ms
# isNaN() 105.040k i/100ms
# obj.$$is_number 106.864k i/100ms
# isNaN(obj) 89.287k i/100ms
# Calculating -------------------------------------
# ... |
github | opal/opal | https://github.com/opal/opal | benchmark-ips/class_shovel_vs_singleton_class.rb | Ruby | mit | 4,915 | master | 246 | o = nil
Benchmark.ips do |x|
x.report('shovel') do
o = Object.new
class << o
attr_accessor :foo
end
end
x.report('singleton_class') do
o2 = Object.new
o2.singleton_class.attr_accessor :foo
end
x.compare!
end |
github | opal/opal | https://github.com/opal/opal | benchmark-ips/bm_js_symbols_vs_strings.rb | Ruby | mit | 4,915 | master | 939 | Benchmark.ips do |x|
%x{
const c_foo = 'foo'
const v_foo = 'foo'
const cfoo = Symbol('foo')
var vfoo = Symbol('foo')
const cgfoo = Symbol.for('foo')
var vgfoo = Symbol.for('foo')
var o = {}
o[cfoo] = 1
o[cgfoo] = 1
o[c_foo] = 1
o[vfoo] = 1
let a1 = 0, a2 = 0, a3 = 0, ... |
github | opal/opal | https://github.com/opal/opal | benchmark-ips/bm_array_unshift.rb | Ruby | mit | 4,915 | master | 8,121 | Benchmark.ips do |x|
x.report("unshift") do
a = ['4768', '4964', '4266', '4872', '4231', '4017', '4565', '4793', '4298', '4135', '4639', '4780', '4237', '4548', '4655', '4153', '4654', '4922', '4563', '4042', '4329', '4699', '4352', '4127', '4544', '4906', '4814', '4948', '4977', '4830', '4405', '4642', '4666', '... |
github | opal/opal | https://github.com/opal/opal | benchmark-ips/bm_while_true_vs_loop.rb | Ruby | mit | 4,915 | master | 243 | Benchmark.ips do |x|
x.report('while true') do
n = 0
while true
n += 1
break if n == 10000
end
end
x.report('loop') do
n = 0
loop do
n += 1
break if n == 10000
end
end
x.compare!
end |
github | opal/opal | https://github.com/opal/opal | benchmark-ips/bm_truthy.rb | Ruby | mit | 4,915 | master | 1,468 | Benchmark.ips do |x|
%x{
// Old version truthy logic
var old_version = function(x) { return x !== nil && x != null && (!x.$$is_boolean || x == true); }
// New version truthy logic
var new_version_1 = function(val) { return undefined !== val && null !== val && false !== val && nil !== val && (!(val ... |
github | opal/opal | https://github.com/opal/opal | benchmark-ips/bm_slice_or_not.rb | Ruby | mit | 4,915 | master | 1,136 | %x{
// Minify common function calls
var $call = Function.prototype.call;
var $bind = Function.prototype.bind;
var $has_own = Object.hasOwn || $call.bind(Object.prototype.hasOwnProperty);
var $set_proto = Object.setPrototypeOf;
var $slice = $call.bind(Array.prototype.slice);
var $splice ... |
github | opal/opal | https://github.com/opal/opal | benchmark-ips/bm_constants_lookup.rb | Ruby | mit | 4,915 | master | 249 | module A
module B
module C
Benchmark.ips do |x|
x.report("Kernel") { Kernel }
x.report("::Kernel") { ::Kernel }
x.report("B") { B }
x.report("B::C") { B::C }
x.compare!
end
end
end
end |
github | opal/opal | https://github.com/opal/opal | benchmark-ips/bm_case.rb | Ruby | mit | 4,915 | master | 501 | Benchmark.ips do |x|
obj = Object.new
x.report("numeric statement") do
case 1
when 4 then 4
when 3 then 3
when 2 then 2
when 1 then 1
end
nil
end
x.report("statement") do
case 1
when 4 then 4
when 3 then 3
when 2 then 2
when obj then :obj
when 1 then 1
end... |
github | opal/opal | https://github.com/opal/opal | benchmark-ips/bm_array_pop_1.rb | Ruby | mit | 4,915 | master | 8,099 | Benchmark.ips do |x|
x.report('pop(1)') do
a = ['4768', '4964', '4266', '4872', '4231', '4017', '4565', '4793', '4298', '4135', '4639', '4780', '4237', '4548', '4655', '4153', '4654', '4922', '4563', '4042', '4329', '4699', '4352', '4127', '4544', '4906', '4814', '4948', '4977', '4830', '4405', '4642', '4666', '4... |
github | opal/opal | https://github.com/opal/opal | tasks/building.rake | Ruby | mit | 4,915 | master | 3,067 | require 'opal/version'
desc <<-DESC
Build *corelib* and *stdlib* to "build/"
You can restrict the file list with the FILES env var (comma separated)
and the destination dir with the DIR env var, FORMATS to select output formats.
Example: rake dist DIR=/tmp/foo FILES='opal.rb,base64.rb'
Example: rake dist DIR=cdn/opa... |
github | opal/opal | https://github.com/opal/opal | tasks/testing.rake | Ruby | mit | 4,915 | master | 17,391 | require_relative "#{__dir__}/../lib/opal/os"
require_relative "#{__dir__}/../lib/opal/cli_runners"
require 'timeout'
require 'rspec/core/rake_task'
OS = Opal::OS unless defined? OS
RSpec::Core::RakeTask.new(:rspec) do |t|
t.pattern = 'spec/lib/**/*_spec.rb'
end
if ENV.key?('RUBYSPEC')
warn "Did you mean RUBYSPE... |
github | opal/opal | https://github.com/opal/opal | tasks/releasing.rake | Ruby | mit | 4,915 | master | 4,013 | # frozen_string_literal: true
require 'bundler'
Bundler.require
Bundler::GemHelper.install_tasks
github_releases = -> do
require 'date'
require 'octokit'
Octokit.auto_paginate = true
Octokit.releases('opal/opal').sort_by do |r|
Gem::Version.new(r[:tag_name][1..-1])
end.select do |release|
release[:... |
github | opal/opal | https://github.com/opal/opal | tasks/linting.rake | Ruby | mit | 4,915 | master | 898 | import 'tasks/building.rake'
namespace :lint do
desc "Build *corelib* and *stdlib* and lint the result"
task :eslint do
require 'json'
require 'pathname'
result_path = "tmp/lint/result.json"
dir = ENV['DIR'] ||= 'tmp/lint'
ENV['FORMATS'] = 'js,map'
rm_rf dir if File.exist? dir
Rake::... |
github | opal/opal | https://github.com/opal/opal | tasks/performance.rake | Ruby | mit | 4,915 | master | 7,111 | # A set of tasks to track performance regressions by the CI
require_relative "#{__dir__}/../lib/opal/util"
require_relative "#{__dir__}/../lib/opal/os"
OS = Opal::OS unless defined? OS
class Timing
def initialize(tries: 31, &block)
@tries = tries
@times = tries.times.map do
t = now
block.()
... |
github | opal/opal | https://github.com/opal/opal | tasks/github.rake | Ruby | mit | 4,915 | master | 1,124 | namespace :github do
desc "Upload assets to github"
task :upload_assets do
require 'octokit'
# https://github.com/octokit/octokit.rb#oauth-access-tokens
token_path = '.github_access_token'
File.exist?(token_path) or raise ArgumentError, "Please create a personal access token (https://github.com/sett... |
github | opal/opal | https://github.com/opal/opal | tasks/benchmarking.rake | Ruby | mit | 4,915 | master | 5,066 | require_relative '../lib/opal/version'
require_relative '../lib/opal/cli_runners'
namespace :bench do
directory "tmp/bench"
report_file_for = -> name {
index = Dir['tmp/bench/*'].map{|f| File.basename(f).to_i}.sort.last.to_i + 1
"tmp/bench/#{index}_#{name.gsub('.', '-')}.txt"
}
runners = Opal::CliRun... |
github | opal/opal | https://github.com/opal/opal | tasks/testing/mspec_special_calls.rb | Ruby | mit | 4,915 | master | 2,009 | require 'opal/nodes/call'
require 'opal/ast/builder'
class Opal::Nodes::CallNode
# Rubyspec uses these calls features at runtime.
# We can't do this at runtime, so handle it during compilation
add_special :not_supported_on do |compile_default|
unless arglist.children.include?(s(:sym, :opal))
compile_d... |
github | opal/opal | https://github.com/opal/opal | tasks/performance/optimization_status.rb | Ruby | mit | 4,915 | master | 1,784 | # backtick_javascript: true
klasses = [
Array,
Class,
# Complex,
# Dir,
Enumerable,
Enumerator,
Exception,
Hash,
# Kernel,
Math,
Method,
Module,
Object,
Proc,
Range,
Rational,
Regexp,
Struct,
String,
Time
]
%x{
function getOptimizationStatus(fn) {
var optstatus = %GetOpti... |
github | opal/opal | https://github.com/opal/opal | spec/spec_helper.rb | Ruby | mit | 4,915 | master | 834 | # backtick_javascript: true
require 'opal'
require 'set'
require 'opal/platform'
require 'opal-parser'
require 'mspec'
require 'mspec/version'
require 'support/mspec_rspec_adapter'
require 'support/guard_platform'
require 'mspec-opal/runner'
# Node v0.12 as well as Google Chrome/V8 42.0.2311.135 (64-bit)
# showed to ... |
github | opal/opal | https://github.com/opal/opal | spec/lib/project_spec.rb | Ruby | mit | 4,915 | master | 1,896 | require 'lib/spec_helper'
RSpec.describe Opal::Project do
context "when used by Builder" do
let(:builder) do
b = Opal::Builder.new
b.append_paths(__dir__+"/fixtures/project")
b
end
it "adds a project and adds a load path from Opalfile if a file is built" do
b = builder
b.bu... |
github | opal/opal | https://github.com/opal/opal | spec/lib/repl_spec.rb | Ruby | mit | 4,915 | master | 721 | require 'lib/spec_helper'
require 'opal/repl'
RSpec.describe Opal::REPL do
describe '#eval_ruby' do
let(:input_and_output) { {
'puts 5' => "5\n=> nil\n",
'a = 1' => "=> 1\n",
'a += 1' => "=> 2\n",
'a + 3' => "=> 5\n",
'puts a + 3' => "5\n=>... |
github | opal/opal | https://github.com/opal/opal | spec/lib/simple_server_spec.rb | Ruby | mit | 4,915 | master | 4,719 | require 'lib/spec_helper'
require 'rack/test'
RSpec.describe Opal::SimpleServer do
include Rack::Test::Methods
attr_accessor :app
# Ensure that each `get` call leads to a new rack session.
def get(path)
rack_test_session(nil).get(path)
end
shared_examples "simple server" do
before do
Opal.... |
github | opal/opal | https://github.com/opal/opal | spec/lib/paths_spec.rb | Ruby | mit | 4,915 | master | 514 | require 'lib/spec_helper'
RSpec.describe 'Opal.use_gem' do
# Coverage probably should be improved
it 'adds require_paths of a gem to Opal paths' do
begin
Opal.use_gem 'rake'
rescue Opal::GemNotFound => e
raise(e) unless e.gem_name == 'rake'
skip %(Will fail if GEM_HOME has "rake" in the ... |
github | opal/opal | https://github.com/opal/opal | spec/lib/rake_dist_spec.rb | Ruby | mit | 4,915 | master | 2,125 | require 'lib/spec_helper'
require 'fileutils'
require 'open3'
require 'opal/os'
require 'tmpdir'
RSpec.describe "rake dist" do
before :all do
@build_dir = Dir.mktmpdir('opal-dist-spec-')
built = system(
{
'DIR' => @build_dir,
'FILES' => 'opal,opal/mini,opal/full,opal-replutils',
... |
github | opal/opal | https://github.com/opal/opal | spec/lib/compiler_spec.rb | Ruby | mit | 4,915 | master | 25,376 | require 'lib/spec_helper'
require 'support/match_helpers'
RSpec.describe Opal::Compiler do
describe 'regexp' do
it 'should escape regexp' do
expect_compiled("%r{^/{4,}$}").to include('/^\/{4,}$/')
expect_compiled('/\\\\"/').to include('/\\\\"/')
end
end
describe 'requiring' do
it 'calls ... |
github | opal/opal | https://github.com/opal/opal | spec/lib/builder_processors_spec.rb | Ruby | mit | 4,915 | master | 1,347 | require 'lib/spec_helper'
require 'opal/builder/processor'
RSpec.describe Opal::Builder::Processor::JsProcessor do
it 'maps to one fragment per line' do
processor = described_class.new("line1\n line2\n line3", 'file.js')
expect(processor.source_map.fragments.map(&:code)).to eq([
"line1\n",
" lin... |
github | opal/opal | https://github.com/opal/opal | spec/lib/path_reader_spec.rb | Ruby | mit | 4,915 | master | 1,401 | require 'lib/spec_helper'
require 'opal/path_reader'
RSpec.describe Opal::PathReader do
subject(:path_reader) { described_class.new }
let(:path) { 'opal_file' }
let(:full_path) { File.expand_path('../fixtures/opal_file.rb', __FILE__) }
let(:contents) { File.read(full_path, mode: "rb:UTF-8") }
before do
... |
github | opal/opal | https://github.com/opal/opal | spec/lib/deprecations_spec.rb | Ruby | mit | 4,915 | master | 422 | require 'lib/spec_helper'
require 'opal/deprecations'
RSpec.describe Opal::Deprecations do
subject { Object.new.extend described_class }
it 'defaults to warn' do
expect(subject).to receive(:warn)
subject.deprecation "there's a new api!"
end
it 'can be set to raise' do
subject.raise_on_deprecation... |
github | opal/opal | https://github.com/opal/opal | spec/lib/cli_runners_spec.rb | Ruby | mit | 4,915 | master | 437 | require 'lib/spec_helper'
require 'opal/cli_runners'
RSpec.describe Opal::CliRunners do
around do |example|
original_register = described_class.instance_variable_get :@register
example.run
described_class.instance_variable_set :@register, original_register
end
describe '.alias_runner' do
it 'ali... |
github | opal/opal | https://github.com/opal/opal | spec/lib/dependency_resolver_spec.rb | Ruby | mit | 4,915 | master | 1,568 | require 'lib/spec_helper'
RSpec.describe Opal::Nodes::CallNode::DependencyResolver do
let(:compiler) { double(:compiler, dynamic_require_severity: :warning) }
it "resolves simple strings to themselves" do
expect(resolve s(:str, 'foo')).to eq('foo')
end
context "using a dynamic segment not supported" do
... |
github | opal/opal | https://github.com/opal/opal | spec/lib/config_spec.rb | Ruby | mit | 4,915 | master | 5,639 | require 'lib/spec_helper'
require 'opal/config'
RSpec.describe Opal::Config do
before { described_class.reset! }
after { described_class.reset! }
describe '.default_config' do
it 'is new each time' do
default_config1 = described_class.default_config
default_config2 = described_class.default_conf... |
github | opal/opal | https://github.com/opal/opal | spec/lib/spec_helper.rb | Ruby | mit | 4,915 | master | 5,003 | $VERBOSE = true
if ENV['CHECK_COVERAGE']
require 'coveralls'
Coveralls.wear!
end
if ENV['CHECK_COVERAGE_SIMPLECOV']
require 'simplecov'
SimpleCov.start
end
require 'opal'
ENV['OPAL_DISABLE_PREFORK_LOGS'] = '1'
$diagnostic_messages = []
Opal::Parser.default_parser_class.diagnostics_consumer = ->(diagnostic)... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.