Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
BASE_DB_URI=postgres@db/rom

BASE_DB_URI=rom:password@postgres/rom
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ jobs:
- '3.1'
- '3.0'
- '2.7'
- '2.6'
# TODO: re-add both as a separate workflow because it's just too slow
# - jruby
# - truffleruby
group: [rom, compat]
include:
- ruby: '3.0'
coverage: 'false'
Expand All @@ -47,8 +47,9 @@ jobs:
CODACY_RUN_LOCAL: "${{matrix.coverage}}"
CODACY_PROJECT_TOKEN: "${{secrets.CODACY_PROJECT_TOKEN}}"
APT_DEPS: libpq-dev libsqlite3-dev
SPEC_GROUP: "${{matrix.group}}"
services:
db:
postgres:
image: postgres:10.8
env:
POSTGRES_USER: runner
Expand All @@ -68,8 +69,8 @@ jobs:
with:
ruby-version: "${{matrix.ruby}}"
bundler-cache: true
- name: Run all tests
run: bundle exec rake
- name: Run tests
run: bundle exec rake spec:$SPEC_GROUP
- name: Run codacy-coverage-reporter
uses: codacy/codacy-coverage-reporter-action@master
if: env.COVERAGE == 'true' && env.COVERAGE_TOKEN != ''
Expand Down
7 changes: 7 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ Metrics/CyclomaticComplexity:
Enabled: true
Max: 12

Metrics/PerceivedComplexity:
Enabled: true
Max: 10

Style/AccessorGrouping:
Enabled: false

Expand Down Expand Up @@ -160,6 +164,9 @@ Style/LambdaCall:
Style/ParallelAssignment:
Enabled: false

Style/RaiseArgs:
Enabled: false

Style/StabbyLambdaParentheses:
Enabled: false

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ ARG RUBY_VERSION

FROM ruby:$RUBY_VERSION-alpine

RUN apk update && apk add bash git gnupg build-base sqlite-dev postgresql-dev
RUN apk update && apk add bash git gnupg build-base sqlite-dev postgresql-dev mysql-dev

WORKDIR /usr/local/src/rom
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gemspec
eval_gemfile "Gemfile.devtools"

gem "dry-container", github: "dry-rb/dry-container", branch: "master"
gem "dry-configurable", github: "dry-rb/dry-configurable", branch: "master"
gem "dry-configurable", "~> 0.14.0"

if ENV["USE_DRY_TRANSFORMER_MASTER"].eql?("true")
gem "dry-transformer", github: "dry-rb/dry-transformer", branch: "master"
Expand Down
6 changes: 1 addition & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ RSpec::Core::RakeTask.new("spec:rom") do |t|
t.pattern = ["spec/suite/rom/**/*_spec.rb"]
end

RSpec::Core::RakeTask.new("spec:legacy") do |t|
t.pattern = ["spec/suite/legacy/**/*_spec.rb"]
end

RSpec::Core::RakeTask.new("spec:compat") do |t|
t.pattern = ["spec/suite/compat/**/*_spec.rb"]
end

desc "Run all spec examples from all groups"
task spec: ["spec:rom", "spec:legacy", "spec:compat"]
task spec: ["spec:rom", "spec:compat"]

task default: :spec

Expand Down
17 changes: 15 additions & 2 deletions lib/rom/commands/class_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,14 @@ def create_class(type: self, meta: {}, rel_meta: {}, plugins: {}, **, &block)
klass = Dry::Core::ClassBuilder.new(name: type.name, parent: type).call

result = meta.fetch(:result, :one)
klass.result(rel_meta.fetch(:combine_type, result))
klass.config.result = rel_meta.fetch(:combine_type, result)

meta.each do |name, value|
klass.public_send(name, value)
if klass.respond_to?(name)
klass.public_send(name, value)
else
klass.config[name] = value
end
end

plugins.each do |plugin, options|
Expand Down Expand Up @@ -123,6 +127,15 @@ def use(plugin, **options)
ROM.plugins[:command].fetch(plugin, adapter).apply_to(self, **options)
end

# Return configured adapter identifier
#
# @return [Symbol]
#
# @api public
def adapter
config.component.adapter
end

# Set before-execute hooks
#
# @overload before(hook)
Expand Down
2 changes: 1 addition & 1 deletion lib/rom/commands/delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Commands
#
# @abstract
class Delete < Command
restrictable true
config.restrictable = true
end
end
end
4 changes: 2 additions & 2 deletions lib/rom/commands/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class Graph
# Graph results are mappable through `combine` operation in mapper DSL
#
# @example
# create_user = rom.commands[:users].create
# create_task = rom.commands[:tasks].create
# create_user = rom.commands[:users][:create]
# create_task = rom.commands[:tasks][:create]
#
# command = create_user
# .curry(name: 'Jane')
Expand Down
2 changes: 1 addition & 1 deletion lib/rom/commands/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Commands
#
# @abstract
class Update < Command
restrictable true
config.restrictable = true
end
end
end
6 changes: 4 additions & 2 deletions lib/rom/compat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

require "rom/core"
require "rom/resolver"
require "rom/runtime"
require "rom/container"
require "rom/configuration"
require "rom/global"

require_relative "compat/auto_registration"
Expand All @@ -23,8 +23,10 @@ module Global
alias_method :container, :runtime
end

Configuration = Runtime

# @api public
class Configuration
class Runtime
# @api public
# @deprecated
def inflector=(inflector)
Expand Down
54 changes: 33 additions & 21 deletions lib/rom/compat/components/dsl/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ module ROM
module Components
module DSL
# @private
#
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
class Schema < Core
mod = Module.new do
# @api private
def call
return super unless config.dsl_class
return super unless config.dsl_class || config.view

configure

Expand All @@ -37,6 +41,13 @@ def call
end
end

# @api public
#
# @deprecated
def associations(&block)
backend.associations(&block)
end

private

# @api private
Expand Down Expand Up @@ -64,26 +75,24 @@ def backend

# @api private
def configure
if !config.view
if provider.config.component.type == :relation
provider.config.component.update(dataset: config.dataset) if config.dataset
provider.config.component.update(id: config.as) if config.as

if provider.config.component.id == :anonymous
provider.config.component.update(id: config.id)
end

if config.id.nil?
config.update(id: provider.config.component.id)
end

if config.relation.nil?
config.update(relation: provider.config.component.id)
end

if config.adapter.nil?
config.update(adapter: provider.config.component.adapter)
end
if !config.view && provider.config.component.type == :relation
provider.config.component.update(dataset: config.dataset) if config.dataset
provider.config.component.update(id: config.as) if config.as

if provider.config.component.id == :anonymous
provider.config.component.update(id: config.id)
end

if config.id.nil?
config.update(id: provider.config.component.id)
end

if config.relation.nil?
config.update(relation: provider.config.component.id)
end

if config.adapter.nil?
config.update(adapter: provider.config.component.adapter)
end
end

Expand All @@ -110,6 +119,9 @@ def inferrer
config.inferrer.with(enabled: config.infer)
end
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity

prepend(mod)
end
Expand Down
5 changes: 3 additions & 2 deletions lib/rom/components.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module ROM
module Components
extend Dry::Container::Mixin
extend Enumerable
extend self

module_function

# @api private
class Handler
Expand Down Expand Up @@ -47,7 +48,7 @@ def register(key, constant = nil, **options)
# Iterate over all registered component handlers
#
# @api public
def each(&block)
def each
keys.each { |key| yield(resolve(key)) }
end
end
Expand Down
10 changes: 9 additions & 1 deletion lib/rom/components/dsl/association.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "rom/schema/associations_dsl"
require "rom/relation/name"

require_relative "core"

Expand Down Expand Up @@ -31,7 +32,14 @@ def backend

# @api private
def source
config.source || config.id
if provider.config.component.key?(:id)
# TODO: decouple associations DSL from Relation::Name
ROM::Relation::Name[
provider.config.component.id, provider.config.component.dataset
]
else
config.source
end
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/rom/components/dsl/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def call
build_class do |dsl|
config.component.adapter = dsl.adapter if dsl.adapter
class_exec(&dsl.block) if dsl.block

if (schema_dataset = components.schemas.first&.config&.dataset)
config.component.dataset = schema_dataset
end
end
end

Expand Down
29 changes: 24 additions & 5 deletions lib/rom/components/dsl/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def attribute(name, type_or_options, options = EMPTY_HASH)
# @api public
def primary_key(*names)
names.each do |name|
attr_index[name][:type] = attr_index[name][:type].meta(primary_key: true)
attributes[name][:type] = attributes[name][:type].meta(primary_key: true)
end
self
end
Expand All @@ -54,7 +54,7 @@ def call

# Apply plugin defaults
plugins.each do |plugin|
plugin.apply_to(self) unless plugin.applied?
plugin.apply_to(self)
end

configure
Expand All @@ -65,6 +65,17 @@ def call
# @api private
def configure
config.update(attributes: attributes.values)

# TODO: make this simpler
config.update(inferrer: config.inferrer.with(enabled: config.infer))

if !config.view && provider.config.component.type == :relation
provider.config.component.update(dataset: config.dataset) if config.dataset
provider.config.component.update(id: config.as) if config.as
end

provider.config.schema.infer = config.infer

super
end

Expand Down Expand Up @@ -98,13 +109,16 @@ def build_type(type, options = EMPTY_HASH)
.compact
.to_h

# TODO: this should be probably moved to rom/compat
source = ROM::Relation::Name[relation]

base =
if options[:read]
type.meta(source: relation, read: options[:read])
type.meta(source: source, read: options[:read])
elsif type.optional? && type.meta[:read]
type.meta(source: relation, read: type.meta[:read].optional)
type.meta(source: source, read: type.meta[:read].optional)
else
type.meta(source: relation)
type.meta(source: source)
end

if meta.empty?
Expand All @@ -113,6 +127,11 @@ def build_type(type, options = EMPTY_HASH)
base.meta(meta)
end
end

# @api private
def relation
config.id
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/rom/components/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def inherited(klass)

# @api private
def initialize(features, type: nil)
super()
@provider = nil
@type = type
@features = features
Expand Down
Loading