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 | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/common_aggregate_components/postal_address.rb | Ruby | mit | 44 | main | 2,399 | class ZATCA::UBL::CommonAggregateComponents::PostalAddress < ZATCA::UBL::BaseComponent
attr_accessor :street_name,
:additional_street_name,
:building_number,
:plot_identification,
:city_subdivision_name,
:city_name,
:postal_zone,
:country_subentity,
:country
SCHEMA = Dry::Schema.Par... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/common_aggregate_components/tax_total.rb | Ruby | mit | 44 | main | 2,083 | class ZATCA::UBL::CommonAggregateComponents::TaxTotal < ZATCA::UBL::BaseComponent
# <cac:TaxTotal>
# <cbc:TaxAmount currencyID="SAR">144.9</cbc:TaxAmount>
# <cac:TaxSubtotal>
# <cbc:TaxableAmount currencyID="SAR">966.00</cbc:TaxableAmount>
# <cbc:TaxAmount currencyID="SAR">144.90</cbc:TaxAmount>
# ... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/common_aggregate_components/item.rb | Ruby | mit | 44 | main | 493 | class ZATCA::UBL::CommonAggregateComponents::Item < ZATCA::UBL::BaseComponent
attr_reader :scheme_id, :id
def initialize(name:, classified_tax_category: nil)
super()
@name = name
@classified_tax_category = classified_tax_category || ZATCA::UBL::CommonAggregateComponents::ClassifiedTaxCategory.new
en... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/common_aggregate_components/legal_monetary_total.rb | Ruby | mit | 44 | main | 2,430 | class ZATCA::UBL::CommonAggregateComponents::LegalMonetaryTotal < ZATCA::UBL::BaseComponent
attr_reader :line_extension_amount, :tax_exclusive_amount,
:tax_inclusive_amount, :allowance_total_amount, :prepaid_amount,
:payable_amount, :currency_id
# <cac:LegalMonetaryTotal>
# <cbc:LineExtensionAmount cur... |
github | jgaskins/primalize | https://github.com/jgaskins/primalize | primalize.gemspec | Ruby | mit | 44 | master | 938 | lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "primalize/version"
Gem::Specification.new do |spec|
spec.name = "primalize"
spec.version = Primalize::VERSION
spec.authors = ["Jamie Gaskins"]
spec.email = ["jgaskins@gmail.c... |
github | jgaskins/primalize | https://github.com/jgaskins/primalize | spec/spec_helper.rb | Ruby | mit | 44 | master | 365 | require "bundler/setup"
require "primalize"
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!
config.expect_with :r... |
github | jgaskins/primalize | https://github.com/jgaskins/primalize | spec/primalize/single_spec.rb | Ruby | mit | 44 | master | 12,195 | require 'primalize/single'
require 'time'
module Primalize
order_serializer_class = Class.new(Primalize::Single) do
attributes(
price_cents: integer,
payment_method: string,
)
end
serializer_class = Class.new(Primalize::Single) do
attributes(
id: integer,
name: string,
... |
github | jgaskins/primalize | https://github.com/jgaskins/primalize | spec/primalize/pattern_match_spec.rb | Ruby | mit | 44 | master | 1,349 | require 'primalize/single'
require 'securerandom'
require 'ostruct'
module Primalize
matched = true
serializer_class = Class.new(Primalize::Single) do
self.type_mismatch_handler = proc { matched = false }
attributes(
id: match(/\w{8}(-\w{4}){3}-\w{12}/), # UUID
price: match(0..10) { |price| p... |
github | jgaskins/primalize | https://github.com/jgaskins/primalize | spec/primalize/many_spec.rb | Ruby | mit | 44 | master | 4,009 | require 'json'
require 'primalize/many'
require 'primalize/single'
module Primalize
RSpec.describe Many do
let(:user_serializer_class) do
Class.new(Single) do
attributes(
id: integer,
name: string,
)
def self.inspect
'UserSerializer'
end
... |
github | jgaskins/primalize | https://github.com/jgaskins/primalize | lib/primalize/single.rb | Ruby | mit | 44 | master | 8,995 | require 'json'
require 'date'
require 'csv'
module Primalize
class Single
@type_mismatch_handler = proc do |klass, attr, type, value|
raise TypeError, "#{klass}##{attr} is specified as #{type.inspect}, but is #{value.inspect}"
end
class << self
def attributes **attrs
_attributes **at... |
github | jgaskins/primalize | https://github.com/jgaskins/primalize | lib/primalize/many.rb | Ruby | mit | 44 | master | 3,359 | require 'json'
module Primalize
class Many
def self.attributes attrs={}
@attributes ||= {}
add_attributes attrs
@attributes
end
def self.add_attributes attrs
return if attrs.none?
attrs.each do |attr, serializer_class|
if serializer_class.nil?
raise Type... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | Gemfile | Ruby | mit | 44 | master | 427 | source 'https://rubygems.org'
git_source(:github) do |repo_name|
"https://github.com/#{repo_name}.git"
end
gemspec
case ENV["GEMS_SOURCE"]
when "local"
gem "roar", path: "../roar"
when "github"
gem 'roar', github: 'trailblazer/roar'
end
gem 'minitest-line'
gem 'minitest-reporters', '<= 1.3.0' # Note 1.3.1 is b... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | Rakefile | Ruby | mit | 44 | master | 234 | require 'bundler'
Bundler::GemHelper.install_tasks
require 'rake/testtask'
task default: [:test]
Rake::TestTask.new(:test) do |test|
test.libs << 'test'
test.test_files = FileList['test/**/*_test.rb']
test.verbose = true
end |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | roar-jsonapi.gemspec | Ruby | mit | 44 | master | 1,204 | $LOAD_PATH.push File.expand_path('../lib', __FILE__)
require 'roar/json/json_api/version'
Gem::Specification.new do |s|
s.name = 'roar-jsonapi'
s.version = Roar::JSON::JSONAPI::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ['Nick Sutterer', 'Alex Coles']
s.email = ['apotonick@g... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | lib/roar/json/json_api.rb | Ruby | mit | 44 | master | 4,617 | require 'roar/json'
require 'roar/decorator'
require 'set'
require 'roar/json/json_api/member_name'
require 'roar/json/json_api/defaults'
require 'roar/json/json_api/meta'
require 'roar/json/json_api/declarative'
require 'roar/json/json_api/options'
require 'roar/json/json_api/document'
require 'roar/json/json_api/s... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | lib/roar/json/json_api/defaults.rb | Ruby | mit | 44 | master | 626 | module Roar
module JSON
module JSONAPI
# Defines defaults for JSON API Representers.
#
# @api public
module Defaults
# Hook called when module is included
#
# @param [Class,Module] base
# the module or class including Defaults
#
# @return [... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | lib/roar/json/json_api/resource_collection.rb | Ruby | mit | 44 | master | 1,022 | module Roar
module JSON
module JSONAPI
# Instance method API for JSON API Documents representing an array of Resources
#
# @api private
module ResourceCollection
# @see Document#to_hash
def to_hash(options = {})
single_options = options.reject { |key, _| [:meta, ... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | lib/roar/json/json_api/options.rb | Ruby | mit | 44 | master | 3,696 | module Roar
module JSON
module JSONAPI
# @api private
module Options
# Transforms `field:` and `include:`` options to their internal
# equivalents.
#
# @see SingleResource#to_hash
class Include
DEFAULT_INTERNAL_INCLUDES = [:attributes, :relationships].... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | lib/roar/json/json_api/meta.rb | Ruby | mit | 44 | master | 1,553 | module Roar
module JSON
module JSONAPI
# Meta information API for JSON API Representers.
#
# @api public
module Meta
# Hook called when module is included
#
# @param [Class,Module] base
# the module or class including JSONAPI
#
# @return [u... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | lib/roar/json/json_api/document.rb | Ruby | mit | 44 | master | 2,105 | module Roar
module JSON
module JSONAPI
# Instance method API for JSON API Documents.
#
module Document
# Render the document as JSON
#
# @example Simple rendering
# representer.to_json
#
# @example Rendering with compound documents and sparse fie... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | lib/roar/json/json_api/member_name.rb | Ruby | mit | 44 | master | 1,808 | # encoding=utf-8
module Roar
module JSON
module JSONAPI
# Member Name formatting according to the JSON API specification.
#
# @see http://jsonapi.org/format/#document-member-names
# @since 0.1.0
class MemberName
# @api private
LENIENT_FILTER_REGEXP = /([^[:alnum:][-_... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | lib/roar/json/json_api/single_resource.rb | Ruby | mit | 44 | master | 2,280 | module Roar
module JSON
module JSONAPI
# Instance method API for JSON API Documents representing a single Resource
#
# @api private
module SingleResource
# @see Document#to_hash
def to_hash(options = {})
document = super(Options::Include.(options, mappings))
... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | lib/roar/json/json_api/for_collection.rb | Ruby | mit | 44 | master | 537 | module Roar
module JSON
module JSONAPI
# @api private
module ForCollection
def collection_representer!(_options)
singular = self # e.g. Song::Representer
nested_builder.(_base: default_nested_class, _features: [Roar::JSON, Roar::Hypermedia, JSONAPI::Defaults, JSONAPI::Meta... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | lib/roar/json/json_api/declarative.rb | Ruby | mit | 44 | master | 7,819 | module Roar
module JSON
module JSONAPI
# Declarative API for JSON API Representers.
#
# @since 0.1.0
module Declarative
# Defjne a type for this resource.
#
# @example
# type :articles
#
# @param [Symbol, String] name type name of this reso... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | test/test_helper.rb | Ruby | mit | 44 | master | 962 | require 'minitest/autorun'
require 'minitest/reporters'
Minitest::Reporters.use! Minitest::Reporters::DefaultReporter.new
require 'roar/representer'
require 'roar/json'
require 'roar/json/json_api'
require 'representable/debug'
require 'pp'
require_relative 'jsonapi/representer'
require 'json_spec/configuration'
re... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | test/jsonapi/relationship_custom_naming_test.rb | Ruby | mit | 44 | master | 1,600 | require 'test_helper'
class RelationshipCustomNameTest < MiniTest::Spec
class ChefDecorator < Roar::Decorator
include Roar::JSON::JSONAPI.resource :chefs
attributes do
property :name
end
end
class IngredientDecorator < Roar::Decorator
include Roar::JSON::JSONAPI.resource :ingredients
... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | test/jsonapi/post_test.rb | Ruby | mit | 44 | master | 1,777 | require 'test_helper'
require 'roar/json/json_api'
require 'json'
class JsonapiPostTest < MiniTest::Spec
describe 'Parse' do
let(:post_article) {
%({
"data": {
"type": "articles",
"attributes": {
"title": "Ember Hamster"
},
"relationships": {
... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | test/jsonapi/render_test.rb | Ruby | mit | 44 | master | 10,072 | require 'test_helper'
require 'roar/json/json_api'
require 'json'
class JsonapiRenderTest < MiniTest::Spec
let(:article) { Article.new(1, 'Health walk', Author.new(2), Author.new('editor:1'), [Comment.new('comment:1', 'Ice and Snow'), Comment.new('comment:2', 'Red Stripe Skank')], [Author.new('contributor:1'),Author... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | test/jsonapi/fieldsets_options_test.rb | Ruby | mit | 44 | master | 7,116 | require 'test_helper'
require 'roar/json/json_api'
class FieldsetsOptionsTest < Minitest::Spec
Include = Roar::JSON::JSONAPI::Options::Include
describe 'with non-empty :include and non-empty :fields option' do
it 'rewrites :include and parses :fields' do
[{ include: [:articles],
fields: { arti... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | test/jsonapi/fieldsets_test.rb | Ruby | mit | 44 | master | 15,805 | require 'test_helper'
require 'roar/json/json_api'
require 'json'
class JSONAPIFieldsetsTest < Minitest::Spec
Article = Struct.new(:id, :title, :summary, :comments, :author, :slug)
Comment = Struct.new(:id, :body, :good, :comment_author)
Author = Struct.new(:id, :name, :email)
describe 'Single Resource Object... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | test/jsonapi/representer.rb | Ruby | mit | 44 | master | 2,884 | Author = Struct.new(:id, :email, :name) do
def self.find_by(options)
AuthorNine if options[:id].to_s == '9'
end
end
AuthorNine = Author.new(9, '9@nine.to')
Article = Struct.new(:id, :title, :author, :editor, :comments, :contributors) do
def reviewers
['Christian Bernstein']
end
end
Comment = Struct.ne... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | test/jsonapi/collection_render_test.rb | Ruby | mit | 44 | master | 13,198 | require 'test_helper'
require 'roar/json/json_api'
require 'json'
class JsonapiCollectionRenderTest < MiniTest::Spec
let(:article) { Article.new(1, 'Health walk', Author.new(2, 'someone@author.com'), Author.new('editor:1'), [Comment.new('comment:1', 'Ice and Snow'), Comment.new('comment:2', 'Red Stripe Skank')], [Au... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | test/jsonapi/resource_linkage_test.rb | Ruby | mit | 44 | master | 2,497 | # encoding: utf-8
require 'test_helper'
require 'roar/json/json_api'
require 'json'
class ResourceLinkageTest < MiniTest::Spec
class ChefDecorator < Roar::Decorator
include Roar::JSON::JSONAPI.resource :chefs
attributes do
property :name
end
end
class IngredientDecorator < Roar::Decorator
... |
github | trailblazer/roar-jsonapi | https://github.com/trailblazer/roar-jsonapi | test/jsonapi/member_name_test.rb | Ruby | mit | 44 | master | 2,869 | # encoding: utf-8
require 'test_helper'
require 'roar/json/json_api'
require 'json'
require 'jsonapi/representer'
class MemberNameTest < MiniTest::Spec
MemberName = Roar::JSON::JSONAPI::MemberName
# http://jsonapi.org/format/#document-member-names-reserved-characters
UNICODE_RESERVED_CHARACTERS = [
"\u002B... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | Rakefile | Ruby | mit | 44 | master | 335 | require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
task default: [:ci]
desc "Run CI tasks"
task ci: [:spec]
begin
require "rubocop/rake_task"
Rake::Task[:default].enhance [:rubocop]
RuboCop::RakeTask.new do |task|
task.options << "--display-cop-names"
end
rescue... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | rom-repository.gemspec | Ruby | mit | 44 | master | 1,084 | require File.expand_path('../lib/rom/repository/version', __FILE__)
Gem::Specification.new do |gem|
gem.name = 'rom-repository'
gem.summary = 'Repository abstraction for rom-rb'
gem.description = 'rom-repository adds support for auto-mapping and commands on top of rom-rb relations'
gem.author ... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | Gemfile | Ruby | mit | 44 | master | 796 | source 'https://rubygems.org'
gemspec
gem 'inflecto'
group :development do
gem 'dry-equalizer', '~> 0.2'
gem 'sqlite3', platforms: [:mri, :rbx]
gem 'jdbc-sqlite3', platforms: :jruby
end
group :test do
gem 'rom', git: 'https://github.com/rom-rb/rom.git', branch: 'release-3.0'
gem 'rom-sql', git: 'https://g... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | benchmarks/basic.rb | Ruby | mit | 44 | master | 1,440 | require_relative 'setup'
benchmark('creating a user') do |x|
x.report('rom-repository') do
user_repo.create(name: 'Jane', email: 'jane@doe.org', age: 21)
end
x.report('rom-repository with a changeset') do
changeset = user_repo.changeset(name: 'Jane', email: 'jane@doe.org', age: 21)
user_repo.create(... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | benchmarks/seed.rb | Ruby | mit | 44 | master | 680 | USER_SEED = COUNT.times.map { |i|
{ id: i + 1,
name: "User #{i + 1}",
email: "email_#{i}@domain.com",
age: i*10 }
}
TASK_SEED = USER_SEED.map { |user|
3.times.map do |i|
{ user_id: user[:id], title: "Task #{i + 1}" }
end
}.flatten
def seed
hr
puts "SEEDING #{USER_SEED.count} users"
... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | benchmarks/setup.rb | Ruby | mit | 44 | master | 2,369 | require 'bundler'
Bundler.require
require 'benchmark/ips'
require 'rom-sql'
require 'rom-repository'
require 'active_record'
require 'logger'
require 'hotch'
begin; require 'byebug'; rescue LoadError; end
require_relative 'gc_suite'
def benchmark(title)
puts "\n"
puts "=> benchmark: #{title}"
puts "\n"
Ben... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | benchmarks/gc_suite.rb | Ruby | mit | 44 | master | 383 | # Enable and start GC before each job run. Disable GC afterwards.
#
# Inspired by https://www.omniref.com/ruby/2.2.1/symbols/Benchmark/bm?#annotation=4095926&line=182
class GCSuite
def warming(*)
run_gc
end
def running(*)
run_gc
end
def warmup_stats(*)
end
def add_report(*)
end
private
... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | examples/sql.rb | Ruby | mit | 44 | master | 927 | require 'rom-repository'
conf = ROM::Configuration.new(:sql, 'sqlite::memory')
migration = conf.gateways[:default].migration do
change do
create_table(:users) do
primary_key :id
column :name, String, null: false
column :email, String, null: false
end
end
end
migration.apply(conf.gateway... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | examples/upsert.rb | Ruby | mit | 44 | master | 2,261 | require 'rom-repository'
require 'byebug'
conf = ROM::Configuration.new(:sql, 'postgres://localhost/rom_example')
migration = conf.gateways[:default].migration do
change do
create_table?(:books) do
primary_key :id
column :title, String, null: false
end
create_table?(:tags) do
primary_... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/spec_helper.rb | Ruby | mit | 44 | master | 1,718 | # this is needed for guard to work, not sure why :(
require "bundler"
Bundler.setup
if RUBY_ENGINE == 'ruby' && ENV['COVERAGE'] == 'true'
require 'yaml'
rubies = YAML.load(File.read(File.join(__dir__, '..', '.travis.yml')))['rvm']
latest_mri = rubies.select { |v| v =~ /\A\d+\.\d+.\d+\z/ }.max
if RUBY_VERSION ... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/support/mutant.rb | Ruby | mit | 44 | master | 212 | module Mutant
class Selector
# Expression based test selector
class Expression < self
def call(_subject)
integration.all_tests
end
end # Expression
end # Selector
end # Mutant |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/integration/typed_structs_spec.rb | Ruby | mit | 44 | master | 1,674 | RSpec.describe 'ROM repository with typed structs' do
subject(:repo) do
Class.new(ROM::Repository[:books]) { commands :create }.new(rom)
end
include_context 'database'
include_context 'seeds'
context 'typed projections' do
before do
configuration.relation(:books) do
schema(infer: true)... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/integration/changeset_spec.rb | Ruby | mit | 44 | master | 5,907 | RSpec.describe 'Using changesets' do
include_context 'database'
include_context 'relations'
before do
module Test
class User < Dry::Struct
attribute :id, Dry::Types['strict.int']
attribute :name, Dry::Types['strict.string']
end
end
configuration.mappers do
define(:u... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/integration/command_macros_spec.rb | Ruby | mit | 44 | master | 5,428 | RSpec.describe ROM::Repository, '.command' do
include_context 'database'
include_context 'relations'
it 'allows configuring a create command' do
repo = Class.new(ROM::Repository[:users]) do
commands :create
end.new(rom)
user = repo.create(name: 'Jane')
expect(user.id).to_not be(nil)
e... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/integration/command_spec.rb | Ruby | mit | 44 | master | 7,321 | RSpec.describe ROM::Repository, '#command' do
include_context 'database'
include_context 'relations'
include_context 'repo'
context 'accessing custom command from the registry' do
before do
configuration.commands(:users) do
define(:upsert, type: ROM::SQL::Commands::Create)
define(:cre... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/integration/multi_adapter_spec.rb | Ruby | mit | 44 | master | 1,964 | # coding: utf-8
RSpec.describe 'Repository with multi-adapters configuration' do
let(:configuration) {
ROM::Configuration.new(default: [:sql, DB_URI], memory: [:memory])
}
let(:sql_conn) { configuration.gateways[:default].connection }
let(:rom) { ROM.container(configuration) }
let(:users) { rom.relatio... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/integration/repository_spec.rb | Ruby | mit | 44 | master | 13,027 | RSpec.describe 'ROM repository' do
include_context 'database'
include_context 'relations'
include_context 'repo'
include_context 'structs'
include_context 'seeds'
it 'loads a single relation' do
expect(repo.all_users.to_a).to match_array([jane, joe])
end
it 'can be used with a custom mapper' do
... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/integration/root_repository_spec.rb | Ruby | mit | 44 | master | 3,018 | RSpec.describe ROM::Repository::Root do
subject(:repo) do
Class.new(ROM::Repository[:users]) do
relations :tasks, :posts, :labels
end.new(rom)
end
include_context 'database'
include_context 'relations'
describe '.[]' do
it 'creates a pre-configured root repo class' do
klass = ROM::Re... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/integration/repository/aggregate_spec.rb | Ruby | mit | 44 | master | 1,819 | RSpec.describe ROM::Repository::Root, '#aggregate' do
subject(:repo) do
Class.new(ROM::Repository[:users]) do
relations :tasks, :posts, :labels
end.new(rom)
end
include_context 'database'
include_context 'relations'
include_context 'seeds'
it 'loads a graph with aliased children and its pare... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/unit/session_spec.rb | Ruby | mit | 44 | master | 1,289 | RSpec.describe ROM::Session do
subject(:session) do
ROM::Session.new(repo)
end
let(:repo) { instance_double(ROM::Repository) }
let(:create_changeset) { instance_double(ROM::Changeset::Create, relation: relation) }
let(:delete_changeset) { instance_double(ROM::Changeset::Delete, relation: relation) }
le... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/unit/relation_proxy_spec.rb | Ruby | mit | 44 | master | 5,983 | require 'dry-struct'
RSpec.describe 'loading proxy' do
include_context 'database'
include_context 'relations'
include_context 'repo'
include_context 'structs'
include_context 'seeds'
let(:users_proxy) do
repo.users
end
let(:tasks_proxy) do
repo.tasks
end
let(:tags_proxy) do
repo.tags... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/unit/changeset_spec.rb | Ruby | mit | 44 | master | 5,707 | require 'ostruct'
RSpec.describe ROM::Changeset do
let(:jane) { { id: 2, name: "Jane" } }
let(:relation) { double(ROM::Relation, name: :users) }
describe '.[]' do
it 'returns a changeset preconfigured for a specific relation' do
klass = ROM::Changeset::Create[:users]
expect(klass.relation).to b... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/unit/struct_builder_spec.rb | Ruby | mit | 44 | master | 3,518 | RSpec.describe 'struct builder', '#call' do
subject(:builder) { ROM::Repository::StructBuilder.new }
def attr_double(name, type, **opts)
double(
name: name,
aliased?: false,
wrapped?: false,
foreign_key?: false,
to_read_type: ROM::Types.const_get(type),
**opts
)
end
... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/unit/changeset/associate_spec.rb | Ruby | mit | 44 | master | 2,884 | require 'spec_helper'
RSpec.describe ROM::Changeset, '#associate' do
include_context 'database setup'
before do
[:todos, :projects, :people].each { |table| conn.drop_table?(table) }
conn.create_table :people do
primary_key :id
column :name, String
end
conn.create_table :projects do
... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/unit/changeset/map_spec.rb | Ruby | mit | 44 | master | 2,974 | RSpec.describe ROM::Changeset, '.map' do
context 'single mapping with transaction DSL' do
subject(:changeset) do
Class.new(ROM::Changeset::Create[:users]) do
map do
unwrap :address
rename_keys street: :address_street, city: :address_city, country: :address_country
end
... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/unit/repository/session_spec.rb | Ruby | mit | 44 | master | 6,242 | RSpec.describe ROM::Repository, '#session' do
subject(:repo) do
Class.new(ROM::Repository) { relations :users, :posts, :labels }.new(rom)
end
include_context 'database'
include_context 'relations'
describe 'with :create command' do
let(:user_changeset) do
repo.changeset(:users, name: 'Jane')
... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/unit/repository/inspect_spec.rb | Ruby | mit | 44 | master | 346 | RSpec.describe ROM::Repository, '#inspect' do
subject(:repo) do
Class.new(ROM::Repository) do
relations :users
def self.to_s
'UserRepo'
end
end.new(rom)
end
include_context 'database'
include_context 'relations'
specify do
expect(repo.inspect).to eql('#<UserRepo relati... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/unit/repository/transaction_spec.rb | Ruby | mit | 44 | master | 1,240 | RSpec.describe ROM::Repository, '#transaction' do
let(:user_repo) do
Class.new(ROM::Repository[:users]) { commands :create }.new(rom)
end
let(:task_repo) do
Class.new(ROM::Repository[:tasks]) { commands :create, :update }.new(rom)
end
include_context 'database'
include_context 'relations'
it 'c... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/unit/repository/changeset_spec.rb | Ruby | mit | 44 | master | 4,685 | RSpec.describe ROM::Repository, '#changeset' do
subject(:repo) do
Class.new(ROM::Repository) { relations :users }.new(rom)
end
include_context 'database'
include_context 'relations'
describe ROM::Changeset::Create do
context 'with a hash' do
let(:changeset) do
repo.changeset(:users, na... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/shared/seeds.rb | Ruby | mit | 44 | master | 1,200 | RSpec.shared_context 'seeds' do
before do
jane_id = conn[:users].insert name: 'Jane'
joe_id = conn[:users].insert name: 'Joe'
conn[:tasks].insert user_id: joe_id, title: 'Joe Task'
task_id = conn[:tasks].insert user_id: jane_id, title: 'Jane Task'
conn[:tags].insert task_id: task_id, name: 'red'... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/shared/database.rb | Ruby | mit | 44 | master | 1,960 | RSpec.shared_context 'database setup' do
let(:configuration) { ROM::Configuration.new(:sql, DB_URI) }
let(:conn) { configuration.gateways[:default].connection }
let(:rom) { ROM.container(configuration) }
before do
conn.loggers << LOGGER
end
end
RSpec.shared_context 'database' do
include_context 'dat... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/shared/mappers.rb | Ruby | mit | 44 | master | 703 | RSpec.shared_context 'mappers' do
let(:user_mappers) { users.mappers[:user] }
let(:task_mappers) { tasks.mappers[:task] }
let(:tag_mappers) { tags.mappers[:tag] }
before do
configuration.mappers do
define(:users) do
model Test::Models::User
register_as :user
attribute :id
... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/shared/structs.rb | Ruby | mit | 44 | master | 3,199 | RSpec.shared_context 'structs' do
let(:user_struct) do
repo.users.mapper.model
end
let(:task_struct) do
repo.tasks.mapper.model
end
let(:tag_struct) do
repo.tags.mapper.model
end
let(:post_struct) do
repo.posts.mapper.model
end
let(:label_struct) do
repo.labels.mapper.model
e... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/shared/repo.rb | Ruby | mit | 44 | master | 1,861 | RSpec.shared_context('repo') do
include_context 'models'
include_context 'mappers'
let(:repo) { repo_class.new(rom) }
let(:repo_class) do
Class.new(ROM::Repository[:users]) do
relations :tasks, :tags, :posts, :labels, :posts_labels, :books, :authors
def find_users(criteria)
users.find... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/shared/plugins.rb | Ruby | mit | 44 | master | 1,521 | RSpec.shared_context 'plugins' do
before do
module Test
class WrappingInput
def initialize(input)
@input = input || Hash
end
end
module Timestamps
class InputWithTimestamp < WrappingInput
def [](value)
v = @input[value]
now = T... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/shared/models.rb | Ruby | mit | 44 | master | 948 | RSpec.shared_context 'models' do
let(:user_model) { Test::Models::User }
let(:task_model) { Test::Models::Task }
let(:tag_model) { Test::Models::Tag }
before do
module Test
module Models
class User
include Dry::Equalizer(:id, :name)
attr_reader :id, :name
def i... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | spec/shared/relations.rb | Ruby | mit | 44 | master | 2,772 | RSpec.shared_context 'relations' do
let(:users) { rom.relations[:users] }
let(:tasks) { rom.relations[:tasks] }
let(:tags) { rom.relations[:tags] }
let(:posts) { rom.relations[:posts] }
let(:books) { rom.relations[:books] }
before do
configuration.relation(:books) do
schema(:books) do
att... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/open_struct.rb | Ruby | mit | 44 | master | 803 | module ROM
# ROM's open structs are used for relations with empty schemas.
# Such relations may exist in cases like using raw SQL strings
# where schema was not explicitly defined using `view` DSL.
#
# @api public
class OpenStruct
IVAR = -> v { :"@#{v}" }
# @api private
def initialize(attribute... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/struct.rb | Ruby | mit | 44 | master | 4,034 | require 'dry/struct'
module ROM
# Simple data-struct class
#
# ROM structs are plain data structures loaded by repositories.
# They implement Hash protocol which means that they can be used
# in places where Hash-like objects are supported.
#
# Repositories define subclasses of ROM::Struct automatically,... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/repository.rb | Ruby | mit | 44 | master | 10,337 | require 'dry/core/deprecations'
require 'rom/initializer'
require 'rom/repository/class_interface'
require 'rom/repository/mapper_builder'
require 'rom/repository/relation_proxy'
require 'rom/repository/command_compiler'
require 'rom/repository/changeset'
require 'rom/repository/session'
module ROM
# Abstract repo... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/repository/changeset.rb | Ruby | mit | 44 | master | 4,029 | require 'dry/core/class_attributes'
require 'dry/core/cache'
require 'rom/initializer'
module ROM
# Abstract Changeset class
#
# If you inherit from this class you need to configure additional settings
#
# @example define a custom changeset using :upsert command
# class NewTag < ROM::Changeset[:tags]
... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/repository/relation_proxy.rb | Ruby | mit | 44 | master | 9,782 | require 'dry/core/deprecations'
require 'rom/initializer'
require 'rom/relation/materializable'
require 'rom/repository/relation_proxy/combine'
require 'rom/repository/relation_proxy/wrap'
module ROM
class Repository
# RelationProxy decorates a relation and automatically generates mappers that
# will map r... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/repository/struct_builder.rb | Ruby | mit | 44 | master | 1,990 | require 'dry/core/inflector'
require 'dry/core/cache'
require 'dry/core/class_builder'
require 'rom/struct'
require 'rom/open_struct'
require 'rom/schema/attribute'
module ROM
class Repository
# @api private
class StructBuilder
extend Dry::Core::Cache
def call(*args)
fetch_or_store(*arg... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/repository/command_compiler.rb | Ruby | mit | 44 | master | 7,927 | require 'dry/core/inflector'
require 'dry/core/cache'
require 'rom/commands'
require 'rom/repository/command_proxy'
module ROM
class Repository
# Builds commands for relations.
#
# This class is used by repositories to automatically create commands for
# their relations. This is used both by `Reposi... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/repository/header_builder.rb | Ruby | mit | 44 | master | 1,492 | require 'rom/header'
require 'rom/repository/struct_builder'
module ROM
class Repository
# @api private
class HeaderBuilder
attr_reader :struct_builder
def initialize(struct_namespace: nil, **options)
@struct_builder = StructBuilder.new(struct_namespace)
end
def call(ast)
... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/repository/class_interface.rb | Ruby | mit | 44 | master | 3,855 | module ROM
class Repository
# Class-level APIs for repositories
#
# @api public
module ClassInterface
# Create a root-repository class and set its root relation
#
# @example
# # where :users is the relation name in your rom container
# class UserRepo < ROM::Repository... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/repository/session.rb | Ruby | mit | 44 | master | 814 | require 'dry/equalizer'
module ROM
# TODO: finish this in 1.1.0
#
# @api private
class Session
include Dry::Equalizer(:queue, :status)
attr_reader :repo
attr_reader :queue
attr_reader :status
def initialize(repo)
@repo = repo
@status = :pending
initialize_queue!
en... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/repository/command_proxy.rb | Ruby | mit | 44 | master | 582 | require 'dry/core/inflector'
module ROM
class Repository
# TODO: look into making command graphs work without the root key in the input
# so that we can get rid of this wrapper
#
# @api private
class CommandProxy
attr_reader :command, :root
def initialize(command)
@comm... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/repository/root.rb | Ruby | mit | 44 | master | 4,628 | require 'dry/core/class_attributes'
module ROM
class Repository
# A specialized repository type dedicated to work with a root relation
#
# This repository type builds commands and aggregates for its root relation
#
# @example
# class UserRepo < ROM::Repository[:users]
# commands :cr... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/repository/mapper_builder.rb | Ruby | mit | 44 | master | 477 | require 'dry/core/cache'
require 'rom/mapper'
require 'rom/repository/header_builder'
module ROM
class Repository
# @api private
class MapperBuilder
extend Dry::Core::Cache
attr_reader :header_builder
def initialize(options = EMPTY_HASH)
@header_builder = HeaderBuilder.new(options... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/repository/relation_proxy/wrap.rb | Ruby | mit | 44 | master | 2,213 | module ROM
class Repository
class RelationProxy
# Provides convenient methods for producing wrapped relations
#
# @api public
module Wrap
# Wrap other relations
#
# @example
# tasks.wrap(owner: [users, user_id: :id])
#
# @param [Hash] optio... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/repository/relation_proxy/combine.rb | Ruby | mit | 44 | master | 11,697 | require 'dry/core/inflector'
module ROM
class Repository
class RelationProxy
# Provides convenient methods for composing relations
#
# @api public
module Combine
# Returns a combine representation of a loading-proxy relation
#
# This will carry meta info used to pr... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/repository/changeset/associated.rb | Ruby | mit | 44 | master | 2,935 | require 'rom/initializer'
module ROM
class Changeset
# Associated changesets automatically set up FKs
#
# @api public
class Associated
extend Initializer
# @!attribute [r] left
# @return [Changeset::Create] Child changeset
param :left
# @!attribute [r] associations
... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/repository/changeset/delete.rb | Ruby | mit | 44 | master | 409 | require 'rom/repository/changeset/restricted'
module ROM
class Changeset
# Changeset specialization for delete commands
#
# Delete changesets will execute delete command for its relation, which
# means proper restricted relations should be used with this changeset.
#
# @api public
class D... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/repository/changeset/create.rb | Ruby | mit | 44 | master | 271 | module ROM
class Changeset
# Changeset specialization for create commands
#
# @see Changeset::Stateful
#
# @api public
class Create < Stateful
command_type :create
def command
super.new(relation)
end
end
end
end |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/repository/changeset/pipe.rb | Ruby | mit | 44 | master | 2,319 | require 'transproc/registry'
require 'transproc/transformer'
module ROM
class Changeset
# Transproc Registry useful for pipe
#
# @api private
module PipeRegistry
extend Transproc::Registry
import Transproc::HashTransformations
def self.add_timestamps(data)
now = Time.now
... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/repository/changeset/update.rb | Ruby | mit | 44 | master | 2,073 | require 'rom/repository/changeset/restricted'
module ROM
class Changeset
# Changeset specialization for update commands
#
# Update changesets will only execute their commands when
# the data is different from the original tuple. Original tuple
# is fetched from changeset's relation using `by_pk` ... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/repository/changeset/restricted.rb | Ruby | mit | 44 | master | 592 | module ROM
class Changeset
module Restricted
# Return a command restricted by the changeset's relation
#
# @see Changeset#command
#
# @api private
def command
super.new(relation)
end
# Restrict changeset's relation by its PK
#
# @example
#... |
github | rom-rb/rom-repository | https://github.com/rom-rb/rom-repository | lib/rom/repository/changeset/stateful.rb | Ruby | mit | 44 | master | 7,684 | require 'rom/repository/changeset/pipe'
module ROM
class Changeset
# Stateful changesets carry data and can transform it into
# a different structure compatible with a persistence backend
#
# @abstract
class Stateful < Changeset
# Default no-op pipe
EMPTY_PIPE = Pipe.new.freeze
... |
github | qonto/api_schema | https://github.com/qonto/api_schema | api_schema.gemspec | Ruby | mit | 19 | master | 1,246 | # coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'api_schema/version'
Gem::Specification.new do |spec|
spec.name = "api_schema"
spec.version = ApiSchema::VERSION
spec.authors = ["Dmitry Chopey"]
spec.email = ... |
github | qonto/api_schema | https://github.com/qonto/api_schema | spec/spec_helper.rb | Ruby | mit | 19 | master | 264 | require "bundler/setup"
require "api_schema"
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
config.expect_with :rspec do |c|
c.syntax = :expect
end
end |
github | qonto/api_schema | https://github.com/qonto/api_schema | spec/api_schema_spec.rb | Ruby | mit | 19 | master | 14,836 | require "spec_helper"
module First
module V1
class BaseDocs
include ApiSchema
configure do |config|
config.title = 'Users API'
config.description = 'API for users'
config.version = '1.0'
config.host = 'sample.com'
config.base_path = '/api'
config.terms... |
github | qonto/api_schema | https://github.com/qonto/api_schema | lib/api_schema.rb | Ruby | mit | 19 | master | 755 | require 'active_support/inflector'
require 'swagger/blocks'
require 'api_schema/patches/operation_node'
require 'api_schema/patches/property_node'
require 'api_schema/patches/schema_node'
require "api_schema/configuration"
require "api_schema/api_version"
require "api_schema/root_methods"
require "api_schema/field"
r... |
github | qonto/api_schema | https://github.com/qonto/api_schema | lib/api_schema/field.rb | Ruby | mit | 19 | master | 461 | module ApiSchema
class Field
attr_accessor :type, :name, :format, :required, :description, :allowed_values
def initialize(type, name, options = {})
@type = type
@name = name
@format = options.fetch(:format, nil)
@required = options.fetch(:required, false)
@description = options... |
github | qonto/api_schema | https://github.com/qonto/api_schema | lib/api_schema/root_methods.rb | Ruby | mit | 19 | master | 1,328 | module ApiSchema
module RootMethods
def inherited(subclass)
instance_var = "@api_version"
subclass.instance_variable_set(instance_var, instance_variable_get(instance_var))
instance_var_neighbors = "@version_resources"
subclass.instance_variable_set(instance_var_neighbors, instance_variabl... |
github | qonto/api_schema | https://github.com/qonto/api_schema | lib/api_schema/resource_definition.rb | Ruby | mit | 19 | master | 3,433 | module ApiSchema
class ResourceDefinition
include ::Swagger::Blocks::ClassMethods
def initialize(method, api_version, base_path, extra_path = nil)
@base_path = base_path
@extra_path = extra_path
@method = method
@api_version = api_version
@header_params = []
@path_params =... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.