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 | biola/Voight-Kampff | https://github.com/biola/Voight-Kampff | lib/voight_kampff/test.rb | Ruby | mit | 190 | master | 1,419 | module VoightKampff
class Test
CRAWLERS_FILENAME = 'crawler-user-agents.json'
attr_accessor :user_agent_string
def initialize(user_agent_string)
@user_agent_string = user_agent_string
end
def agent
@agent ||= matching_crawler || {}
end
def human?
agent.empty?
end
... |
github | biola/Voight-Kampff | https://github.com/biola/Voight-Kampff | lib/voight_kampff/engine.rb | Ruby | mit | 190 | master | 278 | module VoightKampff
class Engine < Rails::Engine
rake_tasks do
load 'tasks/voight_kampff.rake'
end
initializer :add_voight_kampff_methods do |app|
ActionDispatch::Request.class_eval do
include VoightKampff::Methods
end
end
end
end |
github | biola/Voight-Kampff | https://github.com/biola/Voight-Kampff | spec/spec_helper.rb | Ruby | mit | 190 | master | 251 | require 'bundler/setup'
require 'combustion'
require 'voight_kampff'
require 'voight_kampff/rails'
Combustion.initialize! :action_controller
require 'rspec/rails'
Dir['./spec/support/**/*.rb'].each { |f| require f }
RSpec.configure do |config|
end |
github | biola/Voight-Kampff | https://github.com/biola/Voight-Kampff | spec/controllers/replicants_controller_spec.rb | Ruby | mit | 190 | master | 815 | require 'spec_helper'
describe ReplicantsController, type: :controller do
let(:user_agent_string) { '' }
before do
expect_any_instance_of(ActionController::TestRequest).to receive(:user_agent).and_return user_agent_string
get :index
end
HUMANS.each do |name, ua_string|
context "when user agent is ... |
github | biola/Voight-Kampff | https://github.com/biola/Voight-Kampff | spec/support/humans.rb | Ruby | mit | 190 | master | 869 | HUMANS = {
'Unknown' => nil, # for the moment we're treating a blank user agent string as not a bot
'Chrome' => 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36',
'Firefox' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1',
'Safari... |
github | biola/Voight-Kampff | https://github.com/biola/Voight-Kampff | spec/support/replicants.rb | Ruby | mit | 190 | master | 306 | REPLICANTS = {
'Googlebot' => 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
'Bingbot' => 'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)',
'Yahoo! Slurp' => 'Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)'
} |
github | biola/Voight-Kampff | https://github.com/biola/Voight-Kampff | spec/internal/app/controllers/replicants_controller.rb | Ruby | mit | 190 | master | 288 | class ReplicantsController < ActionController::Base
def index
header = "Replicants:\n===========\n"
status, content = if request.bot?
[200, '- Rick Deckard']
else
[403, 'No replicants here']
end
render plain: header + content, status: status
end
end |
github | biola/Voight-Kampff | https://github.com/biola/Voight-Kampff | spec/lib/voight_kampff_spec.rb | Ruby | mit | 190 | master | 695 | require 'spec_helper'
describe VoightKampff do
subject { VoightKampff }
HUMANS.each do |name, ua_string|
context "when user agent is #{ua_string}" do
let(:user_agent_string) { ua_string }
it 'is not a replicant' do
expect(subject.human?(user_agent_string)).to be true
expect(subjec... |
github | biola/Voight-Kampff | https://github.com/biola/Voight-Kampff | spec/lib/voight_kampff/test_spec.rb | Ruby | mit | 190 | master | 945 | require 'spec_helper'
describe VoightKampff::Test do
let(:user_agent_string) { nil }
subject { VoightKampff::Test.new(user_agent_string) }
HUMANS.each do |name, ua_string|
context "when user agent is #{name}" do
let(:user_agent_string) { ua_string }
it 'is not a replicant' do
expect(sub... |
github | biola/Voight-Kampff | https://github.com/biola/Voight-Kampff | spec/lib/voight_kampff/rack_request_spec.rb | Ruby | mit | 190 | master | 855 | require 'spec_helper'
describe Rack::Request do
let(:user_agent_string) { }
let(:env) { {'HTTP_USER_AGENT' => user_agent_string} }
subject { Rack::Request.new(env) }
it { expect(subject).to respond_to :human? }
it { expect(subject).to respond_to :bot? }
it { expect(subject).to respond_to :replicant? }
... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | Rakefile | Ruby | mit | 190 | main | 311 | require "bundler/setup"
APP_RAKEFILE = File.expand_path("demo/Rakefile", __dir__)
load "rails/tasks/engine.rake"
load "rails/tasks/statistics.rake"
require "bundler/gem_tasks"
# assets:precompile does not exist. call app:assets:precompile is used instead
task "assets:precompile" => "app:assets:precompile" |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | spectator_sport.gemspec | Ruby | mit | 190 | main | 830 | require_relative "lib/spectator_sport/version"
Gem::Specification.new do |spec|
spec.name = "spectator_sport"
spec.version = SpectatorSport::VERSION
spec.summary = "Summary of SpectatorSport."
spec.description = "Description of SpectatorSport."
spec.license = "MIT"
spec.authors = [ ... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | Gemfile | Ruby | mit | 190 | main | 522 | source "https://rubygems.org"
if File.exist?(".ruby-version")
ruby file: ".ruby-version"
end
# Specify your gem's dependencies in spectator_sport.gemspec.
gemspec
gem "puma"
gem "sqlite3"
gem "pg"
gem "sprockets-rails"
# Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/]
gem "rubocop-rails-o... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | spec/spec_helper.rb | Ruby | mit | 190 | main | 5,061 | # frozen_string_literal: true
require "warning"
Warning.ignore([ :not_reached, :unused_var ], /.*lib\/mail\/parser.*/)
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` fil... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | spec/rails_helper.rb | Ruby | mit | 190 | main | 2,803 | # frozen_string_literal: true
# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../demo/config/environment', __dir__)
# Prevent database truncation if the environment is production
abort("The Rails environment is run... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | spec/app/controllers/events_controller_spec.rb | Ruby | mit | 190 | main | 783 | # frozen_string_literal: true
require 'rails_helper'
describe SpectatorSport::EventsController, type: :controller do
render_views
before do
@routes = SpectatorSport::Engine.routes
end
describe 'POST #create' do
it 'stores events from rrweb' do
payload = {
"sessionId": "fb1x1aji7p5nljgn... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | spec/app/controllers/dashboard/session_windows_controller_spec.rb | Ruby | mit | 190 | main | 2,560 | # frozen_string_literal: true
require "rails_helper"
describe SpectatorSport::Dashboard::SessionWindowsController, type: :controller do
render_views
before do
@routes = SpectatorSport::Dashboard::Engine.routes
end
let(:spectator_session) { SpectatorSport::Session.create!(secure_id: "test-session-id") }
... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | spec/support/system.rb | Ruby | mit | 190 | main | 1,722 | # frozen_string_literal: true
require "capybara/rspec"
require "capybara/cuprite"
Capybara.default_max_wait_time = 2
Capybara.server = :puma, { Silent: true }
Capybara.disable_animation = true # injects CSP-incompatible CSS and JS
module SystemTestHelpers
def wait_for_recording
# Allow async label/tag watchers... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | spec/support/example_app_helper.rb | Ruby | mit | 190 | main | 3,096 | # frozen_string_literal: true
require 'fileutils'
module ExampleAppHelper
def setup_example_app
FileUtils.rm_rf(example_app_path)
# Rails will not install within a directory containing `bin/rails`
Rails.root.join("../bin/rails").rename(Rails.root.join("../bin/_rails")) if Rails.root.join("../bin/rails"... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | spec/system/recording_tags_spec.rb | Ruby | mit | 190 | main | 525 | # frozen_string_literal: true
require "rails_helper"
RSpec.describe "Recording tags", type: :system, js: true do
it "stores a tag from the page and shows it in the dashboard" do
visit "/examples"
expect(page).to have_text("Your browser activity is being recorded.")
wait_for_recording
visit "/specta... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | spec/system/stop_recording_spec.rb | Ruby | mit | 190 | main | 671 | # frozen_string_literal: true
require "rails_helper"
RSpec.describe "Stop recording", type: :system, js: true do
it "does not record when stop recording tag is present" do
expect {
visit "/examples/stopped"
visit "/spectator_sport_dashboard"
}.not_to change { SpectatorSport::SessionWindow.count ... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | spec/system/dashboard_spec.rb | Ruby | mit | 190 | main | 229 | # frozen_string_literal: true
require "rails_helper"
RSpec.describe "Dashboard", type: :system do
it "shows the dashboard" do
visit "/spectator_sport_dashboard"
expect(page).to have_text("Spectator Sport")
end
end |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | spec/system/recording_labels_spec.rb | Ruby | mit | 190 | main | 3,575 | # frozen_string_literal: true
require "rails_helper"
RSpec.describe "Recording labels", type: :system, js: true do
it "stores a keyed label from the page and shows it in the dashboard" do
visit "/examples"
expect(page).to have_text("Your browser activity is being recorded.")
wait_for_recording
visi... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | spec/system/player_timestamp_link_spec.rb | Ruby | mit | 190 | main | 2,053 | # frozen_string_literal: true
require "rails_helper"
RSpec.describe "Player timestamp link", type: :system, js: true do
it "generates a timestamp link that loads the recording at the correct time" do
session = SpectatorSport::Session.create!(secure_id: "test-session")
session_window = SpectatorSport::Sessio... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | spec/generators/spectator_sport/install_generator_spec.rb | Ruby | mit | 190 | main | 552 | # frozen_string_literal: true
require 'rails_helper'
# require 'generators/spectator_sport/install_generator'
describe "install generator", type: :generator do
around do |example|
quiet { setup_example_app }
example.run
teardown_example_app
end
it 'creates a migration for spectator_sport_events tab... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | db/migrate/20260413000001_create_spectator_sport_labels.rb | Ruby | mit | 190 | main | 674 | class CreateSpectatorSportLabels < ActiveRecord::Migration[7.2]
def change
create_table :spectator_sport_labels do |t|
t.timestamps
t.references :session_window, null: false
t.string :key
t.string :value, null: false
t.boolean :multiple, null: false, default: true
t.index [ :s... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | db/migrate/20260403000000_create_spectator_sport_session_window_tags.rb | Ruby | mit | 190 | main | 325 | class CreateSpectatorSportSessionWindowTags < ActiveRecord::Migration[7.2]
def change
create_table :spectator_sport_session_window_tags do |t|
t.timestamps
t.references :session_window, null: false
t.string :tag, null: false
t.index [ :session_window_id, :tag ], unique: true
end
end... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | db/migrate/20240923140845_create_spectator_sport_events.rb | Ruby | mit | 190 | main | 738 | class CreateSpectatorSportEvents < ActiveRecord::Migration[7.2]
def change
create_table :spectator_sport_sessions do |t|
t.timestamps
t.string :secure_id, null: false
t.index [ :secure_id, :created_at ]
end
create_table :spectator_sport_session_windows do |t|
t.timestamps
t... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | app/models/spectator_sport/event.rb | Ruby | mit | 190 | main | 1,951 | module SpectatorSport
class Event < ApplicationRecord
PAGE_LIMIT = 1_000
belongs_to :session
belongs_to :session_window
scope :page_after, ->(event) { (event ? where("(created_at, id) > (?, ?)", event.created_at, event.id) : self).order(created_at: :asc, id: :asc).limit(PAGE_LIMIT) }
Explanatio... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | app/models/spectator_sport/session_window_tag.rb | Ruby | mit | 190 | main | 439 | module SpectatorSport
class SessionWindowTag < ApplicationRecord
belongs_to :session_window
validates :tag, presence: true, uniqueness: { scope: :session_window_id }
def self.migrated?
return true if table_exists?
Rails.logger.warn "SpectatorSport: pending migration for spectator_sport_sessi... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | app/models/spectator_sport/label.rb | Ruby | mit | 190 | main | 1,530 | module SpectatorSport
class Label < ApplicationRecord
self.table_name = "spectator_sport_labels"
belongs_to :session_window
validates :value, presence: true
def self.migrated?
return true if table_exists?
Rails.logger.warn "SpectatorSport: pending migration for spectator_sport_labels ta... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | app/models/spectator_sport/session_window.rb | Ruby | mit | 190 | main | 361 | module SpectatorSport
class SessionWindow < ApplicationRecord
belongs_to :session
has_many :events, dependent: :delete_all
has_many :session_window_tags, dependent: :delete_all
has_many :labels, class_name: "SpectatorSport::Label", dependent: :delete_all
def analysis
@analysis ||= SessionWi... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | app/models/spectator_sport/session_window_analysis.rb | Ruby | mit | 190 | main | 228 | module SpectatorSport
class SessionWindowAnalysis
def initialize(session_window)
@session_window = session_window
end
def visited_pages
@session_window.events.map { _1.page }.compact
end
end
end |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | app/controllers/spectator_sport/events_controller.rb | Ruby | mit | 190 | main | 2,271 | module SpectatorSport
class EventsController < ApplicationController
skip_before_action :verify_authenticity_token
def index
end
def create
data = if params.key?(:sessionId) && params.key?(:windowId) && params.key?(:events)
params.slice(:sessionId, :windowId, :events, :tags, :labels).s... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | app/controllers/spectator_sport/dashboard/frontends_controller.rb | Ruby | mit | 190 | main | 2,035 | # frozen_string_literal: true
module SpectatorSport
module Dashboard
class FrontendsController < ActionController::Base # rubocop:disable Rails/ApplicationController
protect_from_forgery with: :exception
skip_after_action :verify_same_origin_request, raise: false
def self.asset_path(path)
... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | app/controllers/spectator_sport/dashboard/session_windows_controller.rb | Ruby | mit | 190 | main | 1,293 | module SpectatorSport
module Dashboard
class SessionWindowsController < ApplicationController
def show
@session_window = SessionWindow.find(params[:id])
@events = @session_window.events.page_after(nil)
@tags = SpectatorSport::SessionWindowTag.migrated? ? @session_window.session_windo... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | app/controllers/spectator_sport/dashboard/tags_controller.rb | Ruby | mit | 190 | main | 377 | module SpectatorSport
module Dashboard
class TagsController < ApplicationController
def show
@tag = params[:name]
@session_windows = SpectatorSport::SessionWindowTag
.where(tag: @tag)
.includes(:session_window)
.order(created_at: :desc)
.limit(50)
... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | app/controllers/spectator_sport/dashboard/labels_controller.rb | Ruby | mit | 190 | main | 1,035 | module SpectatorSport
module Dashboard
class LabelsController < ApplicationController
def tags
@value = params[:value]
@session_windows = session_windows_scope
.where(spectator_sport_labels: { key: nil, value: @value })
end
def key_index
@key = params[:key]
... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | app/controllers/spectator_sport/dashboard/application_controller.rb | Ruby | mit | 190 | main | 247 | module SpectatorSport
module Dashboard
class ApplicationController < ActionController::Base
end
end
end
ActiveSupport.run_load_hooks(:spectator_sport_dashboard_application_controller, SpectatorSport::Dashboard::ApplicationController) |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | app/controllers/spectator_sport/dashboard/dashboards_controller.rb | Ruby | mit | 190 | main | 442 | module SpectatorSport
module Dashboard
class DashboardsController < ApplicationController
def index
@session_windows = SessionWindow.order(:created_at).limit(50).reverse_order
@session_windows = @session_windows.includes(:session_window_tags) if SpectatorSport::SessionWindowTag.migrated?
... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | app/helpers/spectator_sport/script_helper.rb | Ruby | mit | 190 | main | 830 | module SpectatorSport
module ScriptHelper
def spectator_sport_script_tags
tag.script defer: true, src: spectator_sport.events_path(format: :js)
end
def spectator_sport_tag_recording(tag_value)
signed = Rails.application.message_verifier(:spectator_sport_tag_recording).generate(tag_value)
... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | app/helpers/spectator_sport/dashboard/icons_helper.rb | Ruby | mit | 190 | main | 448 | module SpectatorSport
module Dashboard
module IconsHelper
def render_icon(name, class: nil, **options)
tag.svg(viewBox: "0 0 16 16", class: "svg-icon #{binding.local_variable_get(:class)}", **options) do
tag.use(fill: "currentColor", href: "#{icons_path}##{name}")
end
end
... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | demo/config/application.rb | Ruby | mit | 190 | main | 1,053 | require_relative "boot"
require "rails/all"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Demo
class Application < Rails::Application
config.load_defaults Rails::VERSION::STRING.to_f
# For compatibili... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | demo/config/routes.rb | Ruby | mit | 190 | main | 327 | Rails.application.routes.draw do
mount SpectatorSport::Engine => "/spectator_sport"
mount SpectatorSport::Dashboard::Engine => "/spectator_sport_dashboard"
root to: "examples#index"
resources :examples, only: [ :index, :show, :new, :create ] do
collection do
get :error
get :stopped
end
e... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | demo/config/puma.rb | Ruby | mit | 190 | main | 1,883 | # This configuration file will be evaluated by Puma. The top-level methods that
# are invoked here are part of Puma's configuration DSL. For more information
# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html.
# Puma starts a configurable number of processes (workers) and each process
# serves... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | demo/config/environments/production.rb | Ruby | mit | 190 | main | 4,560 | require "active_support/core_ext/integer/time"
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.enable_reloading = false
# Eager load code on boot. This eager loads most of Rails and
# your app... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | demo/db/schema.rb | Ruby | mit | 190 | main | 3,276 | # This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rai... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | demo/app/controllers/examples_controller.rb | Ruby | mit | 190 | main | 754 | class ExamplesController < ApplicationController
ExampleError = Class.new(StandardError)
def index
end
def new
@resource = FakeModel.new
end
def create
resource_params = params.require(:resource).permit(:name, :message)
@resource = FakeModel.new(resource_params)
end
class FakeModel
i... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | lib/spectator_sport/engine.rb | Ruby | mit | 190 | main | 533 | module SpectatorSport
class Engine < ::Rails::Engine
isolate_namespace SpectatorSport
initializer "local_helper.action_controller" do
ActiveSupport.on_load :action_controller do
# TODO: this should probably be done manually by the client, maybe?
helper SpectatorSport::ScriptHelper
... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | config/dashboard_routes.rb | Ruby | mit | 190 | main | 729 | SpectatorSport::Dashboard::Engine.routes.draw do
root to: "dashboards#index"
resources :session_windows, only: [ :show, :destroy ] do
member do
get :details
get :events
end
end
resources :tags, only: [ :show ], param: :name
get "labels/tags/:value", to: "labels#tags", as: :label_tag
get ... |
github | bensheldon/spectator_sport | https://github.com/bensheldon/spectator_sport | config/git_worktree.rb | Ruby | mit | 190 | main | 1,477 | # frozen_string_literal: true
# Helper for Git worktree-aware behavior
module GitWorktree
PROJECT_ROOT = File.expand_path("..", __dir__)
def self.name
return @_name if defined?(@_name)
git_dir = `git rev-parse --git-dir 2>/dev/null`.strip
return @_name = nil if git_dir.empty? || !git_dir.include?("/.... |
github | dblock/ruby-enum | https://github.com/dblock/ruby-enum | Rakefile | Ruby | mit | 189 | master | 495 | # frozen_string_literal: true
require 'rubygems'
require 'bundler/gem_tasks'
Bundler.setup :default, :development
require 'rspec/core'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
end
require 'rubocop/rake_task'
RuboCop::RakeTask.new(:rubo... |
github | dblock/ruby-enum | https://github.com/dblock/ruby-enum | Gemfile | Ruby | mit | 189 | master | 344 | # frozen_string_literal: true
source 'http://rubygems.org'
gemspec
gem 'rake'
group :development, :test do
gem 'danger'
gem 'danger-changelog'
gem 'danger-pr-comment'
gem 'danger-toc'
gem 'rspec'
gem 'rubocop', '1.82.1'
gem 'rubocop-rake'
gem 'rubocop-rspec'
end
group :test do
gem 'coveralls_rebo... |
github | dblock/ruby-enum | https://github.com/dblock/ruby-enum | ruby-enum.gemspec | Ruby | mit | 189 | master | 603 | # frozen_string_literal: true
$LOAD_PATH.push File.expand_path('lib', __dir__)
require 'ruby-enum/version'
Gem::Specification.new do |s|
s.name = 'ruby-enum'
s.version = Ruby::Enum::VERSION
s.authors = ['Daniel Doubrovkine']
s.email = 'dblock@dblock.org'
s.platform = Gem::Platform::RUBY
s.required_rubygem... |
github | dblock/ruby-enum | https://github.com/dblock/ruby-enum | benchmarks/case.rb | Ruby | mit | 189 | master | 1,023 | # frozen_string_literal: true
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'benchmark'
require 'ruby-enum'
##
# Test enum
class Color
include Ruby::Enum
include Ruby::Enum::Case
define :RED, :red
define :GREEN, :green
define :BLUE, :blue
end
puts 'Running 1.000.000 normal ca... |
github | dblock/ruby-enum | https://github.com/dblock/ruby-enum | lib/ruby-enum.rb | Ruby | mit | 189 | master | 715 | # frozen_string_literal: true
require 'ruby-enum/version'
require 'ruby-enum/enum'
require 'ruby-enum/enum/case'
require 'ruby-enum/enum/i18n_mock'
# Try to load the I18n gem and provide a mock if it is not available.
begin
require 'i18n'
Ruby::Enum.i18n = I18n
rescue LoadError
# I18n is not available
# :noco... |
github | dblock/ruby-enum | https://github.com/dblock/ruby-enum | lib/ruby-enum/enum.rb | Ruby | mit | 189 | master | 3,951 | # frozen_string_literal: true
module Ruby
module Enum
class << self
# Needed for I18n mock
attr_accessor :i18n
end
attr_reader :key, :value
def initialize(key, value)
@key = key
@value = value
end
def self.included(base)
base.extend Enumerable
base.exten... |
github | dblock/ruby-enum | https://github.com/dblock/ruby-enum | lib/ruby-enum/errors/uninitialized_constant_error.rb | Ruby | mit | 189 | master | 257 | # frozen_string_literal: true
module Ruby
module Enum
module Errors
class UninitializedConstantError < Base
def initialize(attrs)
super(compose_message('uninitialized_constant', attrs))
end
end
end
end
end |
github | dblock/ruby-enum | https://github.com/dblock/ruby-enum | lib/ruby-enum/errors/base.rb | Ruby | mit | 189 | master | 2,280 | # frozen_string_literal: true
module Ruby
module Enum
module Errors
class Base < StandardError
# Problem occurred.
attr_reader :problem
# Summary of the problem.
attr_reader :summary
# Suggested problem resolution.
attr_reader :resolution
# Compose... |
github | dblock/ruby-enum | https://github.com/dblock/ruby-enum | lib/ruby-enum/errors/duplicate_key_error.rb | Ruby | mit | 189 | master | 295 | # frozen_string_literal: true
module Ruby
module Enum
module Errors
# Error raised when a duplicate enum key is found
class DuplicateKeyError < Base
def initialize(attrs)
super(compose_message('duplicate_key', attrs))
end
end
end
end
end |
github | dblock/ruby-enum | https://github.com/dblock/ruby-enum | lib/ruby-enum/errors/duplicate_value_error.rb | Ruby | mit | 189 | master | 301 | # frozen_string_literal: true
module Ruby
module Enum
module Errors
# Error raised when a duplicate enum value is found
class DuplicateValueError < Base
def initialize(attrs)
super(compose_message('duplicate_value', attrs))
end
end
end
end
end |
github | dblock/ruby-enum | https://github.com/dblock/ruby-enum | lib/ruby-enum/enum/case.rb | Ruby | mit | 189 | master | 2,300 | # frozen_string_literal: true
module Ruby
module Enum
##
# Adds a method to an enum class that allows for exhaustive matching on a value.
#
# @example
# class Color
# include Ruby::Enum
# include Ruby::Enum::Case
#
# define :RED, :red
# define :GREEN, :green
# de... |
github | dblock/ruby-enum | https://github.com/dblock/ruby-enum | lib/ruby-enum/enum/i18n_mock.rb | Ruby | mit | 189 | master | 298 | # frozen_string_literal: true
# :nocov:
module Ruby
module Enum
##
# Mock I18n module in case the i18n gem is not available.
module I18nMock
def self.load_path
[]
end
def self.translate(key, _options = {})
key
end
end
end
end
# :nocov: |
github | dblock/ruby-enum | https://github.com/dblock/ruby-enum | spec_i18n/Gemfile | Ruby | mit | 189 | master | 207 | # frozen_string_literal: true
source 'http://rubygems.org'
gemspec path: '../', name: 'ruby-enum'
# This Gemfile should not include any gem that has i18n as a dependency.
gem 'rake'
gem 'rspec', '~> 3.0' |
github | dblock/ruby-enum | https://github.com/dblock/ruby-enum | spec_i18n/Rakefile | Ruby | mit | 189 | master | 222 | # frozen_string_literal: true
require 'rubygems'
require 'rspec/core'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
end
task default: %i[spec] |
github | dblock/ruby-enum | https://github.com/dblock/ruby-enum | spec_i18n/spec/i18n_spec.rb | Ruby | mit | 189 | master | 1,373 | # frozen_string_literal: true
require 'spec_helper'
module I18n
class Colors
include Ruby::Enum
define :RED, 'red'
define :GREEN, 'green'
end
end
describe Ruby::Enum do
context 'when the i18n gem is not loaded' do
it 'raises UninitializedConstantError on an invalid constant' do
expect do... |
github | dblock/ruby-enum | https://github.com/dblock/ruby-enum | spec/spec_helper.rb | Ruby | mit | 189 | master | 243 | # frozen_string_literal: true
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'rubygems'
require 'coveralls'
Coveralls.wear!
require 'rspec'
require 'ruby-enum'
RSpec.configure(&:raise_errors_for_deprecations!) |
github | dblock/ruby-enum | https://github.com/dblock/ruby-enum | spec/ruby-enum/enum_spec.rb | Ruby | mit | 189 | master | 8,711 | # frozen_string_literal: true
require 'spec_helper'
describe Ruby::Enum do
class Colors
include Ruby::Enum
define :RED, 'red'
define :GREEN, 'green'
end
class FirstSubclass < Colors
define :ORANGE, 'orange'
end
class SecondSubclass < FirstSubclass
define :PINK, 'pink'
end
it 'retu... |
github | dblock/ruby-enum | https://github.com/dblock/ruby-enum | spec/ruby-enum/enum/case_spec.rb | Ruby | mit | 189 | master | 3,137 | # frozen_string_literal: true
require 'spec_helper'
module Case
class Colors
include Ruby::Enum
include Ruby::Enum::Case
define :RED, :red
define :GREEN, :green
define :BLUE, :blue
end
end
RSpec.describe Ruby::Enum::Case do
describe '.case' do
context 'when all cases are defined' do
... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | motion_model.gemspec | Ruby | mit | 189 | master | 728 | # -*- encoding: utf-8 -*-
require File.expand_path('../motion/version', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ["Steve Ross"]
gem.email = ["sxross@gmail.com"]
gem.description = "Simple model and validation mixins for RubyMotion"
gem.summary = "Simple model and validation ... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | Rakefile | Ruby | mit | 189 | master | 514 | # -*- coding: utf-8 -*-
require "bundler/gem_tasks"
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project/template/ios'
require 'bundler'
Bundler.require
$:.unshift(File.expand_path('../lib', __FILE__))
require 'motion_model'
Motion::Project::App.setup do |app|
# Use `rake config' to see complete project se... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | spec/cascading_delete_spec.rb | Ruby | mit | 189 | master | 3,003 | class Assignee
include MotionModel::Model
include MotionModel::ArrayModelAdapter
columns :assignee_name => :string
belongs_to :task
end
class Task
include MotionModel::Model
include MotionModel::ArrayModelAdapter
columns :name => :string,
:details => :string,
:some_d... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | spec/column_options_spec.rb | Ruby | mit | 189 | master | 709 | class ModelWithOptions
include MotionModel::Model
include MotionModel::ArrayModelAdapter
columns :date => {:type => :date, :formotion => {:picker_type => :date_time}}
end
describe "column options" do
it "accepts the hash form of column declaration" do
lambda{ModelWithOptions.new}.should.not.raise
end
... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | spec/adapter_spec.rb | Ruby | mit | 189 | master | 716 | class ModelWithAdapter
include MotionModel::Model
include MotionModel::ArrayModelAdapter
columns :name
end
describe 'adapters with adapter method defined' do
it "does not raise an exception" do
lambda{ModelWithAdapter.create(:name => 'bob')}.should.not.raise
end
it "provides humanized string represen... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | spec/relation_spec.rb | Ruby | mit | 189 | master | 7,442 | class Assignee
include MotionModel::Model
include MotionModel::ArrayModelAdapter
columns :assignee_name => :string
belongs_to :task
end
class Task
include MotionModel::Model
include MotionModel::ArrayModelAdapter
columns :name => :string,
:details => :string,
:some_d... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | spec/model_hook_spec.rb | Ruby | mit | 189 | master | 1,820 | Object.send(:remove_const, :Task) if defined?(Task)
class Task
attr_reader :before_delete_called, :after_delete_called
attr_reader :before_save_called, :after_save_called
include MotionModel::Model
include MotionModel::ArrayModelAdapter
columns :name => :string,
:details => :string,
... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | spec/kvo_config_clone_spec.rb | Ruby | mit | 189 | master | 785 | describe "cloning configuration data for KVO" do
class KVOObservable
include MotionModel::Model
include MotionModel::ArrayModelAdapter
columns :name, :nickname
end
class KVOWatcher
attr_reader :o
include BW::KVO
def initialize(o)
@o = o
observe(o, :name) do |old_value, new_... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | spec/date_spec.rb | Ruby | mit | 189 | master | 3,340 | describe "time conversions" do
it "NSDate and Time should agree on minutes since epoch" do
t = Time.new
d = NSDate.dateWithTimeIntervalSince1970(t.to_f)
(t.to_f - d.timeIntervalSince1970).abs.should. < 0.001
end
it "Parsing '3/18/12 @ 7:00 PM' With Natural Language should work right" do
NSDate.da... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | spec/finder_spec.rb | Ruby | mit | 189 | master | 6,633 | class Task
include MotionModel::Model
include MotionModel::ArrayModelAdapter
columns :name => :string,
:details => :string,
:some_day => :date
end
describe 'finders' do
before do
Task.delete_all
1.upto(10) {|i| Task.create(:name => "task #{i}", :id => i)}
end
describe 'find... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | spec/model_spec.rb | Ruby | mit | 189 | master | 9,945 | class ModelSpecTask
include MotionModel::Model
include MotionModel::ArrayModelAdapter
columns :name => :string,
:details => :string,
:some_day => :date,
:enabled => {:type => :boolean, :default => false}
def custom_attribute_by_method
"#{name} - #{details}"
end
end... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | spec/array_model_persistence_spec.rb | Ruby | mit | 189 | master | 8,770 | class PersistTask
include MotionModel::Model
include MotionModel::ArrayModelAdapter
columns :name => :string,
:desc => :string,
:created_at => :date,
:updated_at => :date
end
describe 'persistence' do
before do
PersistTask.delete_all
%w(one two three).each do |task|
... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | spec/validation_spec.rb | Ruby | mit | 189 | master | 6,388 | class ValidatableTask
include MotionModel::Model
include MotionModel::ArrayModelAdapter
include MotionModel::Validatable
columns :name => :string,
:email => :string,
:some_day => :string,
:some_float => :float,
:some_int => :int
validate ... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | spec/transaction_spec.rb | Ruby | mit | 189 | master | 2,721 | class TransactClass
include MotionModel::Model
include MotionModel::ArrayModelAdapter
include MotionModel::Model::Transactions
columns :name, :age
has_many :transaction_things
end
class TransactionThing
include MotionModel::Model
include MotionModel::ArrayModelAdapter
include MotionModel::Model::Transa... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | spec/formotion_spec.rb | Ruby | mit | 189 | master | 6,078 | Object.send(:remove_const, :ModelWithOptions) if defined?(ModelWithOptions)
class ModelWithOptions
include MotionModel::Model
include MotionModel::ArrayModelAdapter
include MotionModel::Formotion
columns :name => :string,
:date => {:type => :date, :formotion => {:picker_type => :date_time}},
... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | spec/proc_defaults_spec.rb | Ruby | mit | 189 | master | 1,903 | describe "proc for defaults" do
describe "accepts a proc or block for default" do
describe "accepts proc" do
class AcceptsProc
include MotionModel::Model
include MotionModel::ArrayModelAdapter
columns subject: { type: :array, default: ->{ [] } }
end
before do
@t... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | spec/ext_spec.rb | Ruby | mit | 189 | master | 1,993 | describe 'Extensions' do
describe 'Pluralization' do
it 'pluralizes a normal word: dog' do
Inflector.inflections.pluralize('dog').should == 'dogs'
end
it 'pluralizes words that end in "s": pass' do
Inflector.inflections.pluralize('pass').should == 'passes'
end
it "pluralizes words th... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | spec/notification_spec.rb | Ruby | mit | 189 | master | 2,084 | class NotifiableTask
include MotionModel::Model
include MotionModel::ArrayModelAdapter
columns :name
@@notification_called = false
@@notification_details = :none
def notification_called; @@notification_called; end
def notification_called=(value); @@notification_called = value; end
def notification_de... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | spec/has_one_as_object_spec.rb | Ruby | mit | 189 | master | 1,534 | class User
include MotionModel::Model
include MotionModel::ArrayModelAdapter
columns :name => :string
has_one :profile
end
class Profile
include MotionModel::Model
include MotionModel::ArrayModelAdapter
columns :email => :string
belongs_to :user
end
describe 'has_one behaviors' do
before do
... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | spec/model_casting_spec.rb | Ruby | mit | 189 | master | 9,065 | class TypeCast
include MotionModel::Model
include MotionModel::ArrayModelAdapter
columns :a_boolean => :boolean,
:an_int => {:type => :int, :default => 3},
:an_integer => :integer,
:a_float => :float,
:a_double => :double,
:a_date => :date,
:a_time => :t... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | motion/input_helpers.rb | Ruby | mit | 189 | master | 6,923 | module MotionModel
module InputHelpers
class ModelNotSetError < RuntimeError; end
# FieldBindingMap contains a simple label to model
# field binding, and is decorated by a tag to be
# used on the UI control.
class FieldBindingMap
attr_accessor :label, :name, :tag
def initialize(optio... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | motion/ext.rb | Ruby | mit | 189 | master | 8,463 | # The reason the String extensions are wrapped in
# conditional blocks is to reduce the likelihood
# of a namespace collision with other libraries.
class String
unless String.instance_methods.include?(:humanize)
def humanize
self.split(/_|-| /).join(' ')
end
end
unless String.instance_methods.incl... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | motion/date_parser.rb | Ruby | mit | 189 | master | 2,398 | module DateParser
@@isoDateFormatter = nil
@@detector = nil
# Parse a date string: E.g.:
#
# DateParser.parse_date "There is a date in here tomorrow at 9:00 AM"
#
# => 2013-02-20 09:00:00 -0800
def self.parse_date(date_string)
if date_string.match(/\d{2}T\d{2}/)
return fractional_date(date_st... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | motion/version.rb | Ruby | mit | 189 | master | 238 | # 0.3.8 is the last version without adapters.
# for backward compatibility, users should
# specify that version in their gem command
# or forward port their code to take advantage
# of adapters.
module MotionModel
VERSION = "0.6.2"
end |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | motion/validatable.rb | Ruby | mit | 189 | master | 6,310 | module MotionModel
module Validatable
class ValidationSpecificationError < RuntimeError; end
class RecordInvalid < RuntimeError; end
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def validate(field = nil, validation_type = {})
if field.nil? || fie... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | motion/model/model.rb | Ruby | mit | 189 | master | 25,528 | # MotionModel encapsulates a pattern for synthesizing a model
# out of thin air. The model will have attributes, types,
# finders, ordering, ... the works.
#
# As an example, consider:
#
# class Task
# include MotionModel
#
# columns :task_name => :string,
# :details => :string,
# ... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | motion/model/transaction.rb | Ruby | mit | 189 | master | 1,047 | module MotionModel
module Model
module Transactions
def transaction(&block)
if block_given?
@savepoints = [] if @savepoints.nil?
@savepoints.push self.duplicate
yield
@savepoints.pop
else
raise ArgumentError.new("transaction must have a block... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | motion/model/column.rb | Ruby | mit | 189 | master | 2,338 | module MotionModel
module Model
class Column
attr_reader :name
attr_reader :owner
attr_reader :type
attr_reader :options
OPTION_ATTRS = [:as, :conditions, :default, :dependent, :foreign_key, :inverse_of, :joined_class_name,
:polymorphic, :symbolize, :through]
OPTION... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | motion/model/model_casts.rb | Ruby | mit | 189 | master | 2,951 | module MotionModel
class Model
def cast_to_bool(arg)
case arg
when NilClass then false
when TrueClass, FalseClass then arg
when Integer then arg != 0
when String then (arg =~ /^true/i) != nil
else raise ArgumentError.new("type #{column_name} : #{column_type(column_nam... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | motion/model/formotion.rb | Ruby | mit | 189 | master | 5,766 | module MotionModel
module Formotion
def self.included(base)
base.extend(PublicClassMethods)
end
module PublicClassMethods
def has_formotion_sections(sections = {})
define_method( "formotion_sections") do
sections
end
end
end
FORMOTION_MAP = {
:stri... |
github | sxross/MotionModel | https://github.com/sxross/MotionModel | motion/adapters/array_finder_query.rb | Ruby | mit | 189 | master | 7,115 | module MotionModel
class ArrayFinderQuery
attr_accessor :field_name
def initialize(*args)#nodoc
@field_name = args[0] if args.length > 1
@collection = args.last
end
def belongs_to(obj, klass = nil) #nodoc
@related_object = obj
@klass = klass
self
end
#... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.