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 | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | Rakefile | Ruby | mit | 46 | master | 698 | require 'rake'
require 'fileutils'
def gemspec_name
@gemspec_name ||= Dir['*.gemspec'][0]
end
def gemspec
@gemspec ||= eval(File.read(gemspec_name), binding, gemspec_name)
end
desc "Build the gem"
task :gem=>:gemspec do
sh "gem build #{gemspec_name}"
FileUtils.mkdir_p 'pkg'
FileUtils.mv "#{gemspec.name}-#{... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | polymorpheus.gemspec | Ruby | mit | 46 | master | 945 | # -*- encoding: utf-8 -*-
require 'rubygems' unless defined? Gem
require File.dirname(__FILE__) + "/lib/polymorpheus/version"
Gem::Specification.new do |s|
s.name = "polymorpheus"
s.version = Polymorpheus::VERSION
s.authors = ["Barun Singh"]
s.email = "bsingh@wegowise.com"
s.homepage ... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | lib/polymorpheus.rb | Ruby | mit | 46 | master | 953 | module Polymorpheus
autoload :Adapter, 'polymorpheus/adapter'
autoload :Interface, 'polymorpheus/interface'
autoload :InterfaceBuilder, 'polymorpheus/interface_builder'
autoload :Trigger, 'polymorpheus/trigger'
autoload :SchemaDumper, 'polymorpheus/schema_dumper'
module Interface
autoload :BelongsToPol... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | lib/polymorpheus/interface.rb | Ruby | mit | 46 | master | 630 | module Polymorpheus
module Interface
class PolymorphicError < ::StandardError; end
class InvalidTypeError < PolymorphicError
def initialize(*accepted_classes)
error = "Invalid type."
error += " Must be one of {#{accepted_classes.join(', ')}}"
super(error)
end
end
... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | lib/polymorpheus/railtie.rb | Ruby | mit | 46 | master | 593 | # Thanks to matthuhiggins/foreigner gem for the template used here
module Polymorpheus
class Railtie < Rails::Railtie
initializer 'polymorpheus.load_adapter' do
ActiveSupport.on_load :active_record do
ActiveRecord::Base.send :include, Polymorpheus::Interface
ActiveRecord::ConnectionAdapte... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | lib/polymorpheus/trigger.rb | Ruby | mit | 46 | master | 981 | module Polymorpheus
class Trigger
attr_accessor :name, :event, :table, :statement, :timing, :created, :sql_mode,
:definer, :charset, :collation_connection, :db_collation
def initialize(arr)
raise ArgumentError unless arr.is_a?(Array) && arr.length == 11
[:name, :event, :table, ... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | lib/polymorpheus/adapter.rb | Ruby | mit | 46 | master | 617 | module Polymorpheus
class Adapter
class << self
@@registered_adapters = {}
def register(adapter_name, file_name)
@@registered_adapters[adapter_name] = file_name
end
def load!
if file = @@registered_adapters[configured_adapter]
require file
end
end... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | lib/polymorpheus/schema_dumper.rb | Ruby | mit | 46 | master | 499 | module Polymorpheus
module SchemaDumper
extend ActiveSupport::Concern
included do
alias_method :tables_without_triggers, :tables
alias_method :tables, :tables_with_triggers
end
def tables_with_triggers(stream)
tables_without_triggers(stream)
if @connection.respond_to?(:trigg... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | lib/polymorpheus/schema_statements.rb | Ruby | mit | 46 | master | 373 | module Polymorpheus
module ConnectionAdapters
module SchemaStatements
def self.included(base)
base::AbstractAdapter.class_eval do
include Polymorpheus::ConnectionAdapters::AbstractAdapter
end
end
end
module AbstractAdapter
def add_polymorphic_constraints(table,... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | lib/polymorpheus/mysql_adapter.rb | Ruby | mit | 46 | master | 6,965 | module Polymorpheus
module ConnectionAdapters
module MysqlAdapter
INSERT = 'INSERT'
UPDATE = 'UPDATE'
# See the README for more information about the use of these methods.
#
# table: a string equal to the name of the db table
#
# columns: a hash, with keys equal to ... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | lib/polymorpheus/interface_builder.rb | Ruby | mit | 46 | master | 2,981 | require 'ostruct'
module Polymorpheus
class InterfaceBuilder
attr_reader :interface_name,
:associations
def initialize(interface_name, association_names, options)
@interface_name = interface_name
@associations = association_names.map do |association_name|
Polymorpheus::I... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | lib/polymorpheus/interface/validates_polymorph.rb | Ruby | mit | 46 | master | 463 | module Polymorpheus
module Interface
module ValidatesPolymorph
def validates_polymorph(polymorphic_api)
validate Proc.new {
unless polymorpheus.active_association
association_names = polymorpheus.associations.map(&:name)
errors.add(:base, "You must specify exactly o... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | lib/polymorpheus/interface/has_many_as_polymorph.rb | Ruby | mit | 46 | master | 868 | module Polymorpheus
module Interface
module HasManyAsPolymorph
def has_many_as_polymorph(association, scope = nil, options = {})
if scope.instance_of?(Hash)
options = scope
scope = nil
end
options.symbolize_keys!
fkey = name.foreign_key
class_nam... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | lib/polymorpheus/interface/belongs_to_polymorphic.rb | Ruby | mit | 46 | master | 1,567 | module Polymorpheus
module Interface
module BelongsToPolymorphic
def belongs_to_polymorphic(*association_names, options)
polymorphic_api = options.delete(:as)
builder = Polymorpheus::InterfaceBuilder.new(polymorphic_api,
association_names,... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | lib/polymorpheus/interface_builder/association.rb | Ruby | mit | 46 | master | 580 | module Polymorpheus
class InterfaceBuilder
class Association
include ActiveSupport::Inflector
attr_reader :name,
:key,
:options
def initialize(name, options)
@name, @options = name.to_s.downcase, options
@key = "#{@name}_id"
end
... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | spec/mysql2_adapter_spec.rb | Ruby | mit | 46 | master | 9,076 | require 'spec_helper'
describe Polymorpheus::ConnectionAdapters::MysqlAdapter do
# The foreign key name is not truncated, so the maximum column name
# length ends up being: 64 - "pets_" - "_fk" == 56
#
# Using `t.references` also adds an index on this column, with a slightly
# longer name: 64 - "index_pets_... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | spec/schema_dumper_spec.rb | Ruby | mit | 46 | master | 1,025 | require 'spec_helper'
describe Polymorpheus::SchemaDumper do
let(:connection) { ActiveRecord::Base.connection }
let(:stream) { StringIO.new }
before do
create_table :story_arcs do |t|
t.references :hero
t.references :villain
end
create_table :heros
create_table :villains
ActiveRe... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | spec/interface_spec.rb | Ruby | mit | 46 | master | 1,055 | require 'spec_helper'
describe Polymorpheus::Interface do
describe 'association options' do
it 'without options' do
create_table :drawings
create_table :books
create_table :binders
expect(Drawing.new.association(:book).reflection.inverse_of).to eq(nil)
expect(Drawing.new.associatio... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | spec/trigger_spec.rb | Ruby | mit | 46 | master | 1,631 | require 'spec_helper'
describe Polymorpheus::Trigger do
let(:name) { "pets_unique_polyfk_on_INSERT" }
let(:event) { "INSERT" }
let(:table) { "pets"}
let(:statement) do
%{BEGIN
IF(IF(NEW.dog_id IS NULL, 0, 1) + IF(NEW.kitty_id IS NULL, 0, 1)) <> 1 THEN
SET NEW = 'Error';
END IF;
... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | spec/spec_helper.rb | Ruby | mit | 46 | master | 975 | require 'active_record'
require 'polymorpheus'
require 'stringio'
ActiveRecord::Base.establish_connection(
adapter: 'mysql2',
database: ENV.fetch('DB_NAME', 'polymorpheus_test'),
host: ENV.fetch('DB_HOST', '127.0.0.1'),
password: ENV.fetch('DB_PASSWORD', ''),
port: ENV.fetch('DB_PORT', '3306'),
username: E... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | spec/support/connection_helpers.rb | Ruby | mit | 46 | master | 276 | module ConnectionHelpers
def add_polymorphic_constraints(*args)
connection.add_polymorphic_constraints(*args)
end
def remove_polymorphic_constraints(*args)
connection.remove_polymorphic_constraints(*args)
end
def triggers
connection.triggers
end
end |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | spec/support/sql_test_helpers.rb | Ruby | mit | 46 | master | 937 | module SqlTestHelpers
extend ActiveSupport::Concern
included do
before do
ActiveSupport::Notifications.subscribe('sql.active_record', sql_logger)
end
after do
ActiveSupport::Notifications.unsubscribe(sql_logger)
end
let(:connection) { ActiveRecord::Base.connection }
let(:sql_l... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | spec/support/class_defs.rb | Ruby | mit | 46 | master | 2,172 | # this is normally done via a Railtie in non-testing situations
ActiveRecord::Base.send :include, Polymorpheus::Interface
# Han Solo is a hero, but not a superhero
class Hero < ActiveRecord::Base
has_many_as_polymorph :story_arcs
has_many :battles, through: :story_arcs
end
# Hannibal Lecter is a villain, but not ... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | spec/support/sql_query_subscriber.rb | Ruby | mit | 46 | master | 305 | module Polymorpheus
class SqlQuerySubscriber
attr_reader :sql_statements
def initialize
@sql_statements = []
end
def call(_name, _start, _finish, _id, payload)
sql_statements << payload[:sql]
end
def clear_sql_history
@sql_statements.clear
end
end
end |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | spec/support/custom_matchers.rb | Ruby | mit | 46 | master | 796 | RSpec::Matchers.define :be_association do |association_name|
match do |actual|
expect(actual).to be_instance_of Polymorpheus::InterfaceBuilder::Association
expect(actual.name).to eq association_name.to_s
end
end
RSpec::Matchers.define :match_associations do |*association_names|
match do |actual|
expe... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | spec/support/schema_helpers.rb | Ruby | mit | 46 | master | 387 | module SchemaHelpers
def create_table(name, options = {})
options.merge!(force: true)
ActiveRecord::Schema.define do
create_table(name, **options) do |t|
yield(t) if block_given?
end
end
name.to_s.classify.constantize.reset_column_information
end
def drop_table(name)
Activ... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | spec/interface/validates_polymorph_spec.rb | Ruby | mit | 46 | master | 1,227 | require 'spec_helper'
describe Polymorpheus::Interface::ValidatesPolymorph do
let(:hero) { Hero.create! }
let(:villain) { Villain.create! }
before do
create_table(:story_arcs) do |t|
t.references :hero
t.references :villain
end
create_table(:heros)
create_table(:villains)
end
sp... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | spec/interface/belongs_to_polymorphic_spec.rb | Ruby | mit | 46 | master | 5,008 | require 'spec_helper'
describe Polymorpheus::Interface::BelongsToPolymorphic do
let(:hero) { Hero.create! }
let(:villain) { Villain.create! }
let(:superhero) { Superhero.create! }
let(:alien_demigod) { AlienDemigod.create! }
before do
create_table :story_arcs do |t|
t.references :hero
t.refe... |
github | wegowise/polymorpheus | https://github.com/wegowise/polymorpheus | spec/interface/has_many_as_polymorph_spec.rb | Ruby | mit | 46 | master | 2,901 | require 'spec_helper'
describe Polymorpheus::Interface::HasManyAsPolymorph do
before do
create_table :story_arcs do |t|
t.references :hero
t.references :villain
t.references :battle
t.references :issue
end
create_table :battles
create_table :heros
create_table :issues
... |
github | djberg96/sys-cpu | https://github.com/djberg96/sys-cpu | Rakefile | Ruby | apache-2.0 | 46 | main | 1,288 | require 'rake'
require 'rake/clean'
require 'rbconfig'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
include RbConfig
CLEAN.include('**/*.gem', '**/*.rbc', '**/*.rbx', '**/*.lock')
namespace 'gem' do
desc "Create the sys-cpu gem"
task :create => [:clean] do
require 'rubygems/package'
spec = G... |
github | djberg96/sys-cpu | https://github.com/djberg96/sys-cpu | sys-cpu.gemspec | Ruby | apache-2.0 | 46 | main | 1,955 | require 'rubygems'
Gem::Specification.new do |spec|
spec.name = 'sys-cpu'
spec.version = '1.3.0'
spec.author = 'Daniel J. Berger'
spec.email = 'djberg96@gmail.com'
spec.license = 'Apache-2.0'
spec.homepage = 'https://github.com/djberg96/sys-cpu'
spec.summary = 'A Ruby interface ... |
github | djberg96/sys-cpu | https://github.com/djberg96/sys-cpu | install.rb | Ruby | apache-2.0 | 46 | main | 2,398 | #######################################################################
# install.rb
#
# For pure Ruby versions only. Generally speaking this script should
# not be run directly. Use the 'rake install' task instead.
#######################################################################
require 'rbconfig'
require 'file... |
github | djberg96/sys-cpu | https://github.com/djberg96/sys-cpu | examples/example_sys_cpu_windows.rb | Ruby | apache-2.0 | 46 | main | 656 | #######################################################################
# example_sys_cpu_windows.rb
#
# Sample cript for general futzing. You can run this code via the
# 'rake example' task.
#
# Modify as you see fit.
#######################################################################
require 'sys/cpu'
require 'pp... |
github | djberg96/sys-cpu | https://github.com/djberg96/sys-cpu | examples/example_sys_cpu_bsd.rb | Ruby | apache-2.0 | 46 | main | 613 | #######################################################################
# example_sys_cpu_bsd.rb
#
# Sample cript for general futzing. You can run this code via the
# 'rake example' task.
#
# Modify as you see fit.
#######################################################################
require "sys/cpu"
include Sys
pu... |
github | djberg96/sys-cpu | https://github.com/djberg96/sys-cpu | examples/example_sys_cpu_linux.rb | Ruby | apache-2.0 | 46 | main | 561 | #######################################################################
# example_sys_cpu_linux.rb
#
# Sample cript for general futzing. You should run this code via the
# 'rake example' task.
#
# Modify as you see fit.
#######################################################################
require "sys/cpu"
require "p... |
github | djberg96/sys-cpu | https://github.com/djberg96/sys-cpu | examples/example_sys_cpu_hpux.rb | Ruby | apache-2.0 | 46 | main | 741 | #######################################################################
# example_sys_cpu_hpux.rb
#
# Sample cript for general futzing. You can run this code via the
# 'rake example' task.
#
# Modify as you see fit.
#######################################################################
require "sys/cpu"
include Sys
p... |
github | djberg96/sys-cpu | https://github.com/djberg96/sys-cpu | lib/sys/cpu.rb | Ruby | apache-2.0 | 46 | main | 767 | # frozen_string_literal: true
# This is just a stub file that requires the appropriate version
# depending on which platform you're on.
require 'rbconfig'
# The Sys module is a namespace only.
module Sys
# The CPU class encapsulates information about the physical cpu's on your system.
# This class is reopened for... |
github | djberg96/sys-cpu | https://github.com/djberg96/sys-cpu | lib/sys/linux/sys/cpu.rb | Ruby | apache-2.0 | 46 | main | 6,984 | # frozen_string_literal: true
##########################################################
# linux.rb (sys-cpu) - pure Ruby version for Linux
##########################################################
# The Sys module is a namespace only.
module Sys
# :stopdoc:
cpu_file = '/proc/cpuinfo'
cpu_hash = {}
# rub... |
github | djberg96/sys-cpu | https://github.com/djberg96/sys-cpu | lib/sys/windows/sys/cpu.rb | Ruby | apache-2.0 | 46 | main | 24,147 | # frozen_string_literal: true
require 'win32ole'
require 'socket'
# The Sys module serves only as a namespace
module Sys
# Encapsulates system CPU information
class CPU
# Error raised if any of the Sys::CPU methods fail.
class Error < StandardError; end
# Base connect string
BASE_CS = 'winmgmts:{... |
github | djberg96/sys-cpu | https://github.com/djberg96/sys-cpu | lib/sys/unix/sys/cpu.rb | Ruby | apache-2.0 | 46 | main | 11,295 | # frozen_string_literal: true
require 'ffi'
require 'rbconfig'
# The Sys module is a name space only.
module Sys
# The CPU class encapsulates information about the physical CPU's on your system.
class CPU
extend FFI::Library
ffi_lib FFI::Library::LIBC
# Error raised if any of the CPU methods fail.
... |
github | djberg96/sys-cpu | https://github.com/djberg96/sys-cpu | lib/sys/darwin/sys/cpu.rb | Ruby | apache-2.0 | 46 | main | 9,307 | # frozen_string_literal: true
require 'ffi'
require 'rbconfig'
# The Sys module serves as a namespace only.
module Sys
# The CPU class encapsulates information about the physical cpu's on your system.
class CPU
extend FFI::Library
ffi_lib FFI::Library::LIBC
# Error raised if any of the CPU methods fa... |
github | djberg96/sys-cpu | https://github.com/djberg96/sys-cpu | spec/sys_cpu_windows_spec.rb | Ruby | apache-2.0 | 46 | main | 3,273 | # frozen_string_literal: true
######################################################################
# sys_cpu_windows_spec.rb
#
# Test suite for MS Windows systems. This should be run via the
# 'rake test' task.
######################################################################
require 'spec_helper'
require 'sys/... |
github | djberg96/sys-cpu | https://github.com/djberg96/sys-cpu | spec/sys_cpu_shared.rb | Ruby | apache-2.0 | 46 | main | 660 | # frozen_string_literal: true
#######################################################################
# sys_cpu_spec.rb
#
# Only shared specs go here. Everything else goes into its own tagged
# spec file.
#######################################################################
require 'sys/cpu'
require 'rspec'
RSpec.s... |
github | djberg96/sys-cpu | https://github.com/djberg96/sys-cpu | spec/sys_cpu_linux_spec.rb | Ruby | apache-2.0 | 46 | main | 2,562 | # frozen_string_literal: true
###########################################################
# sys_cpu_linux_spec.rb
#
# Specs for sys-cpu for Linux. This should be run via
# the 'rake spec' task.
###########################################################
require 'sys/cpu'
require 'spec_helper'
RSpec.describe Sys::CPU,... |
github | djberg96/sys-cpu | https://github.com/djberg96/sys-cpu | spec/spec_helper.rb | Ruby | apache-2.0 | 46 | main | 509 | # frozen_string_literal: true
require 'rspec'
require 'sys_cpu_shared'
RSpec.configure do |config|
config.include_context(Sys::CPU)
config.filter_run_excluding(:bsd) if RbConfig::CONFIG['host_os'] !~ /bsd|darwin|mach|osx|dragonfly/i
config.filter_run_excluding(:windows) if RbConfig::CONFIG['host_os'] !~ /mswin|... |
github | djberg96/sys-cpu | https://github.com/djberg96/sys-cpu | spec/sys_cpu_hpux_spec.rb | Ruby | apache-2.0 | 46 | main | 2,807 | # frozen_string_literal: true
#####################################################################
# sys_cpu_hpux_spec.rb
#
# Test suite for the HP-UX platform. This should be run via the
# 'rake test' task.
#####################################################################
require 'sys/cpu'
require 'spec_helper'
... |
github | djberg96/sys-cpu | https://github.com/djberg96/sys-cpu | spec/sys_cpu_bsd_spec.rb | Ruby | apache-2.0 | 46 | main | 4,865 | # frozen_string_literal: true
#############################################################
# sys_cpu_bsd_spec.rb
#
# Specs for sys-cpu on BSD flavors, including OS X.
#############################################################
require 'sys/cpu'
require 'spec_helper'
RSpec.describe Sys::CPU, :bsd do
example 'arch... |
github | agardiner/csv-diff | https://github.com/agardiner/csv-diff | csv-diff.gemspec | Ruby | bsd-2-clause | 46 | master | 2,304 | GEMSPEC = Gem::Specification.new do |s|
s.name = "csv-diff"
s.version = "0.6.1"
s.authors = ["Adam Gardiner"]
s.date = "2020-10-21"
s.summary = "CSV Diff is a library for generating diffs from data in CSV or XML format"
s.description = <<-EOQ
This library performs diffs of CSV data, or a... |
github | agardiner/csv-diff | https://github.com/agardiner/csv-diff | lib/csv-diff/source.rb | Ruby | bsd-2-clause | 46 | master | 12,350 | class CSVDiff
# Reppresents an input (i.e the left/from or tight/to input) to the diff
# process.
class Source
# @return [String] the path to the source file
attr_accessor :path
# @return [Array<Arrary>] The data for this source
attr_reader :data
# @return [Array<S... |
github | agardiner/csv-diff | https://github.com/agardiner/csv-diff | lib/csv-diff/xml_source.rb | Ruby | bsd-2-clause | 46 | master | 6,577 | require 'nokogiri'
require 'cgi'
class CSVDiff
# Convert XML content to CSV format using XPath selectors to identify the
# rows and field values in an XML document
class XMLSource < Source
attr_accessor :context
# Create a new XMLSource, identified by +path+. Normally this is a path
... |
github | agardiner/csv-diff | https://github.com/agardiner/csv-diff | lib/csv-diff/algorithm.rb | Ruby | bsd-2-clause | 46 | master | 9,391 | class CSVDiff
# Implements the CSV diff algorithm.
module Algorithm
# Holds the details of a single difference
class Diff
attr_accessor :diff_type
attr_reader :fields
attr_reader :row
attr_reader :sibling_position
def initialize(dif... |
github | agardiner/csv-diff | https://github.com/agardiner/csv-diff | lib/csv-diff/csv_diff.rb | Ruby | bsd-2-clause | 46 | master | 7,004 | # This library performs diffs of flat file content that contains structured data
# in fields, with rows provided in a parent-child format.
#
# Parent-child data does not lend itself well to standard text diffs, as small
# changes in the organisation of the tree at an upper level (e.g. re-ordering of
# two ancestor node... |
github | agardiner/csv-diff | https://github.com/agardiner/csv-diff | lib/csv-diff/csv_source.rb | Ruby | bsd-2-clause | 46 | master | 3,816 | class CSVDiff
# Represents a CSV input (i.e. the left/from or right/to input) to the diff
# process.
class CSVSource < Source
# Creates a new diff source.
#
# A diff source must contain at least one field that will be used as the
# key to identify the same record in a diffe... |
github | agardiner/csv-diff | https://github.com/agardiner/csv-diff | test/test_diff.rb | Ruby | bsd-2-clause | 46 | master | 2,041 | require 'test/unit'
require 'csv-diff'
require 'pp'
class TestDiff < Test::Unit::TestCase
DATA1 = [
['Parent', 'Child', 'Description'],
['A', 'A1', 'Account1'],
['A', 'A2', 'Account 2'],
['A', 'A3', 'Account 3'],
['A', 'A4', 'Account 4'],
['A', 'A6', 'Account 6']
... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | Gemfile | Ruby | apache-2.0 | 46 | master | 216 | source 'https://rubygems.org'
# Specify your gem's dependencies in truc.gemspec
gemspec
group :test do
gem 'hashery', '~> 2.1.1'
gem "yajl-ruby", require: 'yajl', platforms: [:ruby_19, :ruby_20, :ruby_21]
end |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | prismic.gemspec | Ruby | apache-2.0 | 46 | master | 1,038 | # coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'prismic/version'
Gem::Specification.new do |spec|
spec.name = 'prismic.io'
spec.version = Prismic::VERSION
spec.authors = ["Étienne Vallette d'Osia", 'Erwan Loisant', '... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic.rb | Ruby | apache-2.0 | 46 | master | 20,902 | # encoding: utf-8
require 'cgi'
require 'net/http'
require 'uri'
require 'json' unless defined?(JSON)
require 'prismic/with_fragments'
module Prismic
EXPERIMENTS_COOKIE = 'io.prismic.experiment'
PREVIEW_COOKIE = 'io.prismic.preview'
# These exception can contains an error cause and is able to show them
cl... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/api.rb | Ruby | apache-2.0 | 46 | master | 11,152 | # encoding: utf-8
module Prismic
# The API is the main class
class API
@@warned_create_search_form = false
@@warned_oauth_initiate_url = false
@@warned_oauth_check_token = false
attr_reader :json
# @return [String]
attr_reader :access_token
attr_reader :http_client
# @return [Hash{S... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/predicates.rb | Ruby | apache-2.0 | 46 | master | 3,027 | module Prismic
module Predicates
def self.at(fragment, value)
['at', fragment, value]
end
def self.not(fragment, value)
['not', fragment, value]
end
def self.in(fragment, value)
['in', fragment, value]
end
def self.any(fragment, values)
['any', fragment, values]... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/json_parsers.rb | Ruby | apache-2.0 | 46 | master | 11,793 | # encoding: utf-8
require 'cgi'
require 'time'
module Prismic
module JsonParser
class << self
@@warned_unknown_type = []
def parsers
@parsers ||= {
'Link.document' => method(:document_link_parser),
'Text' => method(:text_parser),
'Link.web' => m... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/fragments.rb | Ruby | apache-2.0 | 46 | master | 677 | # encoding: utf-8
require 'prismic/fragments/fragment'
require 'prismic/fragments/color'
require 'prismic/fragments/date'
require 'prismic/fragments/embed'
require 'prismic/fragments/geopoint'
require 'prismic/fragments/group'
require 'prismic/fragments/image'
require 'prismic/fragments/link'
require 'prismic/fragments... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/experiments.rb | Ruby | apache-2.0 | 46 | master | 2,150 | # encoding: utf-8
module Prismic
class Experiments
# @return [Array<Experiment>] list of all experiments from Prismic
attr_reader :draft
# @return [Array<Experiments>] list of all experiments from Prismic
attr_reader :running
def initialize(draft, running)
@draft = draft
@running = r... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/with_fragments.rb | Ruby | apache-2.0 | 46 | master | 5,435 | # encoding: utf-8
module Prismic
# A document with Fragments: usually a Prismic.io Document, or a Document within a Group
module WithFragments
# @return [Hash{String => Fragment}]
attr_accessor :fragments
# Generate a Text representation of the entire document
#
# @return [String] the text rep... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/form.rb | Ruby | apache-2.0 | 46 | master | 921 | # encoding: utf-8
module Prismic
class Form
attr_accessor :name, :form_method, :rel, :enctype, :action, :fields
def initialize(api, name, fields, form_method, rel, enctype, action)
@api = api
@name = name
@fields = fields
@form_method = form_method
@rel = rel
@enctype = en... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/cache/lru.rb | Ruby | apache-2.0 | 46 | master | 3,061 | # encoding: utf-8
require 'hashery'
module Prismic
# This is a simple cache class provided with the prismic.io Ruby kit.
#
# It is pretty dumb but effective: * everything is stored in memory,
#
# If you need a smarter caching (for instance, rely on memcached), you can
# extend this class and replace its m... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/fragments/image.rb | Ruby | apache-2.0 | 46 | master | 1,503 | # encoding: utf-8
module Prismic
module Fragments
class Image < Fragment
attr_accessor :main, :views
def initialize(main, views)
@main = main
@views = views
end
def as_html(link_resolver=nil)
main.as_html(link_resolver)
end
def as_text
""
... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/fragments/timestamp.rb | Ruby | apache-2.0 | 46 | master | 517 | # encoding: utf-8
module Prismic
module Fragments
class Timestamp < Fragment
attr_accessor :value
def initialize(value)
@value = value
end
# Generate an HTML representation of the fragment
#
# @param link_resolver [LinkResolver] The LinkResolver used to build
# ... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/fragments/boolean_field.rb | Ruby | apache-2.0 | 46 | master | 443 | # encoding: utf-8
module Prismic
module Fragments
class BooleanField < Fragment
attr_accessor :value
def initialize(value)
@value = value
end
def as_html(link_resolver=nil)
if (@value === true)
%(<input type="checkbox" checked="checke... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/fragments/geopoint.rb | Ruby | apache-2.0 | 46 | master | 661 | # encoding: utf-8
module Prismic
module Fragments
class GeoPoint < Fragment
attr_accessor :longitude, :latitude
def initialize(longitude, latitude)
@longitude = longitude
@latitude = latitude
end
# Generate an HTML representation of the fragment
#
# @param lin... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/fragments/slices.rb | Ruby | apache-2.0 | 46 | master | 3,272 | # encoding: utf-8
module Prismic
module Fragments
# A fragment of type CompositeSlice, an item in a SliceZone
class CompositeSlice < Fragment
attr_accessor :slice_type
attr_accessor :slice_label
attr_accessor :non_repeat
attr_accessor :repeat
def initialize(slice_type, slice_la... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/fragments/text.rb | Ruby | apache-2.0 | 46 | master | 341 | # encoding: utf-8
module Prismic
module Fragments
class Text < Fragment
attr_accessor :value
def initialize(value)
@value = value
end
def as_html(link_resolver=nil)
%(<span class="text">#{CGI::escapeHTML(@value)}</span>)
end
def as_text
@value
e... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/fragments/multiple.rb | Ruby | apache-2.0 | 46 | master | 507 | # encoding: utf-8
module Prismic
module Fragments
class Multiple < Fragment
attr_reader :fragments
def initialize(fragments=[])
@fragments = fragments
end
def size
@fragments.size
end
def [](i)
@fragments[i]
end
def push(fragment)
... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/fragments/link.rb | Ruby | apache-2.0 | 46 | master | 3,995 | # encoding: utf-8
module Prismic
module Fragments
class Link < Fragment
def start_html(link_resolver = nil, target = nil)
unless target.nil?
%(<a href="#{url(link_resolver)}" target="#{target}" rel="noopener">)
else
%(<a href="#{url(link_resolver)}">)
end
... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/fragments/select.rb | Ruby | apache-2.0 | 46 | master | 299 | # encoding: utf-8
module Prismic
module Fragments
class Select < Fragment
attr_accessor :value
def initialize(value)
@value = value
end
def as_html(link_resolver=nil)
%(<span class="text">#{CGI::escapeHTML(@value)}</span>)
end
end
end
end |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/fragments/fragment.rb | Ruby | apache-2.0 | 46 | master | 759 | # encoding: utf-8
module Prismic
module Fragments
# Generic fragment, this class is to be extended by all fragment classes.
class Fragment
# Generic as_html method for fragments, meant to be overriden by
# specific fragment classes.
#
# @return [String] an empty string
def as_ht... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/fragments/embed.rb | Ruby | apache-2.0 | 46 | master | 853 | # encoding: utf-8
module Prismic
module Fragments
class Embed < Fragment
attr_accessor :embed_type, :provider, :url, :html, :o_embed_json
def initialize(embed_type, provider, url, html, o_embed_json)
@embed_type = embed_type
@provider = provider
@url = url
... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/fragments/separator.rb | Ruby | apache-2.0 | 46 | master | 318 | # encoding: utf-8
module Prismic
module Fragments
class Separator < Fragment
attr_accessor :value
def initialize(value)
@value = value
end
def as_html(link_resolver=nil)
%(<hr class="separator" />)
end
def as_text
@value
end
end
end
end |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/fragments/group.rb | Ruby | apache-2.0 | 46 | master | 1,924 | # encoding: utf-8
module Prismic
module Fragments
class GroupDocument
include Prismic::WithFragments
attr_accessor :fragments
def initialize(fragments)
@fragments = fragments
end
# Get a document's field
# @return [Fragments::Fragment]
def [](field)
@fr... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/fragments/structured_text.rb | Ruby | apache-2.0 | 46 | master | 12,667 | # encoding: utf-8
module Prismic
module Fragments
class StructuredText < Fragment
# Used during the call of {StructuredText#as_html} : blocks are first gathered by groups,
# so that list items of the same list are placed within the same group, allowing to frame
# their serialization with <ul>..... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/fragments/date.rb | Ruby | apache-2.0 | 46 | master | 512 | # encoding: utf-8
module Prismic
module Fragments
class Date < Fragment
attr_accessor :value
def initialize(value)
@value = value
end
# Generate an HTML representation of the fragment
#
# @param link_resolver [LinkResolver] The LinkResolver used to build
# a... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/fragments/integration_field.rb | Ruby | apache-2.0 | 46 | master | 278 | module Prismic
module Fragments
class IntegrationField < Fragment
attr_accessor :value
def initialize(value)
@value = value
end
def as_json
value.to_json
end
def as_text
value.to_s
end
end
end
end |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/fragments/number.rb | Ruby | apache-2.0 | 46 | master | 332 | # encoding: utf-8
module Prismic
module Fragments
class Number < Fragment
attr_accessor :value
def initialize(value)
@value = value
end
def as_int
@value.to_int
end
def as_html(link_resolver=nil)
%(<span class="number">#@value</span>)
end
en... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | lib/prismic/fragments/color.rb | Ruby | apache-2.0 | 46 | master | 1,023 | # encoding: utf-8
module Prismic
module Fragments
class Color < Fragment
attr_accessor :value
def initialize(value)
@value = value
end
# Returns the RGB values in a Hash
#
# @example
# color.asRGB # => {'red' => 123, 'green' => 123, 'blue' => 123}
#
... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | spec/micro_spec.rb | Ruby | apache-2.0 | 46 | master | 2,178 | # encoding: utf-8
require 'spec_helper'
describe 'micro' do
before do
@api = Prismic.api('https://micro.prismic.io/api', nil)
@master_ref = @api.master_ref
@link_resolver = Prismic.link_resolver('master'){|doc_link| "http://localhost/#{doc_link.id}" }
end
describe 'embed block in structured text fra... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | spec/json_parsers_spec.rb | Ruby | apache-2.0 | 46 | master | 17,993 | # encoding: utf-8
require 'spec_helper'
describe 'document_link_parser' do
before do
raw_json = <<json
{
"type": "Link.document",
"value": {
"document": {
"id": "UdUjvt_mqVNObPeO",
"type": "product",
"tags": ["Macaron"],
"slug": "dar... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | spec/experiments_spec.rb | Ruby | apache-2.0 | 46 | master | 1,588 | # encoding: utf-8
require 'spec_helper'
describe "Experiments'" do
before do
@raw_json_experiments = File.read("#{File.dirname(__FILE__)}/responses_mocks/experiments.json")
@json_experiments = JSON.load(@raw_json_experiments)
@experiments = Prismic::Experiments.parse(@json_experiments)
end
... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | spec/cache_spec.rb | Ruby | apache-2.0 | 46 | master | 5,116 | # encoding: utf-8
require 'spec_helper'
describe "Cache's" do
describe 'on/off switch' do
before do
@api = Prismic.api("https://micro.prismic.io/api", cache: Prismic::LruCache.new(3))
@cache = @api.cache
@master_ref = @api.master
end
it "is properly on" do
@api.has_cache?.should... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | spec/prismic_spec.rb | Ruby | apache-2.0 | 46 | master | 15,423 | # encoding: utf-8
require 'spec_helper'
describe 'Api' do
before do
json_representation = '{"foo": "bar"}'
@oauth_initiate_url = 'https://micro.prismic.io/auth'
@api = Prismic::API.new(json_representation, nil, Prismic::DefaultHTTPClient, false){|api|
api.bookmarks = {}
api.tags = {}
ap... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | spec/spec_helper.rb | Ruby | apache-2.0 | 46 | master | 294 | # encoding: utf-8
require 'nokogiri'
begin
require 'yajl/json_gem'
rescue LoadError
# ok not a big deal
require 'json'
end
RSpec.configure do |c|
# Stop after the first failure
# c.fail_fast = true
end
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
require 'prismic' |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | spec/fragments_spec.rb | Ruby | apache-2.0 | 46 | master | 27,851 | # encoding: utf-8
require 'spec_helper'
def em(start, stop)
Prismic::Fragments::StructuredText::Span::Em.new(start, stop)
end
def strong(start, stop)
Prismic::Fragments::StructuredText::Span::Strong.new(start, stop)
end
describe 'WebLink' do
before do
@web_link = Prismic::Fragments::WebLink.new('my_url')
... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | spec/predicates_spec.rb | Ruby | apache-2.0 | 46 | master | 12,768 | # encoding: utf-8
require 'spec_helper'
Predicates = Prismic::Predicates
describe 'predicates' do
before do
@api = Prismic.api('https://micro.prismic.io/api', nil)
@master_ref = @api.master_ref
@link_resolver = Prismic.link_resolver('master'){|doc_link| "http://localhost/#{doc_link.id}" }
@boolean_a... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | spec/oauth_spec.rb | Ruby | apache-2.0 | 46 | master | 3,949 | # encoding: utf-8
require 'spec_helper'
describe 'OAuth' do
OAUTH_INITIATE_OPTS = {
client_id: "client_id",
redirect_uri: "http://myapp.com/callback",
scope: "master+releases",
}.freeze
OAUTH_CHECKTOKEN_OPTS = {
grant_type: "authorization_code",
code: "thecode",
redirect_uri: "http://my... |
github | prismicio-community/ruby-kit | https://github.com/prismicio-community/ruby-kit | spec/simple_search_spec.rb | Ruby | apache-2.0 | 46 | master | 1,880 | # encoding: utf-8
require 'spec_helper'
describe Prismic::API do
before do
@api = Prismic.api('https://micro.prismic.io/api', nil)
end
describe '#query' do
it 'returns the documents filter by the query' do
docs = @api.query(Prismic::Predicates::at('document.id', 'UrDejAEAAFwMyrW9'))
docs.siz... |
github | marcinruszkiewicz/where_chain | https://github.com/marcinruszkiewicz/where_chain | where_chain.gemspec | Ruby | mit | 46 | master | 1,354 | # frozen_string_literal: true
$LOAD_PATH.push File.expand_path('lib', __dir__)
# Maintain your gem's version:
require 'where_chain/version'
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = 'where_chain'
s.version = WhereChain::VERSION
s.authors = ['Marcin ... |
github | marcinruszkiewicz/where_chain | https://github.com/marcinruszkiewicz/where_chain | Rakefile | Ruby | mit | 46 | master | 421 | # frozen_string_literal: true
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
require 'rdoc/task'
RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'WhereChain'
rdoc.options << '--line-numbers'
rdoc.rdoc_... |
github | marcinruszkiewicz/where_chain | https://github.com/marcinruszkiewicz/where_chain | Appraisals | Ruby | mit | 46 | master | 405 | # frozen_string_literal: true
appraise '5.2' do
gem 'rails', '~> 5.2.0'
gem 'sqlite3', '~> 1.4'
end
appraise '6.0' do
gem 'rails', '~> 6.0.0'
gem 'sqlite3', '~> 1.4'
end
appraise '6.1' do
gem 'rails', '~> 6.1.0'
gem 'sqlite3', '~> 1.4'
end
appraise '7.0' do
gem 'rails', '~> 7.0.0'
gem 'sqlite3', '~>... |
github | marcinruszkiewicz/where_chain | https://github.com/marcinruszkiewicz/where_chain | lib/where_chain.rb | Ruby | mit | 46 | master | 342 | # frozen_string_literal: true
require 'active_record/where_chain_shared_methods'
# Active Record changed a lot in Rails 5 and 4 is still supported
if ActiveRecord::VERSION::MAJOR == 4
require 'active_record/where_chain_extensions_rails4'
elsif ActiveRecord::VERSION::MAJOR >= 5
require 'active_record/where_chain_e... |
github | marcinruszkiewicz/where_chain | https://github.com/marcinruszkiewicz/where_chain | lib/active_record/where_chain_shared_methods.rb | Ruby | mit | 46 | master | 3,741 | # frozen_string_literal: true
module ActiveRecord
module WhereChainSharedMethods
extend ActiveSupport::Concern
included do
# Initialize the chain with a scope and a toggle to invert the generated
# where statement
def initialize(scope, invert = false)
@scope = scope
@invert... |
github | marcinruszkiewicz/where_chain | https://github.com/marcinruszkiewicz/where_chain | lib/active_record/where_chain_extensions_rails5.rb | Ruby | mit | 46 | master | 2,908 | # frozen_string_literal: true
module ActiveRecord
# Ruby complains about missing the class if we try to patch it without it
class Relation
class QueryMethods; end
end
module QueryMethods
class WhereChain
include ActiveModel::ForbiddenAttributesProtection
include WhereChainSharedMethods
... |
github | marcinruszkiewicz/where_chain | https://github.com/marcinruszkiewicz/where_chain | lib/active_record/where_chain_extensions_rails4.rb | Ruby | mit | 46 | master | 1,964 | # frozen_string_literal: true
module ActiveRecord
module QueryMethods
class WhereChain
include WhereChainSharedMethods
# Returns a new relation expressing WHERE + NOT condition
# according to the conditions in the arguments.
#
# User.where.not(name: nil)
# # SELECT * FR... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.