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 | riemann/riemann-tools | https://github.com/riemann/riemann-tools | lib/riemann/tools/tls_check.rb | Ruby | mit | 181 | main | 19,896 | # frozen_string_literal: true
require 'net/http'
require 'resolv'
require 'riemann/tools'
require 'riemann/tools/utils'
module URI
{
'IMAP' => 143,
'IMAPS' => 993,
'MYSQL' => 3306,
'POSTGRES' => 5432,
}.each do |scheme, port|
klass = Class.new(Generic)
klass.const_set('DEFAULT_P... |
github | riemann/riemann-tools | https://github.com/riemann/riemann-tools | lib/riemann/tools/zpool.rb | Ruby | mit | 181 | main | 862 | # frozen_string_literal: true
require 'open3'
require 'riemann/tools'
module Riemann
module Tools
class Zpool
include Riemann::Tools
def tick
output, status = Open3.capture2e('zpool status -x')
state = if status.success?
case output
when "all po... |
github | riemann/riemann-tools | https://github.com/riemann/riemann-tools | lib/riemann/tools/net.rb | Ruby | mit | 181 | main | 4,182 | # frozen_string_literal: true
require 'riemann/tools'
# Gathers network interface statistics and submits them to Riemann.
module Riemann
module Tools
class Net
include Riemann::Tools
opt :interfaces, 'Interfaces to monitor', type: :strings, default: nil
opt :ignore_interfaces, 'Interfaces to ... |
github | riemann/riemann-tools | https://github.com/riemann/riemann-tools | lib/riemann/tools/dir_files_count.rb | Ruby | mit | 181 | main | 1,718 | # frozen_string_literal: true
require 'riemann/tools'
# Gets the number of files present on a directory and submits it to riemann
module Riemann
module Tools
class DirFilesCount
include Riemann::Tools
opt :directory, '', default: '/var/log'
opt :service_prefix, 'The first part of the service ... |
github | riemann/riemann-tools | https://github.com/riemann/riemann-tools | lib/riemann/tools/proc.rb | Ruby | mit | 181 | main | 3,824 | # frozen_string_literal: true
require 'riemann/tools'
# Reports running process count to riemann.
module Riemann
module Tools
class Proc
include Riemann::Tools
opt :proc_regex, 'regular expression that matches the process to be monitored', type: :string, default: '.*'
opt :proc_min_critical, ... |
github | riemann/riemann-tools | https://github.com/riemann/riemann-tools | spec/spec_helper.rb | Ruby | mit | 181 | main | 1,013 | # frozen_string_literal: true
ARGV.replace([])
RSpec.configure do |config|
# Limits the available syntax to the non-monkey patched syntax that is
# recommended. For more details, see:
# https://relishapp.com/rspec/rspec-core/docs/configuration/zero-monkey-patching-mode
config.disable_monkey_patching!
# Thi... |
github | riemann/riemann-tools | https://github.com/riemann/riemann-tools | spec/riemann/tools_spec.rb | Ruby | mit | 181 | main | 762 | # frozen_string_literal: true
require 'riemann/tools/health'
class ExampleTool
include Riemann::Tools
end
RSpec.describe Riemann::Tools do
describe '#options' do
describe ':ttl' do
subject(:tool) { ExampleTool.new }
{
'' => 10,
'--ttl=60' ... |
github | riemann/riemann-tools | https://github.com/riemann/riemann-tools | spec/riemann/tools/net_spec.rb | Ruby | mit | 181 | main | 6,888 | # frozen_string_literal: true
require 'riemann/tools/net'
RSpec.describe Riemann::Tools::Net do
describe('#report_interface?') do
it 'selects interfaces by name' do
subject.instance_variable_set(:@interfaces, %w[wlan0 wlan1])
subject.instance_variable_set(:@ignore_interfaces, %w[wlan1])
expec... |
github | riemann/riemann-tools | https://github.com/riemann/riemann-tools | spec/riemann/tools/utils_spec.rb | Ruby | mit | 181 | main | 1,020 | # frozen_string_literal: true
require 'riemann/tools/utils'
class TestClass
include Riemann::Tools::Utils
end
RSpec.describe Riemann::Tools::Utils do
describe('#reverse_numeric_sort_with_header') do
subject { TestClass.new.reverse_numeric_sort_with_header(input) }
let(:input) do
<<~INPUT
H... |
github | riemann/riemann-tools | https://github.com/riemann/riemann-tools | spec/riemann/tools/mdstat_parser_spec.rb | Ruby | mit | 181 | main | 1,202 | # frozen_string_literal: true
require 'riemann/tools/mdstat_parser.tab'
RSpec.describe Riemann::Tools::MdstatParser do
{
'example-1' => {},
'example-2' => {},
'example-3' => { 'md2' => 'UU' },
'example-4' => { 'md4' => 'UU', 'md2' => 'UU', 'md3' => 'UU' },
'example-5' => { 'md2' => 'UU', 'm... |
github | riemann/riemann-tools | https://github.com/riemann/riemann-tools | spec/riemann/tools/riemann_client_wrapper_spec.rb | Ruby | mit | 181 | main | 650 | # frozen_string_literal: true
require 'riemann/tools/riemann_client_wrapper'
RSpec.describe Riemann::Tools::RiemannClientWrapper do
subject do
instance = described_class.new({})
client_mock = double
allow(client_mock).to receive(:bulk_send)
allow(instance).to receive(:client).and_return(client_mock)... |
github | riemann/riemann-tools | https://github.com/riemann/riemann-tools | spec/riemann/tools/health_spec.rb | Ruby | mit | 181 | main | 18,089 | # frozen_string_literal: true
require 'riemann/tools/health'
RSpec.describe Riemann::Tools::Health do
describe('#human_size_to_number') do
subject { described_class.new.human_size_to_number(input) }
{
'512' => 512,
'1k' => 1024,
'2K' => 2048,
'42m' => 44_040_192,
}.each do |in... |
github | riemann/riemann-tools | https://github.com/riemann/riemann-tools | spec/riemann/tools/md_spec.rb | Ruby | mit | 181 | main | 4,664 | # frozen_string_literal: true
require 'riemann/tools/md'
RSpec.describe Riemann::Tools::Md do
describe('#tick') do
context 'when all md devices are healthy' do
before do
allow(File).to receive(:read).with('/proc/mdstat').and_return(File.read('spec/fixtures/mdstat/example-8'))
end
it '... |
github | riemann/riemann-tools | https://github.com/riemann/riemann-tools | spec/riemann/tools/haproxy_spec.rb | Ruby | mit | 181 | main | 1,893 | # frozen_string_literal: true
require 'riemann/tools/haproxy'
RSpec.describe Riemann::Tools::Haproxy do
describe('#tick') do
before do
ARGV.replace(['--stats-url', 'http://localhost'])
allow(subject).to receive(:body).and_return(<<~DATA)
# pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bou... |
github | riemann/riemann-tools | https://github.com/riemann/riemann-tools | spec/riemann/tools/tls_check_spec.rb | Ruby | mit | 181 | main | 1,202 | # frozen_string_literal: true
require 'riemann/tools/tls_check'
RSpec.describe Riemann::Tools::TLSCheck do
describe '#test_uri' do
before do
allow(subject).to receive(:report)
subject.test_uri_addresses(uri, addresses)
end
let(:addresses) do
Resolv.getaddresses(uri.hostname)
end
... |
github | riemann/riemann-tools | https://github.com/riemann/riemann-tools | spec/riemann/tools/http_check_spec.rb | Ruby | mit | 181 | main | 21,302 | # frozen_string_literal: true
require 'openssl'
require 'rackup/handler/webrick'
require 'sinatra/base'
require 'webrick'
require 'webrick/https'
require 'riemann/tools/http_check'
class TestWebserver < Sinatra::Base
set :host_authorization, { permitted_hosts: [] }
def authorized?
@auth ||= Rack::Auth::Basi... |
github | riemann/riemann-tools | https://github.com/riemann/riemann-tools | spec/riemann/tools/zpool_spec.rb | Ruby | mit | 181 | main | 2,134 | # frozen_string_literal: true
require 'riemann/tools/zpool'
RSpec.describe Riemann::Tools::Zpool do
describe('#tick') do
before do
process_status = double
allow(process_status).to receive(:success?).and_return(true)
allow(Open3).to receive(:capture2e).with('zpool status -x').and_return([File.r... |
github | riemann/riemann-tools | https://github.com/riemann/riemann-tools | spec/riemann/tools/uptime_parser_spec.rb | Ruby | mit | 181 | main | 1,481 | # frozen_string_literal: true
require 'riemann/tools/uptime_parser.tab'
RSpec.describe Riemann::Tools::UptimeParser do
{
# FreeBSD 13
"11:10 up 3:40, 1 user, load averages: 0,25 0,67 0,68\n" => {
uptime: 13_200,
users: 1,
load_averages: {
1 => 0.25,
5 => 0.... |
github | riemann/riemann-tools | https://github.com/riemann/riemann-tools | spec/riemann/tools/hwmon/device_spec.rb | Ruby | mit | 181 | main | 1,885 | # frozen_string_literal: true
require 'riemann/tools/hwmon'
RSpec.describe Riemann::Tools::Hwmon::Device do
subject { described_class.new(1, :temp, 2) }
before do
allow(File).to receive(:realpath).with('/sys/class/hwmon/hwmon1/name').and_return(device_path)
allow(File).to receive(:read).with('/sys/class/... |
github | riemann/riemann-tools | https://github.com/riemann/riemann-tools | spec/riemann/tools/tls_check/tls_check_result_spec.rb | Ruby | mit | 181 | main | 1,447 | # frozen_string_literal: true
require 'active_support'
require 'active_support/core_ext/numeric'
require 'riemann/tools/tls_check'
def gen_certificate(not_before, validity_duration_days)
certificate = OpenSSL::X509::Certificate.new
certificate.not_before = not_before
certificate.not_after = certificate.not_bef... |
github | quirkey/vegas | https://github.com/quirkey/vegas | Rakefile | Ruby | mit | 181 | master | 1,510 | %w[rubygems rake rake/clean rake/testtask fileutils].each { |f| require f }
require File.dirname(__FILE__) + '/lib/vegas'
begin
require 'jeweler'
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end
VEGAS_VERSION = if ENV["DEV"]
"#{Vegas::VERSION}.#{Time... |
github | quirkey/vegas | https://github.com/quirkey/vegas | vegas.gemspec | Ruby | mit | 181 | master | 2,126 | # 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 = "vegas"
s.version = "0.1.11"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_... |
github | quirkey/vegas | https://github.com/quirkey/vegas | lib/vegas.rb | Ruby | mit | 181 | master | 309 | begin
require 'rack'
require 'rbconfig'
rescue LoadError
require 'rubygems'
require 'rack'
end
module Vegas
VERSION = "0.1.11"
WINDOWS = !!(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i)
JRUBY = !!(RbConfig::CONFIG["RUBY_INSTALL_NAME"] =~ /^jruby/i)
autoload :Runner, 'vegas/runner'
end |
github | quirkey/vegas | https://github.com/quirkey/vegas | lib/vegas/runner.rb | Ruby | mit | 181 | master | 11,396 | require 'open-uri'
require 'logger'
require 'optparse'
require 'fileutils'
if Vegas::WINDOWS
begin
require 'win32/process'
rescue
puts "Sorry, in order to use Vegas on Windows you need the win32-process gem:",
"gem install win32-process"
end
end
module Vegas
class Runner
attr_reader :app,... |
github | quirkey/vegas | https://github.com/quirkey/vegas | test/apps.rb | Ruby | mit | 181 | master | 362 | class TestApp1 < Sinatra::Base
get '/' do
'TestApp1 Index'
end
get '/route' do
'TestApp1 route'
end
end
class TestApp2 < Sinatra::Base
get '/' do
'TestApp2 Index'
end
get '/route' do
'TestApp2 route'
end
end
RackApp1 = Proc.new {|env|
[200, {'Content-Type' => 'text/plai... |
github | quirkey/vegas | https://github.com/quirkey/vegas | test/test_helper.rb | Ruby | mit | 181 | master | 1,126 | dependencies = %w{
bacon
mocha/standalone
mocha/object
sinatra
}
begin
dependencies.each {|f| require f }
rescue LoadError
require 'rubygems'
dependencies.each {|f| require f }
end
require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'vegas.rb')
require File.join(File.expand_path(Fil... |
github | quirkey/vegas | https://github.com/quirkey/vegas | test/test_vegas_runner.rb | Ruby | mit | 181 | master | 5,458 | require 'test_helper'
Vegas::Runner.class_eval do
remove_const :ROOT_DIR
Vegas::Runner::ROOT_DIR = File.join(File.dirname(__FILE__), 'tmp', '.vegas')
end
describe 'Vegas::Runner' do
before do
FileUtils.rm_rf(File.join(File.dirname(__FILE__), 'tmp'))
@log = StringIO.new
Vegas::Runner.logger = Logger.... |
github | carlosbrando/autotest-notification | https://github.com/carlosbrando/autotest-notification | Rakefile | Ruby | mit | 181 | master | 863 | require 'rubygems'
require 'bundler/setup'
require 'hoe'
require 'fileutils'
require './lib/autotest_notification.rb'
Hoe.plugin :newgem
# Hoe.plugin :website
# Hoe.plugin :cucumberfeatures
# Generate all the Rake tasks
# Run 'rake -T' to see list of generated tasks (from gem root directory)
$hoe = Hoe.spec 'autote... |
github | carlosbrando/autotest-notification | https://github.com/carlosbrando/autotest-notification | autotest-notification.gemspec | Ruby | mit | 181 | master | 3,800 | # -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{autotest-notification}
s.version = "2.3.4"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Carlos Brando"]
s.date = %q{2011-07-18}
s.description = %q{This gem set the a... |
github | carlosbrando/autotest-notification | https://github.com/carlosbrando/autotest-notification | test/test_autotest_notification.rb | Ruby | mit | 181 | master | 1,456 | $:.unshift(File.expand_path('.', File.dirname(__FILE__)))
require 'test_helper'
class TestAutotestNotification < Test::Unit::TestCase
def setup
@title = "title"
@msg = "message"
@image = "image"
@priority = 0
@total = 0
@failures = 0
%w( DOOM_EDITION SPEAKING STICKY BUUF )... |
github | carlosbrando/autotest-notification | https://github.com/carlosbrando/autotest-notification | test/test_helper.rb | Ruby | mit | 181 | master | 817 | $:.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
require "test/unit"
require "rubygems"
require 'autotest'
require "mocha"
require 'autotest_notification' unless defined?(AutotestNotification)
class Test::Unit::TestCase
def turn_methods_public(classe, method_name = nil)
if method_name
classe... |
github | carlosbrando/autotest-notification | https://github.com/carlosbrando/autotest-notification | test/autotest_notification/test_freebsd.rb | Ruby | mit | 181 | master | 3,585 | $:.unshift(File.expand_path('..', File.dirname(__FILE__)))
require 'test_helper'
class TestFreeBSD < Test::Unit::TestCase
def setup
turn_methods_public AutotestNotification::FreeBSD
AutotestNotification.const_set :DOOM_EDITION, false
AutotestNotification.const_set :SPEAKING, false
AutotestNotificati... |
github | carlosbrando/autotest-notification | https://github.com/carlosbrando/autotest-notification | test/autotest_notification/test_cygwin.rb | Ruby | mit | 181 | master | 413 | $:.unshift(File.expand_path('..', File.dirname(__FILE__)))
require 'test_helper'
class TestCygwin < Test::Unit::TestCase
def test_notify
AutotestNotification::Cygwin.expects(:get_image_path).with("image").returns(" image ")
AutotestNotification::Cygwin.expects(:system).with('sncmd /m \'title\' \'msg\'... |
github | carlosbrando/autotest-notification | https://github.com/carlosbrando/autotest-notification | test/autotest_notification/test_mac.rb | Ruby | mit | 181 | master | 3,233 | $:.unshift(File.expand_path('..', File.dirname(__FILE__)))
require 'test_helper'
class TestMac < Test::Unit::TestCase
def setup
AutotestNotification.const_set :DOOM_EDITION, false
AutotestNotification.const_set :SPEAKING, false
AutotestNotification.const_set :STICKY, false
AutotestNotification.const... |
github | carlosbrando/autotest-notification | https://github.com/carlosbrando/autotest-notification | test/autotest_notification/test_linux.rb | Ruby | mit | 181 | master | 3,505 | $:.unshift(File.expand_path('..', File.dirname(__FILE__)))
require 'test_helper'
class TestLinux < Test::Unit::TestCase
def setup
turn_methods_public AutotestNotification::Linux
AutotestNotification.const_set :DOOM_EDITION, false
AutotestNotification.const_set :SPEAKING, false
AutotestNotification.c... |
github | carlosbrando/autotest-notification | https://github.com/carlosbrando/autotest-notification | test/autotest_notification/test_windows.rb | Ruby | mit | 181 | master | 298 | $:.unshift(File.expand_path('..', File.dirname(__FILE__)))
require 'test_helper'
class Snarl
end
class TestWindows < Test::Unit::TestCase
def test_notify
Snarl.expects(:show_message).with("title", "msg", "image")
AutotestNotification::Windows.notify("title", "msg", "image")
end
end |
github | carlosbrando/autotest-notification | https://github.com/carlosbrando/autotest-notification | lib/autotest_notification.rb | Ruby | mit | 181 | master | 4,994 | require "autotest"
$:.unshift(File.dirname(__FILE__))
module AutotestNotification
VERSION = '2.3.4'
class Config
class << self
attr_reader :images_directory
attr_accessor :success_image, :fail_image, :pending_image, :expiration_in_seconds
def images_directory=(path)
@images_direct... |
github | carlosbrando/autotest-notification | https://github.com/carlosbrando/autotest-notification | lib/autotest_notification/cygwin.rb | Ruby | mit | 181 | master | 1,082 | module AutotestNotification
class Cygwin
@last_test_failed = false
class << self
def notify(title, msg, img, total = 1, failures = 0)
img = get_image_path(img).strip
system "sncmd /m '#{title}' '#{msg}' '#{img}' /t #{Config.expiration_in_seconds}"
play(SUCCESS_SOUND) if Autotes... |
github | carlosbrando/autotest-notification | https://github.com/carlosbrando/autotest-notification | lib/autotest_notification/freebsd.rb | Ruby | mit | 181 | master | 685 | $:.unshift(File.dirname(__FILE__))
require 'linux'
module AutotestNotification
# FreeBSD specifics; using Linux behavior as a base.
class FreeBSD < Linux
class << self
def say(total, failures)
if failures > 0
DOOM_EDITION ? Doom.play_sound(total, failures) : system("/usr/local/b... |
github | carlosbrando/autotest-notification | https://github.com/carlosbrando/autotest-notification | lib/autotest_notification/doom.rb | Ruby | mit | 181 | master | 831 | module AutotestNotification
class Doom
class << self
def image(total, failures)
"#{Config.images_directory}/doom/doom_#{percent(total, failures)}.png"
end
def play_sound(total, failures)
sound_file = "#{File.expand_path(File.dirname(__FILE__) + "/../../sounds/doom/")}/#{percen... |
github | carlosbrando/autotest-notification | https://github.com/carlosbrando/autotest-notification | lib/autotest_notification/windows.rb | Ruby | mit | 181 | master | 241 | require 'snarl' if RUBY_PLATFORM =~ /mswin/ or RUBY_PLATFORM =~ /mingw/
module AutotestNotification
class Windows
class << self
def notify(title, msg, img)
Snarl.show_message(title, msg, img)
end
end
end
end |
github | carlosbrando/autotest-notification | https://github.com/carlosbrando/autotest-notification | lib/autotest_notification/mac.rb | Ruby | mit | 181 | master | 1,180 | module AutotestNotification
class Mac
@last_test_failed = false
class << self
def notify(title, msg, img, total = 1, failures = 0, priority = 0)
system "growlnotify -n autotest --image #{img} #{'-s ' if ((failures > 0) and STICKY)}-p #{priority} -m '#{msg}' -t #{title}"
play(SUCC... |
github | carlosbrando/autotest-notification | https://github.com/carlosbrando/autotest-notification | lib/autotest_notification/linux.rb | Ruby | mit | 181 | master | 1,848 | module AutotestNotification
class Linux
class << self
def notify(title, msg, img, total = 1, failures = 0, priority = 0)
Config.expiration_in_seconds = 0 if failures > 0 && STICKY
if has_notify?
notify_send(title, msg, img, priority)
elsif has_zenity?
zenity(tit... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | Rakefile | Ruby | mit | 181 | main | 403 | require "bundler/setup"
require "rake/testtask"
require "bundler"
Bundler::GemHelper.install_tasks
Rake::TestTask.new do
# let the user pass *.rb on the command line
files = ARGV.grep(%r{^test/.*\.rb$}).sort
_1.test_files = files.empty? ? FileList["test/**/test_*.rb"] : files
# autoload test_helper
_1.ruby_o... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | table_tennis.gemspec | Ruby | mit | 181 | main | 893 | require_relative "lib/table_tennis/version"
Gem::Specification.new do |s|
s.name = "table_tennis"
s.version = TableTennis::VERSION
s.authors = ["Adam Doppelt"]
s.email = "amd@gurge.com"
s.summary = "Stylish tables in your terminal."
s.homepage = "https://github.com/gurgeous/table_tennis"
s.license = "MI... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | Gemfile | Ruby | mit | 181 | main | 459 | source "https://rubygems.org"
gemspec
group :development, :test do
gem "amazing_print", "~> 2.0"
gem "image_optim", "~> 0.31"
gem "image_optim_pack", "~> 0.12"
gem "minitest", "~> 5.27"
gem "minitest-hooks", "~> 1.5"
gem "mocha", "~> 3.0"
gem "ostruct", "~> 0.6" # required for Ruby 3.5+
gem "pry", "~> ... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | lib/table_tennis.rb | Ruby | mit | 181 | main | 827 | # gems
require "csv"
require "ffi"
require "forwardable"
require "io/console"
require "memo_wise"
require "paint"
require "unicode/display_width"
# mixins must be at top
require "table_tennis/util/inspectable"
require "table_tennis/util/magic_options"
require "table_tennis/column"
require "table_tennis/config"
requir... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | lib/table_tennis/config.rb | Ruby | mit | 181 | main | 3,792 | module TableTennis
class << self
attr_accessor :defaults
end
# Table configuration options, with schema validation courtesy of MagicOptions.
class Config < Util::MagicOptions
OPTIONS = {
coerce: true, # if true, we try to coerce strings into numbers
color_scales: nil, # columns => color sca... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | lib/table_tennis/theme.rb | Ruby | mit | 181 | main | 3,801 | module TableTennis
# This class contains the current theme, as well as the definitions for all
# themes.
class Theme
prepend MemoWise
RESET = Paint::NOTHING
OSC_8 = "\e]8;;"
ST = "\e\\"
NHEADER_COLORS = 6
THEMES = {
dark: {
title: ["blue-400", :bold],
chrome: "gray-... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | lib/table_tennis/row.rb | Ruby | mit | 181 | main | 263 | module TableTennis
# We use this to store each row of data in the table. Row is an array, but with `r` too.
class Row < Array
# r is the index of this row
attr_reader :r
def initialize(r, values)
super(values)
@r = r
end
end
end |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | lib/table_tennis/column.rb | Ruby | mit | 181 | main | 1,348 | module TableTennis
# A single column in a table. The data is actually stored in the rows, but it
# can be enumerated from here.
class Column
extend Forwardable
include Enumerable
include Util::Inspectable
prepend MemoWise
# c is the column index
attr_reader :name, :data, :c
attr_acces... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | lib/table_tennis/table_data.rb | Ruby | mit | 181 | main | 5,766 | module TableTennis
# This class stores our data as rows & columns. The initialization is a little
# tricky due to memoization and some ordering issues, but basically works like
# this:
#
# 1) Start with input_rows.
# 2) Calculate `fat_rows` which is an array of hashes with all keys. This
# might be too... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | lib/table_tennis/table.rb | Ruby | mit | 181 | main | 2,220 | #
# Welcome to TableTennis! Use as follows:
#
# puts TableTennis.new(array_of_hashes, options = {})
#
module TableTennis
# Public API for TableTennis.
class Table
extend Forwardable
include Util::Inspectable
attr_reader :data
def_delegators :data, *%i[column_names columns config rows]
def_dele... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | lib/table_tennis/util/inspectable.rb | Ruby | mit | 181 | main | 653 | module TableTennis
module Util
# A mixin to avoid putting all row data into xxx.inspect. This makes
# development much easier.
module Inspectable
def inspect
vars = instance_variables.filter_map do
next if _1 == :@data || _1 == :@_memo_wise
value = instance_variable_get(_... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | lib/table_tennis/util/strings.rb | Ruby | mit | 181 | main | 3,393 | module TableTennis
module Util
# Helpers for measuring and truncating strings.
module Strings
prepend MemoWise
module_function
ANSI_CODE = /\e\[[0-9;]*m/
# does this string contain ansi codes?
def painted?(str) = str.match?(/\e/)
# strip ansi codes
def unpaint(str... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | lib/table_tennis/util/console.rb | Ruby | mit | 181 | main | 637 | module TableTennis
module Util
# static wrapper around IO.console to handle the case where IO.console is nil
module Console
module_function
# supported when IO.console is nil
def winsize(...)
IO.console&.winsize(...) || [48, 80]
end
# not supported, don't call these
... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | lib/table_tennis/util/termbg.rb | Ruby | mit | 181 | main | 9,484 | module TableTennis
module Util
# Very complicated module for determining the terminal background color,
# used to select the default color theme.
module Termbg
prepend MemoWise
module_function
# get fg color as "#RRGGBB", or nil if we can't tel
def fg = osc_query(10) || env_color... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | lib/table_tennis/util/identify.rb | Ruby | mit | 181 | main | 1,411 | module TableTennis
#
# This module helps to classifying columns and values. Are they floats? Dates?
# Floats strings?
#
module Util
# Helpers for measuring and truncating strings.
module Identify
prepend MemoWise
module_function
def identify_column(values)
# grab 100, what... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | lib/table_tennis/util/magic_options.rb | Ruby | mit | 181 | main | 9,080 | #
# Helper class for validated option processing. This is used by Config but could probably be a
# custom gem at some point...
#
# MagicOptions is created with a `schema` defining a list of `attributes`. Each attribute has a
# `name` and a `type`. `options` is a hash of values that will be validated against the schema.... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | lib/table_tennis/util/colors.rb | Ruby | mit | 181 | main | 17,142 | module TableTennis
module Util
# Named color names and misc color helpers.
module Colors
prepend MemoWise
module_function
NAMED = {
#
# css colors
# https://htmlcolorcodes.com/color-names/
#
# red
"indianred" => "#cd5c5c",
"lightcora... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | lib/table_tennis/util/scale.rb | Ruby | mit | 181 | main | 1,394 | module TableTennis
module Util
# Helpers for color scales (adding background colors to a column based on the
# value of the float in the cell). Like conditional formattiong with a color
# range in google sheets.
module Scale
prepend MemoWise
module_function
WHITE, GREEN, RED, YELLO... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | lib/table_tennis/stage/layout.rb | Ruby | mit | 181 | main | 3,002 | module TableTennis
module Stage
# This stage figures out how wide each column should be. Most of the fun is
# in the autolayout behavior, which tries to fill the terminal without
# overflowing. Once we know the column sizes, it will go ahead and truncate
# the cells if necessary.
class Layout < Ba... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | lib/table_tennis/stage/painter.rb | Ruby | mit | 181 | main | 4,630 | module TableTennis
module Stage
# This stage "paints" the table by calculating the style for cells, rows and
# columns. The styles are stuffed into `data.set_style`. Later, the
# rendering stage can apply them if color is enabled.
#
# A "style" is either:
#
# - a theme symbol (like :title ... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | lib/table_tennis/stage/format.rb | Ruby | mit | 181 | main | 3,146 | module TableTennis
module Stage
# This stage "formats" the table by injesting columns that contain various
# ruby objects and formatting each as a string. Cells are formatted in place
# by transforming rows.
class Format < Base
def run
# Sample each column and infer column types. Determi... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | lib/table_tennis/stage/render.rb | Ruby | mit | 181 | main | 4,993 | module TableTennis
module Stage
# This is the final stage of the rending pipeline - take our layout
# information, the table cells, and the painted styles to render the table
# as a string. This is the slowest part of rendering since there is a lot of
# ansi/string manipulation.
#
# This is al... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | lib/table_tennis/stage/base.rb | Ruby | mit | 181 | main | 459 | module TableTennis
module Stage
# Base class for each stage of the rendering pipeline, mostly here just to
# delegate to TableData.
class Base
extend Forwardable
prepend MemoWise
include Util::Inspectable
attr_reader :data
def_delegators :data, *%i[column_names columns confi... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | test/test_table.rb | Ruby | mit | 181 | main | 2,356 | module TableTennis
class TestTable < Minitest::Test
def test_main
table = Table.new([{a: 1, b: 2}])
assert_equal %i[a b], table.columns.map(&:name)
assert_equal [[1, 2]], table.rows
# to_s
lines = table.to_s.split("\n").map { Util::Strings.unpaint(_1) }
assert_match(/^╭─+┬─+╮$... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | test/test_column.rb | Ruby | mit | 181 | main | 813 | module TableTennis
class TestColumn < Minitest::Test
def test_headers
# normal
data = TableData.new(config: Config.new, rows: [])
assert_equal "foo_bar_id", Column.new(data, :foo_bar_id, 1).header
# headers:
data.config.headers = {hello: "world"}
assert_equal "world", Column.n... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | test/test_theme.rb | Ruby | mit | 181 | main | 1,263 | module TableTennis
class TestTheme < Minitest::Test
def test_theme_keys
Theme::THEMES.each_value { assert_equal Theme::THEME_KEYS, _1.keys }
end
def test_codes
t = Theme.new(:dark)
[
# ansi
[:red, "\e[31m"],
[[:red], "\e[31m"],
[%i[red blue], "\e[31;44m"]... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | test/test_helper.rb | Ruby | mit | 181 | main | 2,253 | if ENV["COVERAGE"]
require "simplecov"
SimpleCov.start do
add_filter "/test/"
coverage_dir "/tmp/coverage"
end
end
require "amazing_print"
require "minitest/autorun"
require "minitest/hooks"
require "minitest/pride"
require "mocha/minitest"
require "ostruct"
require "table_tennis"
class Minitest::Test
... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | test/test_table_data.rb | Ruby | mit | 181 | main | 2,337 | module TableTennis
class TestTableData < Minitest::Test
def test_all
# columns inferred
data = TableData.new(rows: ab)
assert_equal %i[a b], data.column_names
assert_equal [[1, 2]], data.rows
# columns specified
config = Config.new(columns: %i[a])
data = TableData.new(co... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | test/test_config.rb | Ruby | mit | 181 | main | 4,439 | module TableTennis
class TestConfig < Minitest::Test
def test_basic
assert_equal "foo", Config.new(placeholder: "foo").placeholder
assert_equal "foo", Config.new.tap { _1.placeholder = "foo" }.placeholder
assert_true Config.new.tap { _1.zebra = 1 }.zebra
assert_false Config.new.tap { _1.ze... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | test/util/test_strings.rb | Ruby | mit | 181 | main | 6,178 | module TableTennis
module Util
class TestString < Minitest::Test
PLAIN = "foobar"
GREEN_STR = "\e[38;2;0;255;0mfoobar\e[0m"
def test_painted?
assert !Strings.painted?(PLAIN)
assert Strings.painted?(GREEN_STR)
end
def test_unpaint
assert_equal PLAIN, Strings.... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | test/util/test_termbg.rb | Ruby | mit | 181 | main | 4,973 | module TableTennis
module Util
class TestTermbg < Minitest::Test
SUCCESS_STR = ["\e];rgb:ffff/8888/2222\e\\", "\e[1;2R"].join
SUCCESS_BYTES = SUCCESS_STR.bytes
def console = IO.console
def test_main
if windows?
assert !Termbg.osc_supported?
return
end
... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | test/util/test_scale.rb | Ruby | mit | 181 | main | 305 | module TableTennis
module Util
class TestScale < Minitest::Test
def test_interpolate
assert_equal Scale::RED, Scale.interpolate(:rg, 0)
assert_equal "#ffffff", Scale.interpolate(:rg, 0.5)
assert_equal Scale::GREEN, Scale.interpolate(:rg, 1)
end
end
end
end |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | test/util/test_magic_options.rb | Ruby | mit | 181 | main | 5,631 | module TableTennis
module Util
class TestMagicOptions < Minitest::Test
SCHEMA = {
bool: :bool,
float: :float,
int: :int,
num: :num,
proc: -> {
raise ArgumentError, "ugh" if _1 != "yes"
},
range: (-10..10),
re: /hello|world/i,
... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | test/util/test_colors.rb | Ruby | mit | 181 | main | 2,609 | module TableTennis
module Util
class TestColors < Minitest::Test
def test_get
[
# good
[nil, nil],
%i[red red],
["#fff", "#fff"],
["ff8822", "ff8822"],
["#ff8822", "#ff8822"],
["firebrick", "#b22222"],
# bad
[... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | test/util/test_identify.rb | Ruby | mit | 181 | main | 1,060 | module TableTennis
module Util
class TestIdentify < Minitest::Test
def test_detect_type
data = [
[1.23, 1234, 1, "gub", Time.now, :xyz],
[1.23, 1.23, 1, "gub", Time.now, :xyz],
[nil, nil, nil, nil, nil, nil],
]
types = data.transpose.map { Identify.ident... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | test/stage/test_format.rb | Ruby | mit | 181 | main | 6,425 | module TableTennis
module Stage
class TestFormat < Minitest::Test
def test_main
types = %i[float int time string other]
# this column has everything!
kitchen_sink = [
1234.567111, 1234, "-1234.567111", "-1234",
"gub", :xyzzy,
" ", nil,
Date.t... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | test/stage/test_layout.rb | Ruby | mit | 181 | main | 3,152 | module TableTennis
module Stage
class TestLayout < Minitest::Test
def test_false
config = Config.new(layout: false)
data = TableData.new(config:, rows: [{hello: "x" * 123}])
Layout.new(data).run
assert_equal([123], data.columns.map(&:width))
assert_equal([123], data.r... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | test/stage/test_painter.rb | Ruby | mit | 181 | main | 1,927 | module TableTennis
module Stage
class TestPainter < Minitest::Test
def test_main
config = Config.new(
color: true,
color_scales: {b: :rg, c: :y},
mark: ->(row) { row[:a] == "0" },
placeholder: "NA",
row_numbers: true,
theme: :dark,
... |
github | gurgeous/table_tennis | https://github.com/gurgeous/table_tennis | test/stage/test_render.rb | Ruby | mit | 181 | main | 6,800 | module TableTennis
module Stage
class TestRender < Minitest::Test
def test_main
lines = render_string.split("\n")
[
/^╭─+╮$/, # top
/^│ +xyzzy +│$/, # title
/^├─+┬─+┤$/, # sep
/^│\s+a\s+│\s+b\s+│$/, # headers
/^├─... |
github | rubytoolbox/catalog | https://github.com/rubytoolbox/catalog | Gemfile | Ruby | mit | 181 | main | 614 | # frozen_string_literal: true
source "https://rubygems.org"
ruby File.read(File.join(__dir__, ".ruby-version")).strip
gem "json-schema"
gem "rake"
group :test do
gem "rspec"
gem "simplecov"
end
group :development, :test do
gem "pry"
end
group :development do
gem "bundler-audit", require: false
gem "gua... |
github | rubytoolbox/catalog | https://github.com/rubytoolbox/catalog | Guardfile | Ruby | mit | 181 | main | 3,293 | # frozen_string_literal: true
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
## Uncomment and set this to only include directories you want to watch
# directories %w(app lib config test spec features) \
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
## Not... |
github | rubytoolbox/catalog | https://github.com/rubytoolbox/catalog | Rakefile | Ruby | mit | 181 | main | 265 | # frozen_string_literal: true
desc "Loads the code environment into scope"
task :environment do
require File.join(__dir__, "lib/catalog")
end
desc "Generates and exports the catalog to the default location"
task export: :environment do
Catalog.new.export
end |
github | rubytoolbox/catalog | https://github.com/rubytoolbox/catalog | spec/spec_helper.rb | Ruby | mit | 181 | main | 5,200 | # frozen_string_literal: true
ENV["RACK_ENV"] ||= "test"
require File.join(__dir__, "../lib/catalog")
require "simplecov"
# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `-... |
github | rubytoolbox/catalog | https://github.com/rubytoolbox/catalog | spec/catalog_spec.rb | Ruby | mit | 181 | main | 2,051 | # frozen_string_literal: true
require "tempfile"
require "rubygems"
require "rubygems/remote_fetcher"
require "rubygems/name_tuple"
RSpec.describe Catalog do
it "can be represented as_json" do
expect(described_class.new.as_json).to be_a Hash
end
describe "#export" do
it "exports the JSON catalog to a f... |
github | rubytoolbox/catalog | https://github.com/rubytoolbox/catalog | lib/catalog.rb | Ruby | mit | 181 | main | 1,263 | # frozen_string_literal: true
ENV["RACK_ENV"] ||= "development"
require "pathname"
require "yaml"
require "bundler"
Bundler.require :default, ENV.fetch("RACK_ENV", nil)
class Catalog
attr_accessor :root
private :root=
def self.schema
YAML.safe_load Pathname.new(__dir__).join("..", "json-schema.yml").read
... |
github | t6d/smart_properties | https://github.com/t6d/smart_properties | Rakefile | Ruby | mit | 180 | master | 293 | #!/usr/bin/env rake
require 'bundler/setup'
require 'bundler/gem_tasks'
begin
require 'yard'
YARD::Rake::YardocTask.new do |t|
t.files = ['lib/**/*.rb', 'README.md']
end
rescue LoadError
end
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :default => :spec |
github | t6d/smart_properties | https://github.com/t6d/smart_properties | smart_properties.gemspec | Ruby | mit | 180 | master | 1,116 | # -*- encoding: utf-8 -*-
require File.expand_path('../lib/smart_properties/version', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ["Konstantin Tennhard"]
gem.email = ["me@t6d.de"]
gem.description = <<-DESCRIPTION
SmartProperties are a more flexible and feature-rich alternative to
... |
github | t6d/smart_properties | https://github.com/t6d/smart_properties | experiments/initialization_performance.rb | Ruby | mit | 180 | master | 509 | require 'benchmark'
require_relative '../lib/smart_properties'
class A
include SmartProperties
property :a
end
class B < A
property :b
end
class C < B
property :c
end
class A2
def initialize(**attrs)
attrs.each { |k, v| send("#{k}=", v) }
end
attr_accessor :a
end
class B2 < A2
attr_accessor :b
... |
github | t6d/smart_properties | https://github.com/t6d/smart_properties | spec/property_collection_caching_spec.rb | Ruby | mit | 180 | master | 1,522 | require 'spec_helper'
RSpec.describe SmartProperties, "property collection caching:" do
specify "SmartProperty enabled objects should be extendable at runtime" do
base_class = DummyClass.new { property :title }
subclass = DummyClass.new(base_class) { property :body }
subsubclass = DummyClass.new(subclass... |
github | t6d/smart_properties | https://github.com/t6d/smart_properties | spec/required_values_spec.rb | Ruby | mit | 180 | master | 6,453 | require 'spec_helper'
RSpec.describe SmartProperties do
context "when building a class that has a property which is required and has no default" do
subject(:klass) { DummyClass.new { property :title, required: true } }
context 'an instance of this class' do
it 'should have the correct title when provi... |
github | t6d/smart_properties | https://github.com/t6d/smart_properties | spec/base_spec.rb | Ruby | mit | 180 | master | 7,651 | require 'spec_helper'
RSpec.describe SmartProperties do
it 'should add a protected class method called .property when included' do
klass = Class.new { include SmartProperties }
expect(klass.respond_to?(:property, true)).to eq(true)
expect { klass.property }.to raise_error(NoMethodError)
end
context ... |
github | t6d/smart_properties | https://github.com/t6d/smart_properties | spec/acceptance_checking_spec.rb | Ruby | mit | 180 | master | 5,593 | require 'spec_helper'
RSpec.describe SmartProperties, 'acceptance checking' do
context "when used to build a class that has a property called :visible which uses an array of valid values for acceptance checking" do
subject(:klass) { DummyClass.new { property :visible, accepts: [true, false] } }
context "an ... |
github | t6d/smart_properties | https://github.com/t6d/smart_properties | spec/inheritance_spec.rb | Ruby | mit | 180 | master | 11,852 | require 'spec_helper'
RSpec.describe SmartProperties, 'intheritance' do
context 'when used to build a class that has a required property with no default called :text whose getter is overriden' do
subject(:klass) do
DummyClass.new do
property :text, required: true
def text; "<em>#{super}</em... |
github | t6d/smart_properties | https://github.com/t6d/smart_properties | spec/configuration_error_spec.rb | Ruby | mit | 180 | master | 1,804 | require 'spec_helper'
RSpec.describe SmartProperties, 'configuration error' do
subject(:klass) { DummyClass.new }
context "when defining a property with invalid configuration options" do
it "should report all invalid options" do
invalid_property_definition = lambda do
klass.class_eval do
... |
github | t6d/smart_properties | https://github.com/t6d/smart_properties | spec/default_values_spec.rb | Ruby | mit | 180 | master | 4,291 | require 'spec_helper'
RSpec.describe SmartProperties, 'default values' do
context 'when used to build a class that has a property called :id whose default value is a lambda statement for retrieving the object_id' do
subject(:klass) { DummyClass.new { property :id, default: lambda { object_id } } }
context "... |
github | t6d/smart_properties | https://github.com/t6d/smart_properties | spec/reader_spec.rb | Ruby | mit | 180 | master | 882 | require 'spec_helper'
RSpec.describe SmartProperties, 'reader' do
context "when defining a class with a property with a custom reader" do
subject(:klass) do
DummyClass.new do
property :new, default: false, accepts: [true, false], reader: :new?
end
end
context "an instance of this cla... |
github | t6d/smart_properties | https://github.com/t6d/smart_properties | spec/conversion_spec.rb | Ruby | mit | 180 | master | 965 | require 'spec_helper'
RSpec.describe SmartProperties, 'conversion' do
context "when defining a class with a property whose converter is an object that responds to #to_proc" do
subject(:klass) do
converter = double(to_proc: lambda { |t| content_tag(:p, t.to_s) })
DummyClass.new do
property :ti... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.