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 | domitry/nyaplot | https://github.com/domitry/nyaplot | lib/nyaplot/charts/base.rb | Ruby | mit | 221 | v2 | 1,111 | module Nyaplot
module Charts
class ChartBase
class << self
def allow(x, y)
@@allow_x = x
@@allow_y = y
end
def need(*args)
@@needs = args
end
end
attr_reader :glyphs, :deps, :xdomain, :ydomain
def initialize(**opts)
@g... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | lib/nyaplot/charts/line.rb | Ruby | mit | 221 | v2 | 547 | module Nyaplot
module Charts
class Line < ChartBase
allow :all, :all
need :data, :x, :y, :position
def create(**opts)
data = opts[:data]
data_l = ad Layers::Data.new({data: data})
args = {
data: data_l,
x: opts[:x],
y: opts[:y],
... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | lib/nyaplot/charts/scatter.rb | Ruby | mit | 221 | v2 | 553 | module Nyaplot
module Charts
class Scatter < ChartBase
allow :all, :all
need :data, :x, :y, :position
def create(**opts)
data = opts[:data]
data_l = ad Layers::Data.new({data: data})
args = {
data: data_l,
x: opts[:x],
y: opts[:y],
... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | lib/nyaplot/charts/bar.rb | Ruby | mit | 221 | v2 | 1,351 | require_relative './base'
module Nyaplot
module Charts
class Bar < ChartBase
allow :ordinal, :linear
need :data, :x, :y, :xscale, :yscale
## data: {ylabel: [1,2,3], xlabel: [:a, :b. :c]} or equal dataframe
def create(**opts)
data = opts[:data]
accessor = nil
... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | lib/nyaplot/layers/layers.rb | Ruby | mit | 221 | v2 | 1,589 | require_relative './base'
require_relative './tools'
require_relative './glyphs'
require_relative './html'
module Nyaplot
module Layers
class Axis < LayerBase
define_args :scale, :text_color, :axis_color, :tick_color, :stroke_width, :orient, :ticks
end
class Background < LayerBase
define... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | lib/nyaplot/layers/tools.rb | Ruby | mit | 221 | v2 | 393 | module Nyaplot
module Layers
class Accessor < LayerBase
define_args :scale, :label, :type
end
class D2c < LayerBase
define_args :label, :scale
end
class Data < LayerBase
define_args :data
end
class Position2d < LayerBase
define_args :x, :y
end
class Scal... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | lib/nyaplot/layers/base.rb | Ruby | mit | 221 | v2 | 1,347 | module Nyaplot
module Layers
class LayerBase
class << self
def define_args(*args)
args.each do |s|
define_method(s) do |val=nil|
unless val.nil?
@props[s] = val
self
else
@props[s]
end
... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | lib/nyaplot/layers/glyphs.rb | Ruby | mit | 221 | v2 | 1,283 | module Nyaplot
module Layers
class Area < LayerBase
define_args :data, :x, :y0, :y1, :position
define_args :color, :stroke_color, :stroke_width, :interpolate, :transpose, :opacity
end
class Circle < LayerBase
define_args :data, :x, :y, :position
define_args :radius, :color, :strok... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | lib/nyaplot3d/plot3d.rb | Ruby | mit | 221 | v2 | 2,328 | module Nyaplot
# Plot Object for 3D diagrams
class Plot3D
include Jsonizable
define_properties(:diagrams, :extension)
# @!attribute width
# @return [Numeric] the width of the plot
# @!attribute height
# @return [Numeric] the height of the plotp
define_group_properties(:options, [:wi... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | lib/nyaplot3d/diagram.rb | Ruby | mit | 221 | v2 | 3,848 | module Nyaplot
# Diagram3D
# @abstract extended using a module included in Nyaplot::Diagrams3D
class Diagram3D
include Jsonizable
define_properties(:type, :data)
def initialize(df, type, labels)
init_properties
mod = Kernel.const_get("Nyaplot").const_get("Diagrams3D").const_get(type.to_... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | lib/nyaplot3d/core.rb | Ruby | mit | 221 | v2 | 268 | module Nyaplot
add_extension("Elegans")
add_dependency("THREE","http://cdnjs.cloudflare.com/ajax/libs/three.js/r66/three.min")
add_dependency("Elegans","http://cdn.rawgit.com/domitry/elegans/nyaplot-extension/release/elegans")
init_iruby if defined? IRuby
end |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | examples/rb/maps.rb | Ruby | mit | 221 | v2 | 695 | require 'nyaplot'
require 'mapnya'
raw_df = Nyaplot::Countries.df
hash = [:name, :lat, :lng, :area, :capital].map{|label| {label => raw_df.column(label).to_a}}.reduce({}){|memo, hash| memo.merge(hash)}
df = Nyaplot::DataFrame.new(hash)
color = Nyaplot::Colors.Reds
plot = Nyaplot::MapPlot.new
sc = plot.add_with_df(d... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | examples/rb/basic.rb | Ruby | mit | 221 | v2 | 1,691 | require 'nyaplot'
# Bar chart
plot = Nyaplot::Plot.new
plot.add(:bar, ['Persian', 'Maine Coon', 'American Shorthair'], [10,20,30])
plot.x_label("Species")
plot.y_label("Number")
plot.export_html("bar.html")
# Line chart
x = []; y = []; theta = 0.6; a=1
while theta < 14*Math::PI do
x.push(a*Math::cos(theta)/theta)
... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | examples/rb/3d.rb | Ruby | mit | 221 | v2 | 1,704 | require 'nyaplot'
require 'nyaplot3d'
# Wireframe
x=[];y=[];z=[]
-10.step(10, 0.5) do |i|
-10.step(10, 0.5) do |j|
x.push(i)
y.push(j)
z.push(Math.sin(Math.sqrt(i*i+j*j))/Math.sqrt(i*i+j*j))
end
end
z.map!{|val| next (val.nan? ? 0 : val)} #(0,0) will be -inf
plot = Nyaplot::Plot3D.new
plot.add(:wirefr... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | examples/rb/bio.rb | Ruby | mit | 221 | v2 | 2,067 | require 'nyaplot'
require 'bionya'
arr = []
10.times do |i|
arr.push({group: 'group' + i.to_s ,df: Nyaplot::DataFrame.new({axis: ['a', 'b', 'c'], val: [2, 3, 4]})})
end
df = Nyaplot::DataFrame.new(arr)
plot = Nyaplot::CircularPlot.new(df, :group, :df)
plot.add(1, :arc, :axis, :val)
plot.export_html("example_bionya.... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | examples/rb/scatter.rb | Ruby | mit | 221 | v2 | 585 | require 'nyaplot'
samples = Array.new(10).map.with_index{|d,i| 'cat'+i.to_s}
address = ['London', 'Kyoto', 'Los Angeles', 'Puretoria']
x=[];y=[];home=[]
10.times do
x.push(5*rand)
y.push(5*rand)
home.push(address.clone.sample)
end
df = Nyaplot::DataFrame.new({x: x,y: y,name: samples, home: home})
plot = Nyaplo... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | examples/rb/multiple.rb | Ruby | mit | 221 | v2 | 628 | require 'nyaplot'
path = File.expand_path("../../notebook/data/first.tab", __FILE__)
df = Nyaplot::DataFrame.from_csv(path, sep="\t")
df.filter! {|row| row[:set1] != 0.0}
plot4=Nyaplot::Plot.new
plot4.add_with_df(df, :histogram, :set1)
plot4.configure do
height(400)
x_label('PNR')
y_label('Frequency')
filter(... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | examples/rb/wind.rb | Ruby | mit | 221 | v2 | 607 | require 'nyaplot'
require 'mapnya'
path = File.expand_path("../../notebook/data/wind.csv", __FILE__)
abs = []
df = Nyaplot::DataFrame.from_csv(path)
df.filter!{|row| !(row[:lon] < 200 && row[:lon] > 175)}
df.each_row{|row| row[:uwnd] = row[:uwnd]/3; row[:vwnd] = row[:vwnd]/3}
df.each_row{|row| abs.push(Math.sqrt(row[:... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | spec/mapnya_spec.rb | Ruby | mit | 221 | v2 | 2,646 | require 'spec_helper'
require 'mapnya'
describe "Mapnya" do
context "core" do
it "should register the namespace of JS back-end" do
expect(Nyaplot.extension_lists.index("Mapnya").nil?).to eq(false)
end
end
end
describe Nyaplot::MapPlot do
before(:each) do
@plot = Nyaplot::MapPlot.new
end
c... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | spec/bionya_spec.rb | Ruby | mit | 221 | v2 | 2,485 | require 'spec_helper'
require 'bionya'
describe "Bionya" do
context "core" do
it "should register the namespace of JS back-end" do
expect(Nyaplot.extension_lists.index("Bionya").nil?).to eq(false)
end
end
end
describe Nyaplot::CircularPlot do
before(:each) do
df = Nyaplot::DataFrame.new([{nam... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | spec/nyaplot3d_spec.rb | Ruby | mit | 221 | v2 | 2,604 | require 'spec_helper'
require 'nyaplot3d'
describe "Nyaplot3D" do
context "itself" do
it "should register the namespace of JS back-end" do
expect(Nyaplot.extension_lists.index("Elegans").nil?).to eq(false)
end
it "should register dependent libraries" do
module Nyaplot; $dep_libraries = @@dep... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | spec/nyaplot/color_spec.rb | Ruby | mit | 221 | v2 | 1,542 | require 'spec_helper'
describe Nyaplot::Colors do
context ".lists" do
it "should return array of prepared colorset" do
expect(Nyaplot::Colors.lists.is_a? Array).to eq(true)
end
end
context ".sample" do
it "return random colorset" do
expect(Nyaplot::Colors.sample.is_a? Nyaplot::Color).to ... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | spec/nyaplot/base_spec.rb | Ruby | mit | 221 | v2 | 1,634 | require 'spec_helper'
describe Nyaplot::Jsonizable do
before(:all) do
module Nyaplot
class Hoge
include Jsonizable
define_properties(:hoge, :huga)
define_group_properties(:options, [:nya])
def initialize
init_properties
options({})
end
end
... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | spec/nyaplot/plot_spec.rb | Ruby | mit | 221 | v2 | 1,890 | require 'spec_helper'
describe Nyaplot::Plot do
before(:each) do
@pair_property_and_expected_value = [[:width,500], [:height,500], [:margin], [:xrange, [-100,100]], [:yrange,[-100, 100]], [:x_label,:hoge], [:y_label,:nya], [:bg_color,"#000"], [:grid_color,"#fff"], [:legend,true], [:legend_width,200], [:legend_op... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | spec/nyaplot/diagram_spec.rb | Ruby | mit | 221 | v2 | 1,437 | require 'spec_helper'
describe Nyaplot::Diagram do
context ".df_name" do
it "should return the name of dataframe from which the diagram created" do
df = Nyaplot::DataFrame.new({x:[0,1,2], y:[0,1,2]})
sc = Nyaplot::Diagram.new(df, :scatter, [:x, :y])
expect(sc.df_name).to eq(df.name)
end
e... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | spec/nyaplot/frame_spec.rb | Ruby | mit | 221 | v2 | 735 | require 'spec_helper'
describe Nyaplot::Frame do
before(:all) do
@frame = Nyaplot::Frame.new
@plot = Nyaplot::Plot.new
@plot.add(:scatter, [0,1,2], [0,1,2])
end
context ".add" do
it "reflect the result to exported JSON" do
@frame.add(@plot)
expect(JSON.parse(@frame.to_json)[:panes] ... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | spec/nyaplot/database_spec.rb | Ruby | mit | 221 | v2 | 488 | require 'spec_helper'
describe Nyaplot::DataBase do
context ".instance" do
it "should return the instance of DataBase" do
expect(Nyaplot::DataBase.instance.is_a? Singleton).to eq(true)
end
end
context ".add" do
it "should register dataframe specified in the first argument to database" do
... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | spec/nyaplot/core_spec.rb | Ruby | mit | 221 | v2 | 1,246 | require 'spec_helper'
describe Nyaplot do
# Tell the name of new JS extension library to Nyaplotjs
context ".add_extension" do
it "should add extension name to lists" do
Nyaplot.add_extension("Hoge")
expect(Nyaplot.extension_lists.index("Hoge").nil?).to eq(false)
end
end
# Add extension l... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | spec/nyaplot/data_spec.rb | Ruby | mit | 221 | v2 | 4,633 | require 'spec_helper'
describe Nyaplot::DataFrame do
before(:each) do
@df = Nyaplot::DataFrame.new({a: [10, 30], b: [20, 40]})
@column_a_arr = [10, 30]
end
context ".from_csv" do
it "should accept a CSV-style converter in a block" do
path = File.expand_path("../matrix_test.csv", __FILE__)
... |
github | domitry/nyaplot | https://github.com/domitry/nyaplot | spec/nyaplot/monkeys_spec.rb | Ruby | mit | 221 | v2 | 822 | require 'spec_helper'
describe Array do
context "#mean" do
it "should calculate the mean of its entries" do
expect([1,2,3,4,5].mean).to eq 3.0
end
end
context "#median" do
it "should calculate the median of an odd number of entries" do
expect([1,2,3,4,5].median).to eq 3
end
it "... |
github | cldwalker/boson | https://github.com/cldwalker/boson | test/runner_library_test.rb | Ruby | mit | 221 | master | 423 | require File.join(File.dirname(__FILE__), 'test_helper')
describe "RunnerLibrary" do
before { reset }
it "creates a library with correct commands" do
Manager.load create_runner(:blah)
library('blarg').commands.should == ['blah']
end
it "can coexist with another runner library" do
Manager.load cre... |
github | cldwalker/boson | https://github.com/cldwalker/boson | test/options_test.rb | Ruby | mit | 221 | master | 5,707 | require File.join(File.dirname(__FILE__), 'test_helper')
describe "Options" do
def create(opts)
@opt = OptionParser.new(opts)
end
def parse(*args)
@non_opts = []
@opt.parse(args.flatten)
end
describe ":string type" do
before {
create "--foo" => :string, "--bar" => :string, :blah=>{:... |
github | cldwalker/boson | https://github.com/cldwalker/boson | test/scientist_test.rb | Ruby | mit | 221 | master | 6,712 | require File.join(File.dirname(__FILE__), 'test_helper')
describe "Scientist" do
before_all {
Boson.in_shell = nil
eval <<-EOF
module Blah
def blah(arg1, options={})
[arg1, options]
end
def splat_blah(*args)
args
end
def default_blah(arg1, arg2=default, optio... |
github | cldwalker/boson | https://github.com/cldwalker/boson | test/bin_runner_test.rb | Ruby | mit | 221 | master | 2,066 | require File.join(File.dirname(__FILE__), 'test_helper')
require 'boson/bin_runner'
BinRunner = Boson::BinRunner
describe "BinRunner" do
def aborts_with(regex)
BinRunner.expects(:abort).with {|e| e[regex] }
yield
end
unless ENV['FAST']
it "prints usage with no arguments" do
boson
stdout.... |
github | cldwalker/boson | https://github.com/cldwalker/boson | test/test_helper.rb | Ruby | mit | 221 | master | 3,853 | require 'mocha_standalone'
require 'boson'
require 'fileutils'
require 'boson/runner'
require 'bahia'
ENV['RSPEC'] = '1' if $0[/rspec/]
unless ENV['RSPEC']
require 'bacon'
require 'bacon/bits'
require 'mocha-on-bacon'
end
Object.send :remove_const, :OptionParser
Boson.constants.each {|e| Object.const_set(e, Bos... |
github | cldwalker/boson | https://github.com/cldwalker/boson | test/runner_test.rb | Ruby | mit | 221 | master | 7,090 | require File.dirname(__FILE__) + '/test_helper'
require 'shellwords'
# hack required to re-add default_commands_runner methods
$".delete_if {|e| e[%r{boson/runner.rb$}] }
Boson.send(:remove_const, :Runner)
Boson.send(:remove_const, :DefaultCommandsRunner)
require 'boson/runner'
# remove side effects from other tests
... |
github | cldwalker/boson | https://github.com/cldwalker/boson | test/manager_test.rb | Ruby | mit | 221 | master | 3,150 | require File.join(File.dirname(__FILE__), 'test_helper')
describe "Manager" do
def manager
Manager.instance
end
before do
reset_boson
Manager.instance = nil
end
describe ".load" do
def load_library(hash={})
meths = hash.delete(:commands) || []
manager_load create_runner(*(meths ... |
github | cldwalker/boson | https://github.com/cldwalker/boson | test/loader_test.rb | Ruby | mit | 221 | master | 1,091 | require File.join(File.dirname(__FILE__), 'test_helper')
describe "Loader" do
describe "load" do
before { reset }
it "prints error for method conflicts with main_object method" do
runner = create_runner :require
manager_load runner
stderr.should =~ /Unable to load library Blarg.*conflict.*... |
github | cldwalker/boson | https://github.com/cldwalker/boson | test/method_inspector_test.rb | Ruby | mit | 221 | master | 1,965 | require File.join(File.dirname(__FILE__), 'test_helper')
describe "MethodInspector" do
before { MethodInspector.instance = nil }
def method_inspector
MethodInspector.instance
end
it "non commands module can't set anything" do
remove_constant :Blah
eval "module Blah; end"
method_inspector.curr... |
github | cldwalker/boson | https://github.com/cldwalker/boson | test/option_parser_test.rb | Ruby | mit | 221 | master | 11,405 | require File.join(File.dirname(__FILE__), 'test_helper')
describe "OptionParser" do
def create(opts)
@opt = OptionParser.new(opts)
end
def opt; @opt; end
def parse(*args)
@non_opts = []
opt.parse(args.flatten)
end
describe "#indifferent_hash" do
before {
@hash = OptionParser.new({}... |
github | cldwalker/boson | https://github.com/cldwalker/boson | test/util_test.rb | Ruby | mit | 221 | master | 1,918 | require File.join(File.dirname(__FILE__), 'test_helper')
describe "Util" do
it "underscore converts camelcase to underscore" do
Util.underscore('Boson::MethodInspector').should == 'boson/method_inspector'
end
it "constantize converts string to class" do
Util.constantize("Boson").should == ::Boson
end
... |
github | cldwalker/boson | https://github.com/cldwalker/boson | test/command_test.rb | Ruby | mit | 221 | master | 448 | require File.join(File.dirname(__FILE__), 'test_helper')
describe "Command" do
describe ".find" do
before do
reset_boson
@top_level_command = create_command(:name=>'blah', :lib=>'bling')
end
it 'finds correct command when a subcommand of the same name exists' do
Command.find('blah').sh... |
github | cldwalker/boson | https://github.com/cldwalker/boson | lib/boson.rb | Ruby | mit | 221 | master | 2,462 | require 'boson/bare_runner'
require 'boson/manager'
require 'boson/loader'
require 'boson/inspector'
require 'boson/library'
require 'boson/method_inspector'
require 'boson/runner_library'
require 'boson/command'
require 'boson/util'
require 'boson/option_parser'
require 'boson/options'
require 'boson/scientist'
requir... |
github | cldwalker/boson | https://github.com/cldwalker/boson | lib/boson/inspector.rb | Ruby | mit | 221 | master | 3,835 | module Boson
# Uses method decorators to scrape, process and hand off method attributes as
# data to Library objects.
#
# === Method Decorators
# Method decorators refer to methods placed before a command's method in a
# library:
# class SomeRunner < Boson::Runner
# options :verbose=>:boolean
#... |
github | cldwalker/boson | https://github.com/cldwalker/boson | lib/boson/loader.rb | Ruby | mit | 221 | master | 3,294 | module Boson
# Raised if a library has methods which conflict with existing methods
class MethodConflictError < LoaderError
MESSAGE = "The following commands conflict with existing commands: %s"
def initialize(conflicts)
super MESSAGE % conflicts.join(', ')
end
end
# This module is mixed into... |
github | cldwalker/boson | https://github.com/cldwalker/boson | lib/boson/util.rb | Ruby | mit | 221 | master | 4,070 | module Boson
# Collection of utility methods used throughout Boson.
module Util
extend self
# From ActiveSupport, converts a camelcased string to an underscored string:
# 'Boson::MethodInspector' -> 'boson/method_inspector'
def underscore(camel_cased_word)
camel_cased_word.to_s.gsub(/::/, '/')... |
github | cldwalker/boson | https://github.com/cldwalker/boson | lib/boson/bin_runner.rb | Ruby | mit | 221 | master | 3,382 | module Boson
# This class handles the boson executable.
#
# Usage for the boson shell command looks like this:
# boson [GLOBAL OPTIONS] [COMMAND] [ARGS] [COMMAND OPTIONS]
#
# The boson executable comes with several global options: :version, :execute,
# :ruby_debug, :debug, and :load_path.
class BinRun... |
github | cldwalker/boson | https://github.com/cldwalker/boson | lib/boson/options.rb | Ruby | mit | 221 | master | 5,355 | module Boson
# This module contains the methods used to define the default option types.
#
# === Creating Your Own Option Type
# Defining your own option type simply requires one method (create_@type) to
# parse the option value and create the desired object. To create an option
# type :date, you could crea... |
github | cldwalker/boson | https://github.com/cldwalker/boson | lib/boson/runner.rb | Ruby | mit | 221 | master | 2,811 | require 'boson'
module Boson
# Defines a RunnerLibrary for use by executables as a simple way to map
# methods to subcommands
class Runner < BareRunner
# Stores currently started Runner subclass
class <<self; attr_accessor :current; end
def self.inherited(mod)
@help_added ||= add_command_help
... |
github | cldwalker/boson | https://github.com/cldwalker/boson | lib/boson/library.rb | Ruby | mit | 221 | master | 4,385 | module Boson
# A library is a group of commands (Command objects) usually grouped together
# by a module. Libraries are loaded from different sources depending on the
# library subclass.
#
# === Creating Your Own Library
# To create your own subclass you need to define what sources the subclass can
# han... |
github | cldwalker/boson | https://github.com/cldwalker/boson | lib/boson/scientist.rb | Ruby | mit | 221 | master | 5,181 | module Boson
# Scientist wraps around and redefines an object's method to give it the
# following features:
# * Methods can take shell command input with options or receive its normal
# arguments. See the Commandification section.
# * Methods have a slew of global options available. See OptionCommand for an... |
github | cldwalker/boson | https://github.com/cldwalker/boson | lib/boson/command.rb | Ruby | mit | 221 | master | 5,463 | module Boson
# A command starts with the functionality of a ruby method and adds benefits
# with options, etc.
class Command
module APIClassMethods
# Creates a command given its name and a library.
def create(name, library)
new(new_attributes(name, library))
end
# Attributes p... |
github | cldwalker/boson | https://github.com/cldwalker/boson | lib/boson/manager.rb | Ruby | mit | 221 | master | 5,127 | module Boson
# Base class for library loading errors. Raised mostly in Boson::Loader and
# rescued by Boson::Manager.
class LoaderError < StandardError; end
# Handles loading of libraries and commands.
class Manager
# Loads a library or an array of libraries with options. Manager loads the
# first li... |
github | cldwalker/boson | https://github.com/cldwalker/boson | lib/boson/option_command.rb | Ruby | mit | 221 | master | 5,376 | require 'shellwords'
module Boson
# A class used by Scientist to wrap around Command objects. It's main purpose
# is to parse a command's global and local options. As the names imply,
# global options are available to all commands while local options are
# specific to a command. When passing options to comman... |
github | cldwalker/boson | https://github.com/cldwalker/boson | lib/boson/bare_runner.rb | Ruby | mit | 221 | master | 2,430 | module Boson
# Base class for runners.
class BareRunner
DEFAULT_LIBRARIES = []
# Default options for parse_args
GLOBAL_OPTIONS = {
help: { type: :boolean, desc: "Displays this help message" }
}
module API
# Loads rc
def start(*)
@options ||= {}
load_rc
en... |
github | cldwalker/boson | https://github.com/cldwalker/boson | lib/boson/method_inspector.rb | Ruby | mit | 221 | master | 2,942 | module Boson
# Gathers method attributes by redefining method_added and capturing method
# calls before a method.
class MethodInspector
METHODS = [:config, :desc, :options]
SCRAPEABLE_METHODS = [:options]
METHOD_CLASSES = {:config=>Hash, :desc=>String, :options=>Hash}
ALL_METHODS = METHODS + [:opt... |
github | cldwalker/boson | https://github.com/cldwalker/boson | lib/boson/option_parser.rb | Ruby | mit | 221 | master | 18,625 | module Boson
# This class concisely defines commandline options that when parsed produce a
# Hash of option keys and values.
# Additional points:
# * Setting option values should follow conventions in *nix environments.
# See examples below.
# * By default, there are 5 option types, each which produce dif... |
github | cldwalker/boson | https://github.com/cldwalker/boson | lib/boson/runner_library.rb | Ruby | mit | 221 | master | 940 | module Boson
# Library created by Runner
class RunnerLibrary < Library
handles {|source|
source.is_a?(Module) && defined?(Runner) && source.ancestors.include?(Runner)
}
def self.delegate_runner_methods(runner, mod)
mod.module_eval do
runner.public_instance_methods(false).each do |me... |
github | palkan/rubanok | https://github.com/palkan/rubanok | Rakefile | Ruby | mit | 222 | master | 1,222 | # frozen_string_literal: true
require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
begin
require "rubocop/rake_task"
RuboCop::RakeTask.new
RuboCop::RakeTask.new("rubocop:md") do |task|
task.options << %w[-c .rubocop-md.yml]
end
rescue LoadError
task(:rubocop) {}
... |
github | palkan/rubanok | https://github.com/palkan/rubanok | Gemfile | Ruby | mit | 222 | master | 301 | # frozen_string_literal: true
source "https://rubygems.org"
gem "debug", platform: :mri
gemspec
eval_gemfile "gemfiles/rubocop.gemfile"
eval_gemfile "gemfiles/rbs.gemfile"
local_gemfile = ENV.fetch("LOCAL_GEMFILE", "Gemfile.local")
if File.exist?(local_gemfile)
eval_gemfile local_gemfile
end |
github | palkan/rubanok | https://github.com/palkan/rubanok | rubanok.gemspec | Ruby | mit | 222 | master | 1,300 | # frozen_string_literal: true
require_relative "lib/rubanok/version"
Gem::Specification.new do |spec|
spec.name = "rubanok"
spec.version = Rubanok::VERSION
spec.authors = ["Vladimir Dementyev"]
spec.email = ["dementiev.vm@gmail.com"]
spec.summary = "Parameters-based transformation DSL"
spec.description =... |
github | palkan/rubanok | https://github.com/palkan/rubanok | spec/spec_helper.rb | Ruby | mit | 222 | master | 462 | # frozen_string_literal: true
begin
require "debug"
rescue LoadError
end
ENV["RAILS_ENV"] = "test"
require "rubanok"
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
RSpec.configure do |config|
config.mock_with :rspec
config.example_status_persistence_file_path = "tmp/rspec_examp... |
github | palkan/rubanok | https://github.com/palkan/rubanok | spec/processor_spec.rb | Ruby | mit | 222 | master | 1,098 | # frozen_string_literal: true
describe Rubanok::Processor do
describe ".project" do
let(:processor) do
Class.new(Rubanok::Processor) do
map :q do |q:|
raw
end
match :sort_by, :sort, activate_on: :sort_by do
having "status", "asc" do
raw
end... |
github | palkan/rubanok | https://github.com/palkan/rubanok | spec/integrations/rspec_matchers_spec.rb | Ruby | mit | 222 | master | 1,517 | # frozen_string_literal: true
require "spec_helper"
class RspecPlane < Rubanok::Plane
end
class AnotherRspecPlane < Rubanok::Plane
end
describe "Rubanok RSpec matchers" do
describe "#have_rubanok_processed" do
specify "matches processor class" do
expect do
RspecPlane.call([], {type: "array"})
... |
github | palkan/rubanok | https://github.com/palkan/rubanok | spec/integrations/rails_controller_spec.rb | Ruby | mit | 222 | master | 3,636 | # frozen_string_literal: true
require_relative "controller_helper"
class RejectPlane < Rubanok::Plane
map :type do |type:|
raw.reject { |item| item[:type] == type }
end
end
class PostsPlane < Rubanok::Plane
map :type do |type:|
raw.select { |item| item[:type] == type }
end
match :sort_by, :sort, a... |
github | palkan/rubanok | https://github.com/palkan/rubanok | spec/integrations/controller_helper.rb | Ruby | mit | 222 | master | 575 | # frozen_string_literal: true
require "spec_helper"
require_relative "dummy/config/environment"
require "rspec/rails"
ActiveSupport.on_load(:action_controller) do
require "rubanok/rails/controller"
ActionController::Base.include Rubanok::Controller
end
ActiveSupport.on_load(:action_controller_api) do
require... |
github | palkan/rubanok | https://github.com/palkan/rubanok | spec/integrations/dummy/config/application.rb | Ruby | mit | 222 | master | 297 | # frozen_string_literal: true
require File.expand_path("boot", __dir__)
require "rails"
require "action_controller/railtie"
Bundler.require(*Rails.groups)
module Dummy
class Application < Rails::Application
config.logger = Logger.new("/dev/null")
config.eager_load = false
end
end |
github | palkan/rubanok | https://github.com/palkan/rubanok | spec/cases/matching_spec.rb | Ruby | mit | 222 | master | 6,770 | # frozen_string_literal: true
describe "Plane.match" do
let(:input) do
[
{
name: "Dexter",
age: "53",
occupation: "vocal"
},
{
name: "Noodles",
age: "55",
occupation: "guitar"
},
{
name: "Ron",
age: "47",
occupa... |
github | palkan/rubanok | https://github.com/palkan/rubanok | spec/cases/prepare_spec.rb | Ruby | mit | 222 | master | 695 | # frozen_string_literal: true
describe "Plane.prepare_raw" do
let(:input) { {} }
let(:params) { {} }
let(:plane) do
Class.new(Rubanok::Plane) do
prepare do
next if raw&.dig(:index)
{index: "test"}
end
map :q do |q:|
raw[:query] = q
raw
end
end
... |
github | palkan/rubanok | https://github.com/palkan/rubanok | spec/cases/process_spec.rb | Ruby | mit | 222 | master | 2,650 | # frozen_string_literal: true
describe "Plane.process" do
let(:input) do
[
{
name: "Dexter",
occupation: "vocal",
status: "forever"
},
{
name: "Noodles",
occupation: "guitar",
status: "forever"
},
{
name: "Ron",
occupat... |
github | palkan/rubanok | https://github.com/palkan/rubanok | spec/cases/mapping_spec.rb | Ruby | mit | 222 | master | 5,150 | # frozen_string_literal: true
describe "Plane.map" do
let(:input) do
[
{
id: "1",
name: "Kurt",
age: "51",
occupation: "guitar"
},
{
id: "2",
name: "Kris",
age: "53",
occupation: "bas"
},
{
id: "",
name:... |
github | palkan/rubanok | https://github.com/palkan/rubanok | lib/rubanok.rb | Ruby | mit | 222 | master | 1,073 | # frozen_string_literal: true
require "rubanok/version"
require "rubanok/processor"
require "rubanok/railtie" if defined?(Rails)
# @type const ENV: Hash[String, String]
if defined?(RSpec) && (ENV["RACK_ENV"] == "test" || ENV["RAILS_ENV"] == "test")
require "rubanok/rspec"
end
# Rubanok provides a DSL to build par... |
github | palkan/rubanok | https://github.com/palkan/rubanok | lib/rubanok/rspec.rb | Ruby | mit | 222 | master | 1,668 | # frozen_string_literal: true
require "rspec/mocks"
module Rubanok
class HaveProcessed < RSpec::Matchers::BuiltIn::BaseMatcher
include RSpec::Mocks::ExampleMethods
attr_reader :data_class, :processor, :matcher
def initialize(data_class = nil)
if data_class
@data_class = data_class.is_a?(... |
github | palkan/rubanok | https://github.com/palkan/rubanok | lib/rubanok/rule.rb | Ruby | mit | 222 | master | 1,612 | # frozen_string_literal: true
module Rubanok
using(Module.new do
refine NilClass do
def empty?
true
end
end
refine Object do
def empty?
false
end
end
end)
class Rule # :nodoc:
UNDEFINED = Object.new
attr_reader :fields, :activate_on, :activate_al... |
github | palkan/rubanok | https://github.com/palkan/rubanok | lib/rubanok/processor.rb | Ruby | mit | 222 | master | 3,268 | # frozen_string_literal: true
require "set"
require "rubanok/rule"
require "rubanok/dsl/mapping"
require "rubanok/dsl/matching"
require "rubanok/dsl/process"
module Rubanok
# Base class for processors (_planes_)
#
# Define transformation rules via `map` and `match` methods
# and apply them by calling the pr... |
github | palkan/rubanok | https://github.com/palkan/rubanok | lib/rubanok/railtie.rb | Ruby | mit | 222 | master | 483 | # frozen_string_literal: true
module Rubanok # :nodoc:
class Railtie < ::Rails::Railtie # :nodoc:
config.to_prepare do |_app|
ActiveSupport.on_load(:action_controller) do
require "rubanok/rails/controller"
ActionController::Base.include Rubanok::Controller
end
ActiveSupport.on... |
github | palkan/rubanok | https://github.com/palkan/rubanok | lib/rubanok/rails/controller.rb | Ruby | mit | 222 | master | 2,568 | # frozen_string_literal: true
require "active_support/concern"
module Rubanok
# Controller concern.
# Adds `rubanok_process` method.
module Controller
extend ActiveSupport::Concern
included do
if respond_to?(:helper_method)
helper_method :rubanok_scope
helper_method :planish_scope... |
github | palkan/rubanok | https://github.com/palkan/rubanok | lib/rubanok/dsl/matching.rb | Ruby | mit | 222 | master | 3,307 | # frozen_string_literal: true
module Rubanok
class UnexpectedInputError < StandardError; end
module DSL
# Adds `.match` method to Processor class to define key-value-matching rules:
#
# match :sort, :sort_by do |sort:, sort_by:|
# # this rule is activated iff both "sort" and "sort_by" params... |
github | palkan/rubanok | https://github.com/palkan/rubanok | lib/rubanok/dsl/mapping.rb | Ruby | mit | 222 | master | 1,323 | # frozen_string_literal: true
module Rubanok
module DSL
# Adds `.map` method to Processor to define key-matching rules:
#
# map :q do |q:|
# # this rule is activated iff "q" (or :q) param is present
# # the value is passed to the handler
# end
module Mapping
class Rule < R... |
github | palkan/rubanok | https://github.com/palkan/rubanok | lib/rubanok/dsl/process.rb | Ruby | mit | 222 | master | 2,074 | # frozen_string_literal: true
module Rubanok
module DSL
# Adds `.process` method to Processor to define a nested processor:
#
# process :filter do
# map :status do |status:|
# raw.where(status:)
# end
#
module Process
class Rule < Rubanok::Rule
METHOD_PRE... |
github | palkan/rubanok | https://github.com/palkan/rubanok | sig/typeprof.rb | Ruby | mit | 222 | master | 571 | # frozen_string_literal: true
# Run typeprofiler:
#
# typeprof -Ilib sig/typeprof.rb
require "rubanok"
processor = Class.new(Rubanok::Processor) do
map :q do |q:|
raw
end
process :filter do
map :status do |status:|
raw
end
map :name do |name:|
raw
end
end
match :sort_by,... |
github | AlexB52/retest | https://github.com/AlexB52/retest | retest.gemspec | Ruby | mit | 221 | main | 1,672 | require_relative 'lib/retest/version'
Gem::Specification.new do |spec|
spec.name = "retest"
spec.version = Retest::VERSION
spec.authors = ["Alexandre Barret"]
spec.email = ["alex@abletech.nz"]
spec.summary = "A simple command line tool to watch file change and run its matc... |
github | AlexB52/retest | https://github.com/AlexB52/retest | lib/retest.rb | Ruby | mit | 221 | main | 743 | require 'string/similarity'
require 'observer'
require "retest/version"
require "retest/runner"
require "retest/repository"
require "retest/matching_options"
require "retest/options"
require "retest/version_control"
require "retest/setup"
require "retest/command"
require "retest/file_system"
require "retest/program"
r... |
github | AlexB52/retest | https://github.com/AlexB52/retest | lib/retest/runner.rb | Ruby | mit | 221 | main | 3,017 | require 'forwardable'
require_relative "runner/cached_test_file"
module Retest
class Runner
extend Forwardable
include Observable
include CachedTestFile
def_delegators :command, :has_changed?, :has_test?
attr_accessor :command, :stdout, :last_command
def initialize(command, stdout: $stdout)... |
github | AlexB52/retest | https://github.com/AlexB52/retest | lib/retest/sounds.rb | Ruby | mit | 221 | main | 1,581 | module Retest
module Sounds
module_function
def for(options)
options.notify? ? MacOS.new : Mute.new
end
class Mute
def play(_)
end
alias update play
end
class MacOS
def initialize(kernel: Kernel, thread: Thread)
@kernel = kernel
@thread = thread... |
github | AlexB52/retest | https://github.com/AlexB52/retest | lib/retest/setup.rb | Ruby | mit | 221 | main | 581 | module Retest
class Setup
def type
@type ||= begin
return :ruby unless has_lock_file?
if rspec? then :rspec
elsif rails? then :rails
elsif rake? then :rake
else :ruby
end
end
end
private
def has_lock_file?
File.exist... |
github | AlexB52/retest | https://github.com/AlexB52/retest | lib/retest/options.rb | Ruby | mit | 221 | main | 4,694 | require 'optparse'
module Retest
class Options
DEFAULT_PARAMS = {
all: false,
diff: nil,
exts: %w[rb],
help: false,
notify: false,
polling: false,
rake: false,
rails: false,
rspec: false,
ruby: false,
version: false,
watcher: nil,
comm... |
github | AlexB52/retest | https://github.com/AlexB52/retest | lib/retest/output.rb | Ruby | mit | 221 | main | 618 | module Retest
# This library formats output messages displayed to the user
module Output
module_function
# This method formats the force batch search failures and prints it to IO if
# passed in or returns the message otherwise.
def force_batch_failures(paths, out: nil)
return unless paths&.an... |
github | AlexB52/retest | https://github.com/AlexB52/retest | lib/retest/prompt.rb | Ruby | mit | 221 | main | 1,106 | module Retest
class Prompt
include Observable
attr_accessor :input, :output
def initialize(input: nil, output: nil)
@input = input || $stdin
@output = output || $stdout
@question_asked = false
end
def ask_which_test_to_use(path, files)
changed
notify_observers(:que... |
github | AlexB52/retest | https://github.com/AlexB52/retest | lib/retest/watcher.rb | Ruby | mit | 221 | main | 4,382 | require 'pathname'
module Retest
module Watcher
def self.for(watcher)
tool = case watcher.to_s
when 'listen' then Default
when 'watchexec' then Watchexec
when '', 'installed' then installed
else raise ArgumentError, "Unknown #{watcher}"
end... |
github | AlexB52/retest | https://github.com/AlexB52/retest | lib/retest/command.rb | Ruby | mit | 221 | main | 1,823 | require_relative 'command/base'
require_relative 'command/hardcoded'
require_relative 'command/rspec'
require_relative 'command/rails'
require_relative 'command/rake'
require_relative 'command/ruby'
module Retest
class Command
extend Forwardable
def self.for_options(options)
new(options: options).comm... |
github | AlexB52/retest | https://github.com/AlexB52/retest | lib/retest/program.rb | Ruby | mit | 221 | main | 1,927 | require_relative 'program/pausable'
require_relative 'program/forced_selection'
module Retest
class Program
extend Forwardable
include Pausable
include ForcedSelection
attr_accessor :runner, :repository, :stdout
def_delegators :runner,
:run_last_command, :last_command
def initialize(... |
github | AlexB52/retest | https://github.com/AlexB52/retest | lib/retest/matching_options.rb | Ruby | mit | 221 | main | 1,498 | require_relative 'matching_options/path'
module Retest
class MatchingOptions
def self.for(path, files: [], limit: nil)
new(path, files: files, limit: limit).filtered_results
end
attr_reader :path, :files, :test_directories
def initialize(path, files: [], limit: 5, test_directories: nil)
... |
github | AlexB52/retest | https://github.com/AlexB52/retest | lib/retest/repository.rb | Ruby | mit | 221 | main | 1,619 | module Retest
class Repository
attr_accessor :files, :cache, :prompt
def initialize(files: [], cache: {}, prompt: nil)
@cache = cache
@files = files
@prompt = prompt || Prompt.new
end
def find_test(path)
return unless path
return if path.empty?
unless cache.key... |
github | AlexB52/retest | https://github.com/AlexB52/retest | lib/retest/version_control.rb | Ruby | mit | 221 | main | 280 | require_relative 'version_control/git'
require_relative 'version_control/no_version_control'
module Retest
module VersionControl
module_function
def files(extensions: [])
[Git, NoVersionControl].find(&:installed?).files(extensions: extensions)
end
end
end |
github | AlexB52/retest | https://github.com/AlexB52/retest | lib/retest/matching_options/path.rb | Ruby | mit | 221 | main | 1,977 | require 'forwardable'
require 'set'
module Retest
class MatchingOptions
class Path
extend Forwardable
def_delegators :pathname, :to_s, :basename, :extname, :dirname
attr_reader :pathname
def initialize(path)
@pathname = Pathname(path)
end
def ==(other)
pathn... |
github | AlexB52/retest | https://github.com/AlexB52/retest | lib/retest/runner/cached_test_file.rb | Ruby | mit | 221 | main | 451 | module Retest
module CachedTestFile
attr_reader :cached_test_file
def cached_test_file=(value)
@cached_test_file = value || cached_test_file
end
def purge_test_file(purged)
return if purged.empty?
if purged.is_a?(Array) && purged.include?(cached_test_file)
@cached_test_fil... |
github | AlexB52/retest | https://github.com/AlexB52/retest | lib/retest/program/forced_selection.rb | Ruby | mit | 221 | main | 356 | module ForcedSelection
attr_reader :selected_test_files
def initialize_forced_selection(value = [])
@selected_test_files = value
end
def forced_selection?
!@selected_test_files.empty?
end
def reset_selection
@selected_test_files = []
end
def force_selection(test_files)
@selected_test... |
github | AlexB52/retest | https://github.com/AlexB52/retest | lib/retest/program/pausable.rb | Ruby | mit | 221 | main | 233 | module Pausable
def initialize_pause(value = false)
@paused = value
end
def pause
@paused = true
end
def paused?
@paused
end
def resume
@paused = false
end
def running_state
@paused
end
end |
github | AlexB52/retest | https://github.com/AlexB52/retest | lib/retest/version_control/no_version_control.rb | Ruby | mit | 221 | main | 436 | module Retest
module VersionControl
module NoVersionControl
module_function
def installed?
true
end
def name
'default'
end
def files(extensions: [])
result = if extensions.empty?
Dir.glob('**/*')
else
Dir.glob("**/*.{#{ext... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.