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 | t6d/smart_properties | https://github.com/t6d/smart_properties | spec/writable_spec.rb | Ruby | mit | 180 | master | 1,291 | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe SmartProperties, 'writable properties' do
context 'when a property is defined as not writable there should be no accessor for the property' do
subject(:klass) { DummyClass.new { property :id, writable: false } }
it "should throw a no method... |
github | t6d/smart_properties | https://github.com/t6d/smart_properties | spec/spec_helper.rb | Ruby | mit | 180 | master | 3,644 | require 'bundler/setup'
require 'rspec'
require 'pry'
require 'smart_properties'
Dir[File.join(File.dirname(__FILE__), 'support', '**', '*.rb')].each { |f| require f }
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
# rspec-expectations config goes here. You can use a... |
github | t6d/smart_properties | https://github.com/t6d/smart_properties | spec/validations/ancestor_validation_spec.rb | Ruby | mit | 180 | master | 2,141 | # frozen_string_literal: true
require 'spec_helper'
require 'smart_properties/validations/ancestor'
RSpec.describe SmartProperties::Validations::Ancestor, 'validates ancestor' do
context 'used to validate the ancestor of a smart_properties value' do
let!(:test_base) do
Class.new do
def self.to_s
... |
github | t6d/smart_properties | https://github.com/t6d/smart_properties | spec/support/smart_property_matcher.rb | Ruby | mit | 180 | master | 1,600 | module Matchers
class SmartPropertyMatcher
attr_reader :property_name
attr_reader :subject
def initialize(property_name)
@property_name = property_name
end
def matches?(subject)
@subject = subject.is_a?(Class) ? subject : subject.class
smart_property_enabled? && is_smart_proper... |
github | t6d/smart_properties | https://github.com/t6d/smart_properties | spec/support/dummy_class.rb | Ruby | mit | 180 | master | 268 | class << (DummyClass = BasicObject.new)
def new(superclass = ::Object, class_name = 'Dummy', &block)
c = ::Class.new(superclass) { include ::SmartProperties }
c.define_singleton_method(:name) { class_name }
c.class_eval(&block) if block
c
end
end |
github | t6d/smart_properties | https://github.com/t6d/smart_properties | lib/smart_properties.rb | Ruby | mit | 180 | master | 6,730 | ##
# {SmartProperties} can be used to easily build more full-fledged accessors
# for standard Ruby classes. In contrast to regular accessors,
# {SmartProperties} support validation and conversion of input data, as well
# as, the specification of default values. Additionally, individual
# {SmartProperties} can be marked... |
github | t6d/smart_properties | https://github.com/t6d/smart_properties | lib/smart_properties/property_collection.rb | Ruby | mit | 180 | master | 1,807 | module SmartProperties
class PropertyCollection
include Enumerable
attr_reader :parent
def self.for(scope)
parents = scope.ancestors[1..-1].select do |ancestor|
ancestor.ancestors.include?(SmartProperties) &&
ancestor != scope &&
ancestor != SmartProperties
end
... |
github | t6d/smart_properties | https://github.com/t6d/smart_properties | lib/smart_properties/errors.rb | Ruby | mit | 180 | master | 2,738 | module SmartProperties
class Error < ::ArgumentError; end
class ConfigurationError < Error; end
class AssignmentError < Error
attr_accessor :sender
attr_accessor :property
def initialize(sender, property, message)
@sender = sender
@property = property
super(message)
end
end
... |
github | t6d/smart_properties | https://github.com/t6d/smart_properties | lib/smart_properties/property.rb | Ruby | mit | 180 | master | 4,929 | module SmartProperties
class Property
MODULE_REFERENCE = :"@_smart_properties_method_scope"
ALLOWED_DEFAULT_CLASSES = [Proc, Numeric, String, Range, TrueClass, FalseClass, NilClass, Symbol, Module].freeze
attr_reader :name
attr_reader :converter
attr_reader :accepter
attr_reader :reader
a... |
github | t6d/smart_properties | https://github.com/t6d/smart_properties | lib/smart_properties/validations/ancestor.rb | Ruby | mit | 180 | master | 517 | # frozen_string_literal: true
module SmartProperties
module Validations
class Ancestor
include SmartProperties
property! :type, accepts: ->(type) { type.is_a?(Class) }
def validate(klass)
klass.is_a?(Class) && klass < type
end
def to_proc
validator = self
-... |
github | thetron/mongoid_token | https://github.com/thetron/mongoid_token | mongoid_token.gemspec | Ruby | mit | 180 | master | 979 | # -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "version"
Gem::Specification.new do |s|
s.name = "mongoid_token"
s.version = MongoidToken::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Nicholas Bruning"]
s.email = ["nicholas@bruning.com.au"]
s... |
github | thetron/mongoid_token | https://github.com/thetron/mongoid_token | benchmarks/benchmark.rb | Ruby | mit | 180 | master | 1,101 | $: << File.expand_path("../../lib", __FILE__)
require 'database_cleaner'
require 'mongoid'
require 'mongoid_token'
require 'benchmark'
Mongoid.configure do |config|
config.connect_to("mongoid_token_benchmark")
end
DatabaseCleaner.strategy = :truncation
# start benchmarks
TOKEN_LENGTH = 8
class Link
include Mo... |
github | thetron/mongoid_token | https://github.com/thetron/mongoid_token | lib/mongoid/token.rb | Ruby | mit | 180 | master | 2,431 | require 'mongoid/token/exceptions'
require 'mongoid/token/options'
require 'mongoid/token/generator'
require 'mongoid/token/finders'
require 'mongoid/token/collision_resolver'
module Mongoid
module Token
extend ActiveSupport::Concern
module ClassMethods
def initialize_copy(source)
super(source... |
github | thetron/mongoid_token | https://github.com/thetron/mongoid_token | lib/mongoid/token/collisions.rb | Ruby | mit | 180 | master | 1,116 | module Mongoid
module Token
module Collisions
def resolve_token_collisions(resolver)
retries = resolver.retry_count
begin
yield
rescue Mongo::Error::OperationFailure => e
if is_duplicate_token_error?(e, self, resolver.field_name)
if (retries -= 1) >= 0... |
github | thetron/mongoid_token | https://github.com/thetron/mongoid_token | lib/mongoid/token/exceptions.rb | Ruby | mit | 180 | master | 389 | module Mongoid
module Token
class Error < StandardError; end
class CollisionRetriesExceeded < Error
def initialize(resource = "unknown resource", attempts = "unspecified")
@resource = resource
@attempts = attempts
end
def to_s
"Failed to generate unique token for #{... |
github | thetron/mongoid_token | https://github.com/thetron/mongoid_token | lib/mongoid/token/finders.rb | Ruby | mit | 180 | master | 398 | module Mongoid
module Token
module Finders
def self.define_custom_token_finder_for(klass, field_name = :token)
klass.define_singleton_method(:"find_by_#{field_name}") do |token|
if token.is_a?(Array)
self.in field_name.to_sym => token
else
self.find_by fie... |
github | thetron/mongoid_token | https://github.com/thetron/mongoid_token | lib/mongoid/token/options.rb | Ruby | mit | 180 | master | 1,701 | class Mongoid::Token::Options
def initialize(options = {})
@options = merge_defaults validate_options(options)
end
def length
@options[:length]
end
def retry_count
@options[:retry_count]
end
def contains
@options[:contains]
end
def field_name
!@options[:id] && @options[:field_n... |
github | thetron/mongoid_token | https://github.com/thetron/mongoid_token | lib/mongoid/token/collision_resolver.rb | Ruby | mit | 180 | master | 1,182 | require 'mongoid/token/collisions'
module Mongoid
module Token
class CollisionResolver
attr_accessor :create_new_token
attr_reader :klass
attr_reader :field_name
attr_reader :retry_count
def initialize(klass, field_name, retry_count)
@create_new_token = Proc.new {|doc|}
... |
github | thetron/mongoid_token | https://github.com/thetron/mongoid_token | lib/mongoid/token/generator.rb | Ruby | mit | 180 | master | 2,195 | # proposed pattern options
# %c - lowercase character
# %C - uppercase character
# %d - digit
# %D - non-zero digit / no-leading zero digit if longer than 1
# %s - alphanumeric character
# %w - upper and lower alpha character
# %p - URL-safe punctuation
#
# Any pattern can be followed by a number, representing how many... |
github | thetron/mongoid_token | https://github.com/thetron/mongoid_token | spec/spec_helper.rb | Ruby | mit | 180 | master | 586 | require "codeclimate-test-reporter"
CodeClimate::TestReporter.start
$: << File.expand_path("../../lib", __FILE__)
require 'database_cleaner'
require 'mongoid'
require 'mongoid-rspec'
require 'mongoid_token'
ENV['MONGOID_ENV'] = "test"
RSpec.configure do |config|
Mongo::Logger.logger.level = Logger::ERROR
confi... |
github | thetron/mongoid_token | https://github.com/thetron/mongoid_token | spec/mongoid/token_spec.rb | Ruby | mit | 180 | master | 10,152 | require File.join(File.dirname(__FILE__), %w[.. spec_helper])
describe Mongoid::Token do
after do
Object.send(:remove_const, :Document) if Object.constants.include?(:Document)
Object.send(:remove_const, :AnotherDocument) if Object.constants.include?(:AnotherDocument)
Object.send(:remove_const, :Untainted... |
github | thetron/mongoid_token | https://github.com/thetron/mongoid_token | spec/mongoid/token/finders_spec.rb | Ruby | mit | 180 | master | 1,225 | require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
describe Mongoid::Token::Finders do
after do
Object.send(:remove_const, :Document) if Object.constants.include?(:Document)
Object.send(:remove_const, :AnotherDocument) if Object.constants.include?(:AnotherDocument)
end
it "define a finder ... |
github | thetron/mongoid_token | https://github.com/thetron/mongoid_token | spec/mongoid/token/collisions_spec.rb | Ruby | mit | 180 | master | 3,664 | require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
describe Mongoid::Token::Collisions do
let(:document) { Object.new }
describe "#resolve_token_collisions" do
context "when there is a duplicate token" do
let(:resolver) { double("Mongoid::Token::CollisionResolver") }
before(:each) do... |
github | thetron/mongoid_token | https://github.com/thetron/mongoid_token | spec/mongoid/token/options_spec.rb | Ruby | mit | 180 | master | 2,729 | require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
describe Mongoid::Token::Options do
before do
@options = Mongoid::Token::Options.new(
{
:length => 9999,
:retry_count => 8888,
:contains => :nonsense,
:field_name => :not_a_token
}
)
end
it "shou... |
github | thetron/mongoid_token | https://github.com/thetron/mongoid_token | spec/mongoid/token/generator_spec.rb | Ruby | mit | 180 | master | 1,975 | require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
describe Mongoid::Token::Generator do
describe "#generate" do
it "generates lowercase characters" do
100.times{ Mongoid::Token::Generator.generate("%c").should =~ /[a-z]/ }
end
it "generates uppercase characters" do
100.times{ ... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | pgvector.gemspec | Ruby | mit | 180 | master | 507 | require_relative "lib/pgvector/version"
Gem::Specification.new do |spec|
spec.name = "pgvector"
spec.version = Pgvector::VERSION
spec.summary = "pgvector support for Ruby"
spec.homepage = "https://github.com/pgvector/pgvector-ruby"
spec.license = "MIT"
spec.author = ... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | examples/cohere/example.rb | Ruby | mit | 180 | master | 1,336 | require "json"
require "net/http"
require "pg"
conn = PG.connect(dbname: "pgvector_example")
conn.exec("CREATE EXTENSION IF NOT EXISTS vector")
conn.exec("DROP TABLE IF EXISTS documents")
conn.exec("CREATE TABLE documents (id bigserial PRIMARY KEY, content text, embedding bit(1536))")
# https://docs.cohere.com/refer... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | examples/openai/example_sequel.rb | Ruby | mit | 180 | master | 1,336 | require "json"
require "net/http"
require "pgvector"
require "sequel"
DB = Sequel.connect("postgres://localhost/pgvector_example")
DB.run "CREATE EXTENSION IF NOT EXISTS vector"
DB.drop_table? :documents
DB.create_table :documents do
primary_key :id
text :content
column :embedding, "vector(1536)"
end
class Do... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | examples/openai/example.rb | Ruby | mit | 180 | master | 1,305 | require "json"
require "net/http"
require "pg"
require "pgvector"
conn = PG.connect(dbname: "pgvector_example")
conn.exec("CREATE EXTENSION IF NOT EXISTS vector")
conn.exec("DROP TABLE IF EXISTS documents")
conn.exec("CREATE TABLE documents (id bigserial PRIMARY KEY, content text, embedding vector(1536))")
# https:/... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | examples/informers/example.rb | Ruby | mit | 180 | master | 877 | require "informers"
require "pg"
require "pgvector"
conn = PG.connect(dbname: "pgvector_example")
conn.exec("CREATE EXTENSION IF NOT EXISTS vector")
conn.exec("DROP TABLE IF EXISTS documents")
conn.exec("CREATE TABLE documents (id bigserial PRIMARY KEY, content text, embedding vector(384))")
model = Informers.pipeli... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | examples/rdkit/example.rb | Ruby | mit | 180 | master | 841 | require "pg"
require "rdkit-rb"
def generate_fingerprint(molecule)
RDKit::Molecule.from_smiles(molecule).morgan_fingerprint
end
conn = PG.connect(dbname: "pgvector_example")
conn.exec("CREATE EXTENSION IF NOT EXISTS vector")
conn.exec("DROP TABLE IF EXISTS molecules")
conn.exec("CREATE TABLE molecules (id text PRI... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | examples/sparse/example.rb | Ruby | mit | 180 | master | 1,795 | # good resources
# https://opensearch.org/blog/improving-document-retrieval-with-sparse-semantic-encoders/
# https://huggingface.co/opensearch-project/opensearch-neural-sparse-encoding-v1
require "pg"
require "pgvector"
require "transformers-rb"
conn = PG.connect(dbname: "pgvector_example")
conn.exec("CREATE EXTENSIO... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | examples/loading/example.rb | Ruby | mit | 180 | master | 1,206 | require "numo/narray/alt"
require "pg"
require "pgvector"
# generate random data
rows = 1000000
dimensions = 128
embeddings = Numo::SFloat.new(rows, dimensions).rand
# enable extension
conn = PG.connect(dbname: "pgvector_example")
conn.exec("CREATE EXTENSION IF NOT EXISTS vector")
# create table
conn.exec("DROP TABL... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | examples/hybrid/example.rb | Ruby | mit | 180 | master | 1,713 | require "informers"
require "pg"
require "pgvector"
conn = PG.connect(dbname: "pgvector_example")
conn.exec("CREATE EXTENSION IF NOT EXISTS vector")
conn.exec("DROP TABLE IF EXISTS documents")
conn.exec("CREATE TABLE documents (id bigserial PRIMARY KEY, content text, embedding vector(384))")
conn.exec("CREATE INDEX O... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | examples/citus/example.rb | Ruby | mit | 180 | master | 1,920 | require "numo/narray/alt"
require "pg"
require "pgvector"
# generate random data
rows = 1000000
dimensions = 128
embeddings = Numo::SFloat.new(rows, dimensions).rand
categories = Numo::Int64.new(rows, dimensions).rand(100)
queries = Numo::SFloat.new(10, dimensions).rand
# enable extensions
conn = PG.connect(dbname: "... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | examples/disco/item_recs.rb | Ruby | mit | 180 | master | 740 | require "disco"
require "pgvector"
require "sequel"
DB = Sequel.connect("postgres://localhost/pgvector_example")
DB.run "CREATE EXTENSION IF NOT EXISTS vector"
DB.drop_table? :movies
DB.create_table :movies do
primary_key :id
text :name
column :factors, "vector(20)"
end
class Movie < Sequel::Model
plugin :p... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | examples/disco/user_recs.rb | Ruby | mit | 180 | master | 1,177 | require "disco"
require "pgvector"
require "sequel"
DB = Sequel.connect("postgres://localhost/pgvector_example")
DB.run "CREATE EXTENSION IF NOT EXISTS vector"
DB.drop_table? :movies
DB.create_table :movies do
primary_key :id
text :name
column :factors, "vector(20)"
end
DB.drop_table? :users
DB.create_table :... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | examples/tomoto/example.rb | Ruby | mit | 180 | master | 1,119 | require "pg"
require "pgvector"
require "tomoto"
conn = PG.connect(dbname: "pgvector_example")
conn.exec("CREATE EXTENSION IF NOT EXISTS vector")
conn.exec("DROP TABLE IF EXISTS documents")
conn.exec("CREATE TABLE documents (id bigserial PRIMARY KEY, content text, embedding vector(20))")
def generate_embeddings(inpu... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | lib/pgvector.rb | Ruby | mit | 180 | master | 605 | # modules
require_relative "pgvector/bit"
require_relative "pgvector/half_vector"
require_relative "pgvector/sparse_vector"
require_relative "pgvector/vector"
require_relative "pgvector/version"
module Pgvector
autoload :PG, "pgvector/pg"
def self.encode(data)
if data.is_a?(Vector) || data.is_a?(HalfVector) |... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | lib/pgvector/pg.rb | Ruby | mit | 180 | master | 3,439 | require "pg"
module Pgvector
module PG
def self.register_vector(registry)
registry.register_type(0, "vector", TextEncoder::Vector, TextDecoder::Vector)
registry.register_type(1, "vector", BinaryEncoder::Vector, BinaryDecoder::Vector)
# no binary decoder for halfvec since unpack does not have d... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | lib/pgvector/half_vector.rb | Ruby | mit | 180 | master | 304 | module Pgvector
class HalfVector
def initialize(data)
@data = data.to_a.map(&:to_f)
end
def self.from_text(string)
new(string[1..-2].split(",").map(&:to_f))
end
def to_s
"[#{@data.to_a.map(&:to_f).join(",")}]"
end
def to_a
@data
end
end
end |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | lib/pgvector/bit.rb | Ruby | mit | 180 | master | 544 | module Pgvector
class Bit
def initialize(data)
if data.is_a?(Array)
@data = data.map { |v| v ? "1" : "0" }.join
else
@data = data.to_str
end
end
def self.from_text(string)
Bit.new(string)
end
def self.from_binary(string)
length, data = string.unpack(... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | lib/pgvector/vector.rb | Ruby | mit | 180 | master | 1,025 | module Pgvector
class Vector
def initialize(data)
# keep as NArray when possible for performance
@data =
if numo?(data)
data.cast_to(Numo::SFloat)
else
data.to_a.map(&:to_f)
end
end
def self.from_text(string)
Vector.new(string[1..-2].split(","... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | lib/pgvector/sparse_vector.rb | Ruby | mit | 180 | master | 2,431 | module Pgvector
class SparseVector
attr_reader :dimensions, :indices, :values
NO_DEFAULT = Object.new
def initialize(value, dimensions = NO_DEFAULT)
if value.is_a?(Hash)
if dimensions == NO_DEFAULT
raise ArgumentError, "missing dimensions"
end
from_hash(value, dim... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | lib/sequel/plugins/pgvector.rb | Ruby | mit | 180 | master | 2,496 | module Sequel
module Plugins
module Pgvector
def self.configure(model, *columns)
model.vector_columns ||= {}
columns.each do |column|
model.vector_columns[column.to_sym] = {}
end
end
module DatasetMethods
def nearest_neighbors(column, value, distance:)
... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | test/pgvector_test.rb | Ruby | mit | 180 | master | 762 | require_relative "test_helper"
class PgvectorTest < Minitest::Test
def test_encode_array
assert_equal "[1.0,2.0,3.0]", Pgvector.encode([1, 2, 3])
end
def test_encode_vector
assert_equal "[1.0,2.0,3.0]", Pgvector.encode(Pgvector::Vector.new([1, 2, 3]))
end
def test_encode_half_vector
assert_equa... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | test/half_vector_test.rb | Ruby | mit | 180 | master | 291 | require_relative "test_helper"
class HalfVectorTest < Minitest::Test
def test_to_s
vec = Pgvector::HalfVector.new([1, 2, 3])
assert_equal "[1.0,2.0,3.0]", vec.to_s
end
def test_to_a
vec = Pgvector::HalfVector.new([1, 2, 3])
assert_equal [1, 2, 3], vec.to_a
end
end |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | test/sequel_test.rb | Ruby | mit | 180 | master | 7,053 | require_relative "test_helper"
adapter = RUBY_ENGINE == "jruby" ? "jdbc:postgresql" : "postgres"
DB = Sequel.connect("#{adapter}://localhost/pgvector_ruby_test")
if ENV["VERBOSE"]
require "logger"
DB.loggers << Logger.new($stdout, formatter: ->(_, _, _, msg) { "#{msg}\n" })
end
DB.run("CREATE EXTENSION IF NOT E... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | test/sparse_vector_test.rb | Ruby | mit | 180 | master | 1,244 | require_relative "test_helper"
class SparseVectorTest < Minitest::Test
def test_hash
vec = Pgvector::SparseVector.new({2 => 2, 4 => 3, 0 => 1, 3 => 0}, 6)
assert_equal [1, 0, 2, 0, 3, 0], vec.to_a
assert_equal [0, 2, 4], vec.indices
end
def test_hash_no_dimensions
error = assert_raises(ArgumentE... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | test/vector_test.rb | Ruby | mit | 180 | master | 567 | require_relative "test_helper"
class VectorTest < Minitest::Test
def test_to_s
vec = Pgvector::Vector.new([1, 2, 3])
assert_equal "[1.0,2.0,3.0]", vec.to_s
end
def test_to_a
vec = Pgvector::Vector.new([1, 2, 3])
assert_equal [1, 2, 3], vec.to_a
end
def test_numo
skip if ["jruby", "truff... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | test/pg_test.rb | Ruby | mit | 180 | master | 6,224 | require_relative "test_helper"
class PgTest < Minitest::Test
def setup
skip if RUBY_ENGINE == "jruby"
conn.exec("DELETE FROM pg_items")
end
def test_vector_text
embedding = [1.5, 2, 3]
conn.exec_params("INSERT INTO pg_items (embedding) VALUES ($1), (NULL)", [embedding])
res = conn.exec("SE... |
github | pgvector/pgvector-ruby | https://github.com/pgvector/pgvector-ruby | test/bit_test.rb | Ruby | mit | 180 | master | 290 | require_relative "test_helper"
class BitTest < Minitest::Test
def test_to_s
vec = Pgvector::Bit.new([true, false, true])
assert_equal "101", vec.to_s
end
def test_to_a
vec = Pgvector::Bit.new([true, false, true])
assert_equal [true, false, true], vec.to_a
end
end |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | fitgem.gemspec | Ruby | mit | 180 | master | 989 | # -*- encoding: utf-8 -*-
$:.push File.expand_path('../lib', __FILE__)
$:.push File.join(File.dirname(__FILE__), '.', 'lib')
require 'fitgem/version'
Gem::Specification.new do |s|
s.name = 'fitgem'
s.version = Fitgem::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ['Zachery Moneypenny'... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | Guardfile | Ruby | mit | 180 | master | 655 | # A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'rspec', :cli => "--color --format Fuubar --fail-fast", :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
wat... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | Rakefile | Ruby | mit | 180 | master | 307 | require 'bundler'
require 'rspec/core/rake_task'
Bundler::GemHelper.install_tasks
desc 'Default: run specs.'
task :default => :spec
desc "Run specs"
RSpec::Core::RakeTask.new do |t|
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
# Put spec opts in a file named .rspec in root
end |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | spec/fitgem_notifications_spec.rb | Ruby | mit | 180 | master | 7,504 | require 'spec_helper'
require 'ostruct'
describe Fitgem::Client do
before(:each) do
@client = Fitgem::Client.new({:consumer_key => '12345', :consumer_secret => '56789'})
end
describe "#subscriptions" do
before(:each) do
allow(@client).to receive(:get)
end
it "calls #make_headers to create... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | spec/fitgem_body_measurements_spec.rb | Ruby | mit | 180 | master | 2,007 | require 'spec_helper'
describe Fitgem::Client do
before(:each) do
@client = Fitgem::Client.new({
:consumer_key => '12345',
:consumer_secret => '67890'
})
end
describe "#body_weight" do
it "formats the correct URI based on a date" do
expect(@client).to receive(:get).with("/user/-/bo... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | spec/fitgem_helper_spec.rb | Ruby | mit | 180 | master | 9,959 | require 'spec_helper'
describe Fitgem::Client do
before(:each) do
@client = Fitgem::Client.new({
:consumer_key => '12345',
:consumer_secret => '67890'
})
end
describe "#construct_date_range_fragment" do
it 'should format the correct URI fragment based on a base date and end date' do
... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | spec/fitgem_constructor_spec.rb | Ruby | mit | 180 | master | 574 | require 'spec_helper'
describe Fitgem::Client do
describe "constructor" do
it "requires consumer_key" do
expect {
opts = { :consumer_secret => "12345" }
client = Fitgem::Client.new(opts)
}.to raise_error(Fitgem::InvalidArgumentError, "Missing required options: consumer_key")
end
... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | spec/fitgem_client_spec.rb | Ruby | mit | 180 | master | 1,307 | require 'spec_helper'
RSpec.describe Fitgem::Client do
let(:access_token) {
double 'Access Token', :get => response, :request => response
}
let(:client) { Fitgem::Client.new({
:consumer_key => '12345',
:consumer_secret => '67890'
}) }
let(:response) { double :body => {:foo => :bar}.to_j... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | spec/fitgem_spec.rb | Ruby | mit | 180 | master | 1,975 | require 'spec_helper'
describe Fitgem do
before do
@client = Fitgem::Client.new({
:consumer_key => '12345',
:consumer_secret => '67890'
})
end
describe 'global settings' do
it 'should expose the api_version' do
expect(@client.api_version).to eq "1"
end
it 'should all clien... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | spec/fitgem_activities_spec.rb | Ruby | mit | 180 | master | 5,522 | require 'spec_helper'
describe Fitgem::Client do
before do
@client = Fitgem::Client.new({
:consumer_key => '12345',
:consumer_secret => '67890'
})
end
describe '#create_or_update_daily_goal' do
before(:each) do
@opts = {type: :steps, value: '10000'}
end
it 'raises an excep... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | lib/fitgem/body_measurements.rb | Ruby | mit | 180 | master | 8,915 | module Fitgem
class Client
# ==========================================
# Body Measurements Methods
# ==========================================
# Get the body measurements logged on a specified date
#
# @param [DateTime, String] date The date to retrieve body
# measurements for. ... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | lib/fitgem/devices.rb | Ruby | mit | 180 | master | 835 | module Fitgem
class Client
# ==========================================
# Device Retrieval Methods
# ==========================================
# Get a list of devices for the current account
#
# @return [Array] An array of hashes, each of which describes
# a device attaached t... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | lib/fitgem/units.rb | Ruby | mit | 180 | master | 1,745 | module Fitgem
# Enumeration of valid unit systems that can be sent to fitbit
#
# Set the {Fitgem::Client#api_unit_system} property to one of
# these values to set the unit system used for all subsequent
# API calls.
#
# See {https://wiki.fitbit.com/display/API/API-Unit-System} for
# more information on ... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | lib/fitgem/foods.rb | Ruby | mit | 180 | master | 5,769 | module Fitgem
class Client
# ==========================================
# Food Retrieval Methods
# ==========================================
# Get all foods logged on the supplied date
#
# @param [DateTime, Date, String] date
# @return [Array] A list of the foods, each of which ... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | lib/fitgem/glucose.rb | Ruby | mit | 180 | master | 1,919 | module Fitgem
class Client
# ==========================================
# Glucose Retrieval Methods
# ==========================================
# Get glucose log entries for the supplied date
#
# @param [DateTime, Date, String] date
# @return [Hash] Hash containing an average of th... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | lib/fitgem/notifications.rb | Ruby | mit | 180 | master | 5,004 | module Fitgem
class Client
SUBSCRIBABLE_TYPES = [:sleep, :body, :activities, :foods, :all]
# Get a list of all subscriptions
#
# @param [Hash] opts Subscription query data
# @option opts [Integer, String] :type The type of subscription (valid
# values are :activities, :foods, :sleep, :body,... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | lib/fitgem/helpers.rb | Ruby | mit | 180 | master | 8,604 | module Fitgem
class Client
# Format any of a variety of date types into the formatted string
# required when using the fitbit API.
#
# The date parameter can take several different kind of objects: a
# DateTime object, a Date object, a Time object or a String object. Furthermore,
# the string... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | lib/fitgem/water.rb | Ruby | mit | 180 | master | 1,688 | module Fitgem
class Client
# ==========================================
# Water Retrieval Methods
# ==========================================
# Get water log entries for the supplied date
#
# @param [DateTime, Date, String] date
# @return [Hash] Hash containing the summary of th... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | lib/fitgem/alarms.rb | Ruby | mit | 180 | master | 2,877 | module Fitgem
class Client
# Add a silent alarm to your profile
#
# @param [Hash] opts Alarm options
# @option opts [Integer, String] device_id The id of the device you would like
# to manage the alarm on
# @option opts [String] :time Time of the alarm in the format XX:XX+XX:XX, time
# ... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | lib/fitgem/friends.rb | Ruby | mit | 180 | master | 3,047 | module Fitgem
class Client
# ==========================================
# Friend Retrieval Methods
# ==========================================
# Get a list of the current user's friends
#
# @return [Array] List of friends, each of which is a Hash
# containing friend informatio... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | lib/fitgem/blood_pressure.rb | Ruby | mit | 180 | master | 1,883 | module Fitgem
class Client
# ==========================================
# Blood Pressure Retrieval Methods
# ==========================================
# Get blood pressure log entries for the supplied date
#
# @param [DateTime, Date, String] date
# @return [Hash] Hash containing an... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | lib/fitgem/client.rb | Ruby | mit | 180 | master | 5,920 | require 'fitgem/version'
require 'fitgem/helpers'
require 'fitgem/errors'
require 'fitgem/users'
require 'fitgem/activities'
require 'fitgem/sleep'
require 'fitgem/water'
require 'fitgem/blood_pressure'
require 'fitgem/glucose'
require 'fitgem/heart_rate'
require 'fitgem/units'
require 'fitgem/foods'
require 'fitgem/fr... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | lib/fitgem/activities.rb | Ruby | mit | 180 | master | 11,012 | module Fitgem
class Client
# ==========================================
# Activity Retrieval Methods
# ==========================================
# Get a list of all activities
#
# The returned list includes all public activities plus any
# activities that the current user created... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | lib/fitgem/food_form.rb | Ruby | mit | 180 | master | 307 | module Fitgem
# Enumeration of food form types
#
# Primarily used in calls to {#create_food}.
class FoodFormType
# Food in liquid form
# @return [String]
def self.LIQUID
"LIQUID"
end
# Food in dry form
# @return [String]
def self.DRY
"DRY"
end
end
end |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | lib/fitgem/time_range.rb | Ruby | mit | 180 | master | 3,040 | module Fitgem
class Client
# Gets historical resource data in the time range specified by
# options hash param. The time range can either be specified by
# :base_date and :end_date OR by using :base_date and a :period
# (supported periods are 1d, 7d, 30d, 1w, 1m, 3m, 6m, 1y, max)
#
# Suppor... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | lib/fitgem/badges.rb | Ruby | mit | 180 | master | 207 | module Fitgem
class Client
# Get a list of all badges earned
#
# @return [Hash] Hash containing an array of badges
def badges
get("/user/#{@user_id}/badges.json")
end
end
end |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | lib/fitgem/users.rb | Ruby | mit | 180 | master | 2,379 | module Fitgem
class Client
# Get information aobut current user
#
# @param [Hash] opts User information request data
# @return [Hash] User information
def user_info(opts={})
get("/user/#{@user_id}/profile.json", opts)
end
# Update profile information for current user
#
# @pa... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | lib/fitgem/locales.rb | Ruby | mit | 180 | master | 1,108 | module Fitgem
# Enumeration of valid locales that can be sent to fitbit
#
# Set the {Fitgem::Client#api_locale} property to one of
# these values to set the locale used for all subsequent
# API calls.
#
# See {https://wiki.fitbit.com/display/API/API+Localization} for
# more information on how the variou... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | lib/fitgem/heart_rate.rb | Ruby | mit | 180 | master | 1,959 | module Fitgem
class Client
# ==========================================
# Heart Rate Retrieval Methods
# ==========================================
# Get heart rate log entries for the supplied date
#
# @param [DateTime, Date, String] date
# @return [Hash] Hash containing an average... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | lib/fitgem/sleep.rb | Ruby | mit | 180 | master | 1,600 | module Fitgem
class Client
# ==========================================
# Sleep Retrieval Methods
# ==========================================
# Get sleep data for specified date
#
# @param [DateTime, Date, String] date
# @return [Array] List of sleep items for the supplied date
... |
github | whazzmaster/fitgem | https://github.com/whazzmaster/fitgem | lib/fitgem/errors.rb | Ruby | mit | 180 | master | 544 | module Fitgem
class InvalidArgumentError < ArgumentError
end
class UserIdError < Exception
end
class InvalidDateArgument < InvalidArgumentError
end
class InvalidTimeArgument < InvalidArgumentError
end
class InvalidTimeRange < InvalidArgumentError
end
class InvalidUnitSystem < InvalidArgumentE... |
github | ko1/yomikomu | https://github.com/ko1/yomikomu | yomikomu.gemspec | Ruby | mit | 180 | master | 1,050 | # coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'yomikomu/version'
Gem::Specification.new do |spec|
spec.name = "yomikomu"
spec.version = Yomikomu::VERSION
spec.authors = ["Koichi Sasada"]
spec.email = ["ko1... |
github | ko1/yomikomu | https://github.com/ko1/yomikomu | lib/yomikomu.rb | Ruby | mit | 180 | master | 9,370 | # frozen_string_literal: true
require "yomikomu/version"
module Yomikomu
STATISTICS = Hash.new(0)
def self.prefix
unless yomu_dir = ENV['YOMIKOMU_STORAGE_DIR']
yomu_dir = File.expand_path("~/.ruby_binaries")
end
Dir.mkdir(yomu_dir) unless File.exist?(yomu_dir)
"#{yomu_dir}/cb."
end
YOMI... |
github | ko1/yomikomu | https://github.com/ko1/yomikomu | test/test_helper.rb | Ruby | mit | 180 | master | 227 | $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'tmpdir'
tmpdir = Dir.mktmpdir('yomikomu')
ENV['YOMIKOMU_STORAGE_DIR'] = tmpdir
ENV['YOMIKOMU_STORAGE'] = 'fs2'
require 'yomikomu'
require 'minitest/autorun' |
github | ko1/yomikomu | https://github.com/ko1/yomikomu | test/yomikomu_test.rb | Ruby | mit | 180 | master | 1,261 | require 'test_helper'
class YomikomuTest < Minitest::Test
def test_that_it_has_a_version_number
refute_nil ::Yomikomu::VERSION
end
def test_compile_file
assert_equal 0, ::Yomikomu::STATISTICS[:loaded]
assert_equal 0, ::Yomikomu::STATISTICS[:compiled]
ignored = ::Yomikomu::STATISTICS[:ignored]
... |
github | middleman/middleman-syntax | https://github.com/middleman/middleman-syntax | Rakefile | Ruby | mit | 180 | master | 498 | require 'bundler/gem_tasks'
require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
exempt_tags = ["--tags 'not @wip'"]
exempt_tags << "--tags 'not @nojava'" if RUBY_PLATFORM == "java"
t.cucumber_opts = "--require features --color #{exempt_tags.join(' ')} --strict... |
github | middleman/middleman-syntax | https://github.com/middleman/middleman-syntax | Gemfile | Ruby | mit | 180 | master | 426 | source "https://rubygems.org"
gem "middleman-core", git: "https://github.com/middleman/middleman.git"
# Specify your gem's dependencies in middleman-syntax.gemspec
gemspec
# Build and doc tools
gem 'rake', '~> 13.1', require: false
gem 'yard', '~> 0.9', require: false
# Test tools
gem 'aruba'
gem 'cucumber'
gem 'ca... |
github | middleman/middleman-syntax | https://github.com/middleman/middleman-syntax | middleman-syntax.gemspec | Ruby | mit | 180 | master | 706 | require "./lib/middleman-syntax/version"
Gem::Specification.new do |s|
s.name = "middleman-syntax"
s.version = Middleman::Syntax::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Ben Hollis"]
s.email = ["ben@benhollis.net"]
s.homepage = "https://github.com/middleman/middleman-syntax"
s.summary = %q... |
github | middleman/middleman-syntax | https://github.com/middleman/middleman-syntax | features/support/env.rb | Ruby | mit | 180 | master | 223 | PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
ENV['TEST'] = 'true'
require "middleman-core"
require "middleman-core/step_definitions"
require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-syntax') |
github | middleman/middleman-syntax | https://github.com/middleman/middleman-syntax | features/support/step_definitions.rb | Ruby | mit | 180 | master | 495 | # step definition for testing line number markup
Then(/^I should not see line numbers markup$/) do
expect(page).not_to have_selector("pre.lineno")
end
# step definition for testing that specific content is not present
Then(/^I should not see "([^"]*)"$/) do |content|
expect(page.body).not_to include(content)
end
... |
github | middleman/middleman-syntax | https://github.com/middleman/middleman-syntax | lib/middleman-syntax/language_parameter_parser.rb | Ruby | mit | 180 | master | 634 | module Middleman
module Syntax
module LanguageParameterParser
def self.parse_parameter_from_language(language = "")
language, params = language.to_s.split("?", 2)
if params and params.to_s.include? "="
attribute, value = params.to_s.split("=")
# if there are more argument... |
github | middleman/middleman-syntax | https://github.com/middleman/middleman-syntax | lib/middleman-syntax/highlighter.rb | Ruby | mit | 180 | master | 706 | require 'middleman-syntax/formatters'
module Middleman
module Syntax
module Highlighter
mattr_accessor :options
# A helper module for highlighting code
def self.highlight(code, language=nil, opts={})
highlighter_options = options.to_h.merge(opts)
lexer_options = highlighter_opt... |
github | middleman/middleman-syntax | https://github.com/middleman/middleman-syntax | lib/middleman-syntax/extension.rb | Ruby | mit | 180 | master | 2,954 | require 'rouge'
require 'middleman-syntax/highlighter'
require 'middleman-syntax/redcarpet_code_renderer'
require 'middleman-syntax/haml_monkey_patch'
require 'middleman-syntax/language_parameter_parser.rb'
module Middleman
module Syntax
class SyntaxExtension < Extension
option :css_class, 'highlight', 'Cl... |
github | middleman/middleman-syntax | https://github.com/middleman/middleman-syntax | lib/middleman-syntax/formatters.rb | Ruby | mit | 180 | master | 1,379 | module Middleman
module Syntax
module Formatters
class HTML < Rouge::Formatter
tag 'html'
def initialize(opts={})
@formatter = if opts[:inline_theme]
Rouge::Formatters::HTMLInline.new(opts[:inline_theme])
else
... |
github | middleman/middleman-syntax | https://github.com/middleman/middleman-syntax | lib/middleman-syntax/haml_monkey_patch.rb | Ruby | mit | 180 | master | 1,028 | # If Haml is around, define a :code filter that can be used to more conveniently output highlighted code.
if defined? Haml
module HamlMonkeyPatch
def render(code)
code = code.rstrip
code = code.encode(Encoding::UTF_8)
# Allow language to be specified via a special comment like:
# # lang:... |
github | middleman/middleman-syntax | https://github.com/middleman/middleman-syntax | lib/middleman-syntax/redcarpet_code_renderer.rb | Ruby | mit | 180 | master | 439 | require 'middleman-syntax/language_parameter_parser.rb'
module Middleman
module Syntax
# A mixin for the Redcarpet Markdown renderer that will highlight
# code.
module RedcarpetCodeRenderer
def block_code(code, language)
opts = Middleman::Syntax::LanguageParameterParser.parse_parameter_from... |
github | amatsuda/nested_scaffold | https://github.com/amatsuda/nested_scaffold | nested_scaffold.gemspec | Ruby | mit | 180 | master | 986 | # coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
Gem::Specification.new do |spec|
spec.name = "nested_scaffold"
spec.version = '1.1.0'
spec.authors = ["Akira Matsuda"]
spec.email = ["ronnie@dio.jp"]
spec.summary ... |
github | amatsuda/nested_scaffold | https://github.com/amatsuda/nested_scaffold | Rakefile | Ruby | mit | 180 | master | 245 | require "bundler/gem_tasks"
require "rake/testtask"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList['test/**/*_test.rb'].reject {|f| f.start_with?('test/dummy/test') }
end
task :default => :test |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.