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 | tomdalling/rschema | https://github.com/tomdalling/rschema | spec/schemas/maybe_spec.rb | Ruby | apache-2.0 | 45 | master | 751 | RSpec.describe RSchema::Schemas::Maybe do
subject { described_class.new(subschema) }
let(:subschema) { SchemaStub.new }
it_behaves_like 'a schema'
context 'successful validation' do
it 'allows nil' do
expect(validate(nil)).to be_valid
end
it 'otherwise delegates to the subschema' do
e... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | spec/schemas/variable_length_array_spec.rb | Ruby | apache-2.0 | 45 | master | 1,474 | RSpec.describe RSchema::Schemas::VariableLengthArray do
subject { described_class.new(subschema) }
let(:subschema) { SchemaStub.new }
it_behaves_like 'a schema'
specify 'successful validation' do
result = validate([:valid, :valid, :valid])
expect(result).to be_valid
expect(result.value).to eq([:v... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | spec/schemas/convenience_spec.rb | Ruby | apache-2.0 | 45 | master | 2,245 | RSpec.describe RSchema::Schemas::Convenience do
subject { described_class.new(subschema) }
let(:subschema) { SchemaStub.new }
specify '#validate' do
expect(subschema)
.to receive(:call)
.with(5, RSchema::Options.default)
.and_return(:yep)
result = subject.validate(5)
expect(result... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema.rb | Ruby | apache-2.0 | 45 | master | 3,492 | # frozen_string_literal: true
require 'docile'
require 'rschema/options'
require 'rschema/error'
require 'rschema/result'
require 'rschema/schemas'
require 'rschema/dsl'
require 'rschema/coercers'
require 'rschema/coercion_wrapper'
#
# Schema-based validation and coercion
#
module RSchema
#
# Creates a schema obj... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/result.rb | Ruby | apache-2.0 | 45 | master | 836 | # frozen_string_literal: true
module RSchema
#
# The return value when calling a schema
#
class Result
def self.success(value = nil)
if value.nil?
NIL_SUCCESS
else
new(true, value, nil)
end
end
def self.failure(error = nil)
if error.nil?
NIL_FAILURE
... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/rails.rb | Ruby | apache-2.0 | 45 | master | 2,207 | # frozen_string_literal: true
require 'rschema'
require 'rschema/coercion_wrapper/rack_params'
module RSchema
module Rails
#
# A mixin for ActionController that provides methods for validating params.
#
module Controller
def self.included(klass)
klass.include(InstanceMethods)
k... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/options.rb | Ruby | apache-2.0 | 45 | master | 386 | # frozen_string_literal: true
module RSchema
#
# Settings, passed in as an argument when calling schemas
#
class Options
def self.default
@default ||= new
end
def self.fail_fast
@fail_fast ||= new(fail_fast: true)
end
def initialize(fail_fast: false)
@fail_fast = fail_fa... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/dsl.rb | Ruby | apache-2.0 | 45 | master | 10,423 | # frozen_string_literal: true
module RSchema
#
# A mixin containing all the standard RSchema DSL methods.
#
# This mixin contains only the standard RSchema DSL methods, without any of
# the extra ones that may have been included by third-party gems/code.
#
# @note Do not include your custom DSL methods i... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/error.rb | Ruby | apache-2.0 | 45 | master | 703 | # frozen_string_literal: true
module RSchema
#
# Contains info about how a schema failed validation
#
class Error
attr_reader :schema, :value, :symbolic_name, :vars
def initialize(schema:, value:, symbolic_name:, vars: {})
raise ArgumentError.new('vars must be a hash') unless vars.is_a?(Hash)
... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/coercion_wrapper.rb | Ruby | apache-2.0 | 45 | master | 1,226 | # frozen_string_literal: true
module RSchema
#
# Builds coercing schemas, by wrapping coercers around an existing schema.
#
class CoercionWrapper
def initialize(&initializer)
@builder_by_schema = {}
@builder_by_type = {}
instance_eval(&initializer) if initializer
end
def coerce(s... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/schemas/pipeline.rb | Ruby | apache-2.0 | 45 | master | 1,061 | # frozen_string_literal: true
module RSchema
module Schemas
#
# A schema that chains together an ordered list of other schemas
#
# @example A schema for positive floats
# schema = RSchema.define do
# pipeline(
# _Float,
# predicate{ |f| f > 0.0 },
# ... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/schemas/anything.rb | Ruby | apache-2.0 | 45 | master | 571 | # frozen_string_literal: true
module RSchema
module Schemas
#
# A schema that matches literally any value
#
# @example The anything schema
# schema = RSchema.define { anything }
# schema.valid?(nil) #=> true
# schema.valid?(6.2) #=> true
# schema.valid?({ hello: Time.now }) #=... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/schemas/boolean.rb | Ruby | apache-2.0 | 45 | master | 857 | # frozen_string_literal: true
module RSchema
module Schemas
#
# A schema that matches only `true` and `false`
#
# @example The boolean schema
# schema = RSchema.define { boolean }
# schema.valid?(true) #=> true
# schema.valid?(false) #=> true
# schema.valid?(nil) #=... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/schemas/predicate.rb | Ruby | apache-2.0 | 45 | master | 1,024 | # frozen_string_literal: true
module RSchema
module Schemas
#
# A schema that uses a given block to determine whether a value is valid
#
# @example A predicate that checks if numbers are odd
# schema = RSchema.define do
# predicate('odd'){ |x| x.odd? }
# end
# schema... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/schemas/variable_hash.rb | Ruby | apache-2.0 | 45 | master | 2,439 | # frozen_string_literal: true
module RSchema
module Schemas
#
# A schema that matches variable-sized `Hash` objects, where the keys are
# _not_ known ahead of time.
#
# @example A hash of integers to strings
# schema = RSchema.define { variable_hash(_Integer => _String) }
# schema... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/schemas/fixed_hash.rb | Ruby | apache-2.0 | 45 | master | 5,664 | # frozen_string_literal: true
module RSchema
module Schemas
#
# A schema that matches `Hash` objects with known keys
#
# @example A typical fixed hash schema
# schema = RSchema.define do
# fixed_hash(
# name: _String,
# optional(:age) => _Integer,
# ... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/schemas/maybe.rb | Ruby | apache-2.0 | 45 | master | 770 | # frozen_string_literal: true
module RSchema
module Schemas
#
# A schema representing that a value may be `nil`
#
# If the value is not `nil`, it must conform to the subschema
#
# @example A nil-able Integer
# schema = RSchema.define{ maybe(_Integer) }
# schema.valid?(5) #=> t... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/schemas/set.rb | Ruby | apache-2.0 | 45 | master | 1,923 | # frozen_string_literal: true
require 'set'
module RSchema
module Schemas
#
# A schema that matches `Set` objects (from the Ruby standard library)
#
# @example A set of integers
# require 'set'
# schema = RSchema.define { set(_Integer) }
# schema.valid?(Set[1, 2, 3]) #=> true... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/schemas/sum.rb | Ruby | apache-2.0 | 45 | master | 960 | # frozen_string_literal: true
module RSchema
module Schemas
#
# A schema that represents a "sum type"
#
# Values must conform to one of the subschemas.
#
# @example A schema that matches both Integers and Strings
# schema = RSchema.define { either(_String, _Integer) }
# schema... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/schemas/convenience.rb | Ruby | apache-2.0 | 45 | master | 3,824 | # frozen_string_literal: true
require 'delegate'
module RSchema
module Schemas
#
# A wrapper that provides convenience methods for schema objects.
#
# Because this class inherits from `SimpleDelegator`, convenience wrappers
# behave like their underlying schemas. That is, you can call methods on... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/schemas/variable_length_array.rb | Ruby | apache-2.0 | 45 | master | 1,921 | # frozen_string_literal: true
module RSchema
module Schemas
#
# A schema that matches variable-length arrays, where all elements conform
# to a single subschema
#
# @example A variable-length array schema
# schema = RSchema.define { array(_Integer) }
# schema.valid?([1,2,3]) #=> t... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/schemas/enum.rb | Ruby | apache-2.0 | 45 | master | 1,115 | # frozen_string_literal: true
module RSchema
module Schemas
#
# A schema that matches a values in a given set.
#
# @example Rock-Paper-Scissors values
# schema = RSchema.define { enum([:rock, :paper, :scissors]) }
# schema.valid?(:rock) #=> true
# schema.valid?(:paper) #=> tr... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/schemas/type.rb | Ruby | apache-2.0 | 45 | master | 1,029 | # frozen_string_literal: true
module RSchema
module Schemas
#
# A schema that matches values of a given type (i.e. `value.is_a?(type)`)
#
# @example An Integer schema
# schema = RSchema.define { _Integer }
# schema.valid?(5) #=> true
#
# @example A namespaced type
# sc... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/schemas/fixed_length_array.rb | Ruby | apache-2.0 | 45 | master | 2,350 | # frozen_string_literal: true
module RSchema
module Schemas
#
# A schema that represents an array of fixed length
#
# Each element in the fixed-length array has its own subschema
#
# @example A fixed-length array schema
# schema = RSchema.define { array(_Integer, _String) }
# ... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/schemas/coercer.rb | Ruby | apache-2.0 | 45 | master | 1,225 | # frozen_string_literal: true
module RSchema
module Schemas
#
# A schema that applies a coercer to a value, before passing the coerced
# value to a subschema.
#
# This is not a type of schema that you would typically create yourself.
# It is used internally to implement RSchema's coercion fun... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/coercers/symbol.rb | Ruby | apache-2.0 | 45 | master | 483 | # frozen_string_literal: true
module RSchema
module Coercers
#
# Coerces `String`s to `Symbol`s
#
module Symbol
extend self
def build(_schema)
self
end
def call(value)
case value
when ::Symbol then Result.success(value)
when ::String then Resu... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/coercers/integer.rb | Ruby | apache-2.0 | 45 | master | 511 | # frozen_string_literal: true
module RSchema
module Coercers
#
# Coerces values to `Integer`s using `Kernel#Integer`
module Integer
extend self
def build(_schema)
self
end
def call(value)
int = begin
Integer(value)
rescue StandardErr... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/coercers/boolean.rb | Ruby | apache-2.0 | 45 | master | 919 | # frozen_string_literal: true
module RSchema
module Coercers
#
# Coerces certain strings, and nil, to true or false
#
module Boolean
extend self
TRUTHY_STRINGS = %w[on 1 true yes].freeze
FALSEY_STRINGS = %w[off 0 false no].freeze
def build(_schema)
self
end
... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/coercers/nil_empty_strings.rb | Ruby | apache-2.0 | 45 | master | 429 | # frozen_string_literal: true
module RSchema
module Coercers
#
# Coerces empty strings to `nil`
#
module NilEmptyStrings
extend self
def build(_schema)
self
end
def call(value)
if value == ''
Result.success(nil)
else
Result.success... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/coercers/float.rb | Ruby | apache-2.0 | 45 | master | 516 | # frozen_string_literal: true
module RSchema
module Coercers
#
# Coerces values into `Float` objects using `Kernel#Float`
#
module Float
extend self
def build(_schema)
self
end
def call(value)
flt = begin
Float(value)
rescue Stan... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/coercers/chain.rb | Ruby | apache-2.0 | 45 | master | 1,031 | # frozen_string_literal: true
module RSchema
module Coercers
#
# Applies a list of coercers, in order
#
class Chain
attr_reader :subcoercers
def self.[](*subbuilders)
Builder.new(subbuilders)
end
def initialize(subcoercers)
@subcoercers = subcoercers
en... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/coercers/date.rb | Ruby | apache-2.0 | 45 | master | 729 | # frozen_string_literal: true
module RSchema
module Coercers
#
# Coerces strings into `Date` objects using `Date.parse`
module Date
extend self
def build(_schema)
self
end
def call(value)
case value
when ::Date then Result.success(value)
when ::St... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/coercers/time.rb | Ruby | apache-2.0 | 45 | master | 720 | # frozen_string_literal: true
module RSchema
module Coercers
#
# Coerces `String`s to `Time`s using `Time.parse`
module Time
extend self
def build(_schema)
self
end
def call(value)
case value
when ::Time then Result.success(value)
when ::String th... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/coercers/any.rb | Ruby | apache-2.0 | 45 | master | 1,006 | # frozen_string_literal: true
module RSchema
module Coercers
#
# Applies subcoercers, in order, until one succeeds
#
class Any
attr_reader :subcoercers
def self.[](*subbuilders)
Builder.new(subbuilders)
end
def initialize(subcoercers)
@subcoercers = subcoerce... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/coercers/fixed_hash/default_booleans_to_false.rb | Ruby | apache-2.0 | 45 | master | 1,940 | # frozen_string_literal: true
require 'set'
module RSchema
module Coercers
module FixedHash
# The HTTP standard says that when a form is submitted, all unchecked
# check boxes will _not_ be sent to the server. That is, they will not
# be present at all in the params hash.
#
# This ... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/coercers/fixed_hash/symbolize_keys.rb | Ruby | apache-2.0 | 45 | master | 1,733 | # frozen_string_literal: true
require 'set'
module RSchema
module Coercers
module FixedHash
#
# Coerces `String` keys into `Symbol`s according to the attributes in
# a given `FixedHash` schema.
#
class SymbolizeKeys
attr_reader :hash_attributes
def self.build(schem... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/coercers/fixed_hash/default_arrays_to_empty.rb | Ruby | apache-2.0 | 45 | master | 1,997 | # frozen_string_literal: true
require 'set'
module RSchema
module Coercers
module FixedHash
# The HTTP standard says that when a form is submitted, all unchecked
# check boxes will _not_ be sent to the server. That is, they will not
# be present at all in the params hash.
#
# This ... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/coercers/fixed_hash/remove_extraneous_attributes.rb | Ruby | apache-2.0 | 45 | master | 1,315 | # frozen_string_literal: true
module RSchema
module Coercers
module FixedHash
#
# Removes elements from `Hash` values that are not defined in the given
# `FixedHash` schema.
#
class RemoveExtraneousAttributes
attr_reader :hash_attributes
def self.build(schema)
... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | lib/rschema/coercion_wrapper/rack_params.rb | Ruby | apache-2.0 | 45 | master | 768 | # frozen_string_literal: true
require 'date'
module RSchema
class CoercionWrapper
RACK_PARAMS = CoercionWrapper.new do
coerce_type Symbol, with: Coercers::Symbol
coerce_type Integer, with: Coercers::Integer
coerce_type Float, with: Coercers::Float
coerce_type Time, with: Coercers::Time
... |
github | tomdalling/rschema | https://github.com/tomdalling/rschema | benchmarks/input_validation.rb | Ruby | apache-2.0 | 45 | master | 2,559 | require 'benchmark/ips'
require 'active_model'
require 'action_controller'
require 'dry-schema'
require 'dry/schema/version'
require_relative '../sh/env'
require 'rschema/coercion_wrapper/rack_params'
GOOD_INPUTS = [
{ name: 'Tom', age: 904 },
{ name: 'Piotr', age: nil },
{ name: 'Dane', age: 44, password: 'wig... |
github | stattleship/batcher | https://github.com/stattleship/batcher | batcher.gemspec | Ruby | mit | 45 | master | 930 | # -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "batcher/version"
Gem::Specification.new do |s|
s.name = "batcher"
s.version = Batcher::VERSION
s.authors = ["Harold Giménez"]
s.email = ["hgimenez@thoughtbot.com"]
s.homepage = ""
s.summary = %q{Data... |
github | stattleship/batcher | https://github.com/stattleship/batcher | lib/batcher/process.rb | Ruby | mit | 45 | master | 610 | module Batcher
class Process
attr_accessor :batch_size
def initialize(scope, opts = {})
@scope = scope
@batch_size = opts[:batch_size] || 1000
end
def each(&block)
iterator.each do |object|
yield object
end
end
def iterator
Enumerator.new do |yiel... |
github | stattleship/batcher | https://github.com/stattleship/batcher | spec/batcher_spec.rb | Ruby | mit | 45 | master | 228 | require 'spec_helper'
class User < ActiveRecord::Base
end
describe Batcher do
it 'provides an interface to Process' do
batcher = Batcher(User.where(name: 'foo'))
batcher.should be_kind_of(Batcher::Process)
end
end |
github | stattleship/batcher | https://github.com/stattleship/batcher | spec/spec_helper.rb | Ruby | mit | 45 | master | 764 | require 'rspec'
require 'active_record'
module DBHelpers
def build_and_migrate_database
create_db
ActiveRecord::Schema.define do
create_table :users, force: true do |t|
t.string :name
end
end
end
def create_db
ActiveRecord::Base.establish_connection(
:adapter => 'postg... |
github | stattleship/batcher | https://github.com/stattleship/batcher | spec/process_spec.rb | Ruby | mit | 45 | master | 785 | require 'spec_helper'
require 'batcher'
class User < ActiveRecord::Base
end
describe Batcher::Process do
it 'can be set a batch size' do
batcher = Batcher::Process.new(stub, batch_size: 42)
batcher.batch_size.should be == 42
end
it 'defaults to a batch size of 1000' do
batcher = Batcher::Process.ne... |
github | DGaffney/stop_sign_project | https://github.com/DGaffney/stop_sign_project | environment.rb | Ruby | mit | 45 | master | 1,061 | require 'tzinfo'
require 'twitter'
require 'pry'
require 'mongo_mapper'
require 'oauth'
require 'sinatra'
require 'oauth'
require 'csv'
require 'json'
require 'time'
require 'imgurapi'
Dir[File.dirname(__FILE__) + '/extensions/*.rb'].each {|file| require file }
Dir[File.dirname(__FILE__) + '/lib/*.rb'].each {|file| req... |
github | DGaffney/stop_sign_project | https://github.com/DGaffney/stop_sign_project | Rakefile | Ruby | mit | 45 | master | 400 | load 'environment.rb'
task :record_data do
RunCamera.new.run
end
task :analyze_data do
while true
puts Time.now
RunPredictor.new.run
puts "Sleeping for an hour!"
sleep(3600)
end
end
task :summarize_data do
while true
begin
puts Time.now
StopSignLog.generate_stats
puts "Sl... |
github | DGaffney/stop_sign_project | https://github.com/DGaffney/stop_sign_project | Gemfile | Ruby | mit | 45 | master | 214 | source 'https://rubygems.org'
gem 'rake', '~> 10.0.3'
gem 'pry'
gem 'mongo_mapper', '~> 0.12.0'
gem 'bson_ext', '~> 1.8.2'
gem 'hashie'
gem "sinatra"
gem "tux"
gem "oauth"
gem "imgurapi"
gem "twitter"
gem 'tzinfo' |
github | DGaffney/stop_sign_project | https://github.com/DGaffney/stop_sign_project | handlers/main.rb | Ruby | mit | 45 | master | 4,460 | VOTE_TYPES = {
"presence" => {"machine_vote_yes" => "Machine thinks there's a car in this GIF", "machine_vote_no" => "Machine thinks there's not a car in this GIF", "vote_type" => "Car Presence", "vote_negative" => "No Car", "vote_affirmative" => "Yes Car", "vote_text" => "Is there a moving car in this GIF? Press J i... |
github | DGaffney/stop_sign_project | https://github.com/DGaffney/stop_sign_project | lib/run_camera.rb | Ruby | mit | 45 | master | 4,368 | #This technique is from here: https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=156555
class RunCamera
def stream_photos
`mkdir #{CONFIG["project_dir"]}pics`
`mjpg_streamer -b -i "/usr/local/lib/input_uvc.so -d /dev/video0 -y -r 500x375 -f 20 -q 50" -o "/usr/local/lib/output_file.so -f #{CONFIG["projec... |
github | DGaffney/stop_sign_project | https://github.com/DGaffney/stop_sign_project | lib/reporting.rb | Ruby | mit | 45 | master | 3,936 | class Reporting
def self.generate
ssls = StopSignLog.where("voted_as.presence" => true, "voted_as.full_scene" => true).fields(:observation_timestamp).collect{|x| Time.at(x.observation_timestamp)}
violation_counts = Hash[ssls.collect{|x| x.strftime("%H")}.counts.sort_by{|k,v| k}]
ssls_weekend = StopSignLog... |
github | DGaffney/stop_sign_project | https://github.com/DGaffney/stop_sign_project | lib/run_predictor.rb | Ruby | mit | 45 | master | 2,224 | class RunPredictor
def can_be_learned(method)
return Vote.where(vote_method: method).count > 300 && Vote.where(vote_method: method, vote: 0).distinct(:stop_id).count > 100 && Vote.where(vote_method: method, vote: 1).distinct(:stop_id).count > 100
end
#eventually this needs memory optimization.
def export_... |
github | DGaffney/stop_sign_project | https://github.com/DGaffney/stop_sign_project | lib/tweet.rb | Ruby | mit | 45 | master | 863 | class Tweet
def self.client
Twitter::REST::Client.new do |config|
config.consumer_key = CONFIG["consumer_key"]
config.consumer_secret = CONFIG["consumer_secret"]
config.access_token = CONFIG["access_token"]
config.access_token_secret = CONFIG["access_token_secret"]
en... |
github | DGaffney/stop_sign_project | https://github.com/DGaffney/stop_sign_project | lib/export_data.rb | Ruby | mit | 45 | master | 3,192 | class ExportData
def self.run
`rsync -r #{CONFIG["raspi_rsync_addr"]}../videos .`
`rsync -r #{CONFIG["raspi_rsync_addr"]}cases .`
`rsync #{CONFIG["raspi_rsync_addr"]}stop_sign.log #{CONFIG["project_dir"]}stop_sign.log`
`rsync #{CONFIG["raspi_rsync_addr"]}stream_record.log #{CONFIG["project_dir"]}strea... |
github | DGaffney/stop_sign_project | https://github.com/DGaffney/stop_sign_project | helpers/layout.rb | Ruby | mit | 45 | master | 2,014 | module LayoutHelper
def include_css(*files)
if files.last.is_a?(Hash)
options = files.pop
else
options = {}
end
files.collect{|f|
timestamp = File.mtime(File.join(File.dirname(__FILE__), '..', 'public', 'css', f)).to_i
"<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/... |
github | DGaffney/stop_sign_project | https://github.com/DGaffney/stop_sign_project | extensions/fixnum.rb | Ruby | mit | 45 | master | 237 | class Fixnum
def delimited(delimiter=",")
self.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}")
end
end
class Float
def delimited(delimiter=",")
self.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}")
end
end |
github | DGaffney/stop_sign_project | https://github.com/DGaffney/stop_sign_project | extensions/array.rb | Ruby | mit | 45 | master | 4,587 | class Array
def rolling_diff
diff = []
self[0..-2].each_with_index do |val,i|
diff << val - self[i+1]
end
diff
end
def moving_average(increment = 1)
return self.average if increment == 1
a = self.dup
result = []
while(!a.empty?)
data = a.slice!(0,increment)
resul... |
github | DGaffney/stop_sign_project | https://github.com/DGaffney/stop_sign_project | models/machine_learner.rb | Ruby | mit | 45 | master | 713 | class MachineLearner
include MongoMapper::Document
key :vote_method, String
key :accuracy, Float
key :conmat, Hash
def estimated_count
marked_true = StopSignLog.count("voted_as.#{self.vote_method}" => true)
marked_false = StopSignLog.count("voted_as.#{self.vote_method}" => false)
return (marked... |
github | DGaffney/stop_sign_project | https://github.com/DGaffney/stop_sign_project | models/vote.rb | Ruby | mit | 45 | master | 303 | class Vote
include MongoMapper::Document
timestamps!
key :stop_id, String
key :vote_method, String
key :vote, Integer
key :session_id, String
key :vote_ip, String
def self.indices
Vote.ensure_index(:vote_method)
Vote.ensure_index([[:vote_method, 1], [:stop_id, 1]])
end
end |
github | DGaffney/stop_sign_project | https://github.com/DGaffney/stop_sign_project | models/observation_period.rb | Ruby | mit | 45 | master | 798 | class ObservationPeriod
include MongoMapper::Document
key :start_time, Time
key :end_time, Time
key :interevent_time, Float
key :observation_timestamp, Time
key :processed, Boolean
def self.import(import_file = "#{CONFIG["project_dir"]}stream_record.log")
CSV.read(import_file).each do |row|
if ... |
github | DGaffney/stop_sign_project | https://github.com/DGaffney/stop_sign_project | models/stats.rb | Ruby | mit | 45 | master | 574 | class Stats
include MongoMapper::Document
key :name, String
key :hourly, Hash
key :daily, Hash
key :total_transits, Integer
key :violation_rate, Float
key :observed_count, Integer
key :extrapolated_count, Integer
key :observation_period_count, Integer
key :stop_sign_log_count, Integer
key :seconds... |
github | DGaffney/stop_sign_project | https://github.com/DGaffney/stop_sign_project | models/stop_sign_log.rb | Ruby | mit | 45 | master | 12,545 | class StopSignLog
include MongoMapper::Document
key :frame_count, Integer
key :daylight, Boolean
key :ran_sign, Boolean
key :x_velocity, Float
key :event_at, Time
key :at_disallowed_time, Boolean
key :number_stopped_frames, Integer
key :centroid_data, Array
key :box_data, Array
key :stop_id, Strin... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | bookbinder.gemspec | Ruby | apache-2.0 | 45 | main | 2,477 | require 'base64'
Gem::Specification.new do |s|
s.name = 'bookbindery'
s.version = '10.1.18'
s.summary = 'Markdown to Rackup application documentation generator'
s.description = 'A command line utility to be run in Book repositories to stitch together their constituent Markdown repos into a stati... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | master_middleman/subdirectory_aware_assets.rb | Ruby | apache-2.0 | 45 | main | 1,168 | class SubdirectoryAwareAssets < ::Middleman::Extension
helpers do
def asset_path(path, prefix="", options={})
url = super(path, prefix, options)
unless global_asset_at? url
current_dir = Pathname('/' + current_resource.destination_path)
url = Pathname(url).relative_path_from(current_d... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | master_middleman/config.rb | Ruby | apache-2.0 | 45 | main | 942 | require 'bookbinder_helpers'
require 'proof'
require 'middleman-syntax'
require 'middleman-livereload'
require 'middleman-sprockets'
require 'subdirectory_aware_assets'
require 'middleman-compass'
require 'font-awesome-sass'
config = YAML.load_file('bookbinder_config.yml')
config.each do |k, v|
set k, v
end
set :ma... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | master_middleman/quicklinks_renderer.rb | Ruby | apache-2.0 | 45 | main | 1,859 | require 'nokogiri'
require 'redcarpet'
class QuicklinksRenderer < Redcarpet::Render::Base
class BadHeadingLevelError < StandardError; end
attr_reader :vars
def initialize(template_variables)
super()
@vars = template_variables
end
def doc_header
@items = []
@items[1] = document.css('ul').fi... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | master_middleman/proof.rb | Ruby | apache-2.0 | 45 | main | 2,587 | require 'nokogiri'
module Bookbinder
class Proof < ::Middleman::Extension
def initialize(*args)
super
@blacklist = [
%r{\Alayouts/},
%r{\Asubnavs/}
]
end
def before_build(builder)
return unless proofing?
builder.instance_variable_set(:@parallel, false)
... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | master_middleman/archive_drop_down_menu.rb | Ruby | apache-2.0 | 45 | main | 948 | module Bookbinder
class ArchiveDropDownMenu
def initialize(config, current_path: nil)
@config = config_with_default(config)
@current_path = current_path
end
def title
directory_config.first
end
def dropdown_links
versions_to_paths.map { |version_path|
{version_pat... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | master_middleman/bookbinder_helpers.rb | Ruby | apache-2.0 | 45 | main | 8,454 | require 'bookbinder/code_example_reader'
require 'bookbinder/ingest/cloner_factory'
require 'bookbinder/ingest/git_accessor'
require 'bookbinder/local_filesystem_accessor'
require 'date'
require_relative 'archive_drop_down_menu'
require_relative 'quicklinks_renderer'
I18n.enforce_available_locales = false
module Book... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/terminal.rb | Ruby | apache-2.0 | 45 | main | 497 | require_relative 'colorizer'
module Bookbinder
class Terminal
def initialize(colorizer)
@colorizer = colorizer
end
def update(user_message)
if user_message.error?
error_message = @colorizer.colorize(user_message.message, Colorizer::Colors.red)
$stderr.puts error_message
... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/css_link_checker.rb | Ruby | apache-2.0 | 45 | main | 1,803 | require 'css_parser'
module Bookbinder
class CssLinkChecker
def broken_links_in_all_stylesheets
localized_links_in_stylesheets.reject { |link| target_exists?(link) }
end
private
def localized_links_in_stylesheets
links_in_stylesheets = []
Dir.glob('**/*.css').each { |stylesheet| l... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/server_director.rb | Ruby | apache-2.0 | 45 | main | 584 | require 'puma'
module Bookbinder
class ServerDirector
def initialize(app: nil, directory: nil, port: 41722)
@app = app
@directory = directory
@port = port
end
def use_server
Dir.chdir(@directory) do
events = Puma::Events.new $stdout, $stderr
server = Puma::Server.... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/dita_command_creator.rb | Ruby | apache-2.0 | 45 | main | 3,180 | module Bookbinder
class DitaCommandCreator
MissingDitaOTFlagValue = Class.new(RuntimeError)
def initialize(path_to_dita_ot_library)
@path_to_dita_ot_library = path_to_dita_ot_library
end
def convert_to_pdf_command(dita_section, dita_flags: nil, write_to: nil)
"export CLASSPATH=#{classpat... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/middleman_runner.rb | Ruby | apache-2.0 | 45 | main | 1,444 | require 'middleman-core'
require 'middleman-core/cli'
require 'middleman-core/profiling'
require 'yaml'
module Bookbinder
class MiddlemanRunner
def initialize(fs, sheller)
@fs = fs
@sheller = sheller
end
def run(command,
streams: nil,
output_locations: nil,
... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/html_document_manipulator.rb | Ruby | apache-2.0 | 45 | main | 498 | require 'nokogiri'
module Bookbinder
class HtmlDocumentManipulator
def set_attribute(document: nil,
selector: nil,
attribute: nil,
value: nil)
doc = Nokogiri::HTML.fragment(document)
node_set = doc.css(selector)
node_set.attr(att... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/sheller.rb | Ruby | apache-2.0 | 45 | main | 1,020 | require 'open3'
module Bookbinder
class Sheller
ShelloutFailure = Class.new(RuntimeError)
class DevNull
def puts(_)
end
def <<(_)
end
end
def run_command(*command)
out, err =
if Hash === command.last
command.last.values_at(:out, :err)
else
... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/colorizer.rb | Ruby | apache-2.0 | 45 | main | 317 | require 'ansi/code'
require 'ostruct'
module Bookbinder
class Colorizer
Colors = OpenStruct.new(
green: ->(msg) { ANSI.green {msg} },
red: ->(msg) { ANSI.red {msg} },
yellow: ->(msg) { ANSI.yellow {msg} },
)
def colorize(string, color)
color.call string.to_s
end
end
end |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/local_filesystem_accessor.rb | Ruby | apache-2.0 | 45 | main | 3,102 | require 'find'
require 'pathname'
require_relative 'errors/programmer_mistake'
module Bookbinder
class LocalFilesystemAccessor
def file_exist?(path)
File.exist?(path)
end
def is_file?(path)
File.file?(path)
end
def is_dir?(path)
Dir.exists?(path)
end
def write(to: ni... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/dita_html_for_middleman_formatter.rb | Ruby | apache-2.0 | 45 | main | 1,531 | module Bookbinder
class DitaHtmlForMiddlemanFormatter
def initialize(file_system_accessor, html_document_manipulator)
@file_system_accessor = file_system_accessor
@html_document_manipulator = html_document_manipulator
end
def format_html(src, dest)
all_files_with_ext = file_system_acce... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/code_example_reader.rb | Ruby | apache-2.0 | 45 | main | 2,105 | module Bookbinder
class CodeExampleReader
class InvalidSnippet < StandardError
def initialize(repo, marker)
super "Error with marker #{marker} in #{repo}."
end
end
def initialize(streams, fs)
@out = streams[:out]
@fs = fs
end
def get_snippet_and_language_at(marker... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/cli.rb | Ruby | apache-2.0 | 45 | main | 3,535 | require 'thor'
require_relative 'ingest/git_accessor'
require_relative 'streams/colorized_stream'
require_relative 'colorizer'
require_relative 'commands/collection'
module Bookbinder
class CLI < Thor
def self.exit_on_failure?
true
end
map '--version' => :version
map '--help' => :help
de... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/values/output_locations.rb | Ruby | apache-2.0 | 45 | main | 1,815 | require_relative '../directory_helpers'
require_relative '../errors/programmer_mistake'
module Bookbinder
class OutputLocations
include DirectoryHelperMethods
def initialize(final_app_dir: nil, context_dir: nil)
@final_app_dir = final_app_dir
@context_dir = context_dir
end
def final_app... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/values/user_message.rb | Ruby | apache-2.0 | 45 | main | 308 | require 'ostruct'
module Bookbinder
UserMessage = Struct.new(:message, :escalation_type) do
def error?
escalation_type == EscalationType.error
end
def warn?
escalation_type == EscalationType.warn
end
end
EscalationType = OpenStruct.new(success: 0, error: 1, warn: 2)
end |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/values/section.rb | Ruby | apache-2.0 | 45 | main | 1,438 | require_relative '../errors/programmer_mistake'
require_relative '../ingest/destination_directory'
module Bookbinder
Section = Struct.new(
:path_to_repository,
:full_name,
:desired_directory_name,
:subnav_templ,
:desired_subnav_name,
:preprocessor_config,
:at_repo_path,
:repo_name,
... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/postprocessing/redirection.rb | Ruby | apache-2.0 | 45 | main | 841 | module Bookbinder
module Postprocessing
class Redirection
def initialize(fs, file_path)
@redirect_regexes = {}
@redirect_strings = {}
load!(fs, file_path)
end
def redirected?(url)
@redirect_strings.has_key?(url) ||
@redirect_regexes.keys.detect {|regex|... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/postprocessing/link_checker.rb | Ruby | apache-2.0 | 45 | main | 3,798 | require 'nokogiri'
require_relative '../css_link_checker'
require_relative 'redirection'
module Bookbinder
module Postprocessing
class LinkChecker
def initialize(fs, root_path, output_streams)
@fs = fs
@root_path = root_path
@output_streams = output_streams
@broken_link_coun... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/commands/watch.rb | Ruby | apache-2.0 | 45 | main | 3,090 | module Bookbinder
module Commands
class Watch
def initialize(streams,
middleman_runner: nil,
output_locations: nil,
config_fetcher: nil,
config_decorator: nil,
file_system_accessor: nil,
... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/commands/bind.rb | Ruby | apache-2.0 | 45 | main | 4,024 | require 'middleman-syntax'
require_relative 'components/command_options'
module Bookbinder
module Commands
class Bind
def initialize(base_streams,
output_locations: nil,
config_fetcher: nil,
config_decorator: nil,
file_sys... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/commands/punch.rb | Ruby | apache-2.0 | 45 | main | 886 | module Bookbinder
module Commands
class Punch
def initialize(streams, configuration_fetcher, version_control_system)
@streams = streams
@configuration_fetcher = configuration_fetcher
@version_control_system = version_control_system
end
def run((tag, *))
urls(conf... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/commands/collection.rb | Ruby | apache-2.0 | 45 | main | 6,548 | Dir.glob(File.expand_path('../../commands/*.rb', __FILE__)).each do |command_file|
require command_file unless command_file =~ /collection\.rb\z/
end
require_relative '../commands/components/bind/directory_preparer'
require_relative '../commands/components/imprint/directory_preparer'
require_relative '../config/conf... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/commands/generate.rb | Ruby | apache-2.0 | 45 | main | 2,297 | require 'bundler'
module Bookbinder
module Commands
class Generate
def initialize(fs, sheller, context_dir, streams)
@fs = fs
@sheller = sheller
@context_dir = context_dir
@streams = streams
end
def run(name, special_bookbinder_gem_args={})
path = contex... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/commands/update_local_doc_repos.rb | Ruby | apache-2.0 | 45 | main | 1,179 | require_relative '../ingest/destination_directory'
module Bookbinder
module Commands
class UpdateLocalDocRepos
def initialize(streams, configuration_fetcher, version_control_system)
@streams = streams
@configuration_fetcher = configuration_fetcher
@version_control_system = version_c... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/commands/imprint.rb | Ruby | apache-2.0 | 45 | main | 1,846 | require_relative 'components/command_options'
module Bookbinder
module Commands
class Imprint
def initialize(base_streams,
output_locations: nil,
config_fetcher: nil,
preprocessor: nil,
cloner_factory: nil,
... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/commands/components/command_options.rb | Ruby | apache-2.0 | 45 | main | 1,119 | require_relative '../../sheller'
require_relative '../../colorizer'
require_relative '../../streams/colorized_stream'
require_relative '../../streams/filter_stream'
module Bookbinder
module Commands
module Components
class CommandOptions
def initialize(opts, base_streams, verbose = false)
... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/commands/components/bind/layout_preparer.rb | Ruby | apache-2.0 | 45 | main | 830 | module Bookbinder
module Commands
module Components
module Bind
class LayoutPreparer
def initialize(fs)
@fs = fs
end
attr_reader :fs
def prepare(output_locations, cloner, ref_override, config)
if config.has_option?('layout_repo')
... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/commands/components/bind/directory_preparer.rb | Ruby | apache-2.0 | 45 | main | 968 | require_relative 'layout_preparer'
module Bookbinder
module Commands
module Components
module Bind
class DirectoryPreparer
def initialize(fs)
@fs = fs
end
def prepare_directories(config, gem_root, output_locations, cloner, ref_override: nil)
fs... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/commands/components/imprint/directory_preparer.rb | Ruby | apache-2.0 | 45 | main | 530 | module Bookbinder
module Commands
module Components
module Imprint
class DirectoryPreparer
def initialize(fs)
@fs = fs
end
def prepare_directories(output_locations)
fs.empty_directory(output_locations.output_dir)
fs.make_directory(ou... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/config/configuration_decorator.rb | Ruby | apache-2.0 | 45 | main | 1,493 | require_relative 'configuration'
module Bookbinder
module Config
class ConfigurationDecorator
def initialize(loader: nil, config_filename: nil)
@loader = loader
@config_filename = config_filename
end
def generate(base_config, sections)
base_config.merge(
Confi... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/config/product_config.rb | Ruby | apache-2.0 | 45 | main | 507 | module Bookbinder
module Config
class ProductConfig
def initialize(config)
@config = config
end
def id
config['id']
end
def pdf_config
config['pdf_config']
end
def subnav_root
config['subnav_root']
end
def valid?
(CO... |
github | pivotal-cf/bookbinder | https://github.com/pivotal-cf/bookbinder | lib/bookbinder/config/fetcher.rb | Ruby | apache-2.0 | 45 | main | 1,940 | require_relative 'configuration'
require_relative 'yaml_loader'
module Bookbinder
module Config
class Fetcher
def initialize(configuration_validator, loader, config_class)
@loader = loader
@configuration_validator = configuration_validator
@config_class = config_class
end
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.