rom 2.0.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -7
- data/.yardopts +2 -0
- data/CHANGELOG.md +35 -1
- data/Gemfile +17 -2
- data/Rakefile +7 -2
- data/lib/rom/array_dataset.rb +44 -0
- data/lib/rom/association_set.rb +11 -5
- data/lib/rom/auto_curry.rb +55 -0
- data/lib/rom/command.rb +331 -47
- data/lib/rom/command_registry.rb +7 -18
- data/lib/rom/commands/class_interface.rb +120 -6
- data/lib/rom/commands/composite.rb +0 -1
- data/lib/rom/commands/graph.rb +7 -15
- data/lib/rom/commands/lazy/update.rb +1 -1
- data/lib/rom/configuration.rb +2 -0
- data/lib/rom/configuration_dsl/command.rb +6 -8
- data/lib/rom/configuration_dsl/mapper.rb +2 -3
- data/lib/rom/configuration_dsl/mapper_dsl.rb +0 -1
- data/lib/rom/configuration_dsl/relation.rb +4 -4
- data/lib/rom/configuration_dsl.rb +0 -4
- data/lib/rom/constants.rb +7 -1
- data/lib/rom/container.rb +11 -17
- data/lib/rom/create_container.rb +0 -2
- data/lib/rom/data_proxy.rb +94 -0
- data/lib/rom/enumerable_dataset.rb +68 -0
- data/lib/rom/gateway.rb +74 -32
- data/lib/rom/global/plugin_dsl.rb +0 -2
- data/lib/rom/global.rb +0 -2
- data/lib/rom/initializer.rb +26 -0
- data/lib/rom/lint/gateway.rb +17 -0
- data/lib/rom/mapper_registry.rb +1 -1
- data/lib/rom/memory/commands.rb +0 -2
- data/lib/rom/memory/dataset.rb +1 -2
- data/lib/rom/memory/relation.rb +14 -1
- data/lib/rom/memory/schema.rb +13 -0
- data/lib/rom/plugin_registry.rb +1 -1
- data/lib/rom/plugins/command/schema.rb +2 -2
- data/lib/rom/plugins/configuration/configuration_dsl.rb +6 -2
- data/lib/rom/plugins/relation/key_inference.rb +4 -2
- data/lib/rom/plugins/relation/registry_reader.rb +5 -1
- data/lib/rom/registry.rb +50 -0
- data/lib/rom/relation/class_interface.rb +142 -30
- data/lib/rom/relation/curried.rb +15 -15
- data/lib/rom/relation/view_dsl.rb +31 -0
- data/lib/rom/relation.rb +101 -41
- data/lib/rom/schema/attribute.rb +367 -0
- data/lib/rom/schema/dsl.rb +14 -10
- data/lib/rom/schema.rb +337 -19
- data/lib/rom/setup/auto_registration.rb +20 -17
- data/lib/rom/setup/auto_registration_strategies/base.rb +8 -3
- data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +4 -3
- data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +5 -4
- data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +3 -3
- data/lib/rom/setup/finalize/finalize_commands.rb +1 -1
- data/lib/rom/setup/finalize/finalize_mappers.rb +1 -1
- data/lib/rom/setup/finalize/finalize_relations.rb +4 -2
- data/lib/rom/setup/finalize.rb +1 -1
- data/lib/rom/transaction.rb +24 -0
- data/lib/rom/types.rb +9 -1
- data/lib/rom/version.rb +1 -1
- data/lib/rom.rb +4 -8
- data/rom.gemspec +5 -4
- data/spec/integration/command_registry_spec.rb +1 -14
- data/spec/integration/commands/create_spec.rb +5 -25
- data/spec/integration/commands/delete_spec.rb +1 -1
- data/spec/integration/commands/error_handling_spec.rb +1 -1
- data/spec/integration/commands/graph_spec.rb +20 -14
- data/spec/integration/commands/update_spec.rb +4 -27
- data/spec/integration/commands_spec.rb +1 -1
- data/spec/integration/{repositories → gateways}/extending_relations_spec.rb +1 -1
- data/spec/integration/{repositories → gateways}/setting_logger_spec.rb +2 -2
- data/spec/integration/mappers/combine_spec.rb +1 -1
- data/spec/integration/mappers/deep_embedded_spec.rb +1 -1
- data/spec/integration/mappers/definition_dsl_spec.rb +1 -1
- data/spec/integration/mappers/embedded_spec.rb +1 -1
- data/spec/integration/mappers/exclude_spec.rb +1 -1
- data/spec/integration/mappers/fold_spec.rb +1 -1
- data/spec/integration/mappers/group_spec.rb +1 -1
- data/spec/integration/mappers/overwrite_attributes_value_spec.rb +1 -1
- data/spec/integration/mappers/prefix_separator_spec.rb +1 -1
- data/spec/integration/mappers/prefix_spec.rb +1 -1
- data/spec/integration/mappers/prefixing_attributes_spec.rb +1 -1
- data/spec/integration/mappers/registering_custom_mappers_spec.rb +1 -1
- data/spec/integration/mappers/renaming_attributes_spec.rb +1 -1
- data/spec/integration/mappers/reusing_mappers_spec.rb +1 -1
- data/spec/integration/mappers/step_spec.rb +1 -1
- data/spec/integration/mappers/symbolizing_attributes_spec.rb +1 -1
- data/spec/integration/mappers/unfold_spec.rb +1 -1
- data/spec/integration/mappers/ungroup_spec.rb +2 -2
- data/spec/integration/mappers/unwrap_spec.rb +2 -2
- data/spec/integration/mappers/wrap_spec.rb +1 -1
- data/spec/integration/memory/commands/create_spec.rb +1 -1
- data/spec/integration/memory/commands/delete_spec.rb +1 -1
- data/spec/integration/memory/commands/update_spec.rb +1 -1
- data/spec/integration/multi_env_spec.rb +1 -1
- data/spec/integration/multi_repo_spec.rb +1 -1
- data/spec/integration/relations/default_dataset_spec.rb +1 -1
- data/spec/integration/relations/reading_spec.rb +1 -1
- data/spec/integration/relations/registry_dsl_spec.rb +1 -1
- data/spec/integration/setup_spec.rb +10 -4
- data/spec/shared/command_graph.rb +8 -4
- data/spec/shared/enumerable_dataset.rb +1 -1
- data/spec/spec_helper.rb +7 -9
- data/spec/support/schema.rb +14 -0
- data/spec/unit/rom/array_dataset_spec.rb +59 -0
- data/spec/unit/rom/association_set_spec.rb +4 -0
- data/spec/unit/rom/auto_curry_spec.rb +63 -0
- data/spec/unit/rom/commands/graph_spec.rb +12 -11
- data/spec/unit/rom/commands/lazy_spec.rb +8 -5
- data/spec/unit/rom/commands/pre_and_post_processors_spec.rb +336 -0
- data/spec/unit/rom/commands/result_spec.rb +1 -1
- data/spec/unit/rom/commands_spec.rb +26 -3
- data/spec/unit/rom/configuration_spec.rb +1 -1
- data/spec/unit/rom/container_spec.rb +15 -5
- data/spec/unit/rom/create_container_spec.rb +1 -1
- data/spec/unit/rom/enumerable_dataset_spec.rb +15 -0
- data/spec/unit/rom/gateway_spec.rb +1 -1
- data/spec/unit/rom/mapper_registry_spec.rb +1 -1
- data/spec/unit/rom/memory/commands_spec.rb +1 -1
- data/spec/unit/rom/memory/dataset_spec.rb +1 -1
- data/spec/unit/rom/memory/{repository_spec.rb → gateway_spec.rb} +1 -1
- data/spec/unit/rom/memory/inheritance_spec.rb +32 -0
- data/spec/unit/rom/memory/relation_spec.rb +15 -3
- data/spec/unit/rom/memory/storage_spec.rb +1 -1
- data/spec/unit/rom/plugin_spec.rb +1 -1
- data/spec/unit/rom/plugins/command/schema_spec.rb +5 -5
- data/spec/unit/rom/plugins/relation/key_inference_spec.rb +1 -1
- data/spec/unit/rom/registry_spec.rb +86 -0
- data/spec/unit/rom/relation/attribute_reader_spec.rb +17 -0
- data/spec/unit/rom/relation/call_spec.rb +51 -0
- data/spec/unit/rom/relation/composite_spec.rb +1 -1
- data/spec/unit/rom/relation/graph_spec.rb +1 -1
- data/spec/unit/rom/relation/lazy/combine_spec.rb +1 -1
- data/spec/unit/rom/relation/lazy_spec.rb +1 -1
- data/spec/unit/rom/relation/loaded_spec.rb +1 -1
- data/spec/unit/rom/relation/schema_spec.rb +50 -6
- data/spec/unit/rom/relation/view_spec.rb +122 -0
- data/spec/unit/rom/relation_spec.rb +20 -5
- data/spec/unit/rom/schema/accessing_attributes_spec.rb +52 -0
- data/spec/unit/rom/schema/append_spec.rb +17 -0
- data/spec/unit/rom/schema/exclude_spec.rb +15 -0
- data/spec/unit/rom/schema/finalize_spec.rb +59 -0
- data/spec/unit/rom/schema/key_predicate_spec.rb +15 -0
- data/spec/unit/rom/schema/merge_spec.rb +17 -0
- data/spec/unit/rom/schema/prefix_spec.rb +16 -0
- data/spec/unit/rom/schema/project_spec.rb +15 -0
- data/spec/unit/rom/schema/rename_spec.rb +22 -0
- data/spec/unit/rom/schema/type_spec.rb +49 -0
- data/spec/unit/rom/schema/uniq_spec.rb +21 -0
- data/spec/unit/rom/schema/wrap_spec.rb +17 -0
- data/spec/unit/rom/schema_spec.rb +2 -2
- metadata +79 -17
- data/lib/rom/plugins/relation/view/dsl.rb +0 -32
- data/lib/rom/plugins/relation/view.rb +0 -95
- data/spec/unit/rom/plugins/relation/view_spec.rb +0 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 078640069bc820b095d68303b641a154635a91f6
|
4
|
+
data.tar.gz: 79499e687dc324c807495be3e332cd27dee00002
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd576e0492c38c4b68ac39a7a9fe406d333035658d014541aa379698c08649064a93b1cb7db762d8c327d0f01fa1eb4b1e62c9d3693c83e1e97f0887286966c7
|
7
|
+
data.tar.gz: e930878f5a01d11b9c2c1cd09e2fddfb91584ac7c2daca875acb06f772921bafaa8755dd7fcedece03c7b9ebe04d75f277f1f9a42efd01780db8f08de728b2dd
|
data/.travis.yml
CHANGED
@@ -5,20 +5,17 @@ cache: bundler
|
|
5
5
|
bundler_args: --without sql benchmarks console tools
|
6
6
|
script: "bundle exec rake ci"
|
7
7
|
after_success:
|
8
|
-
- '[ "$
|
8
|
+
- '[ "${TRAVIS_JOB_NUMBER#*.}" = "1" ] && [ "$TRAVIS_BRANCH" = "master" ] && bundle exec codeclimate-test-reporter'
|
9
9
|
rvm:
|
10
|
-
- 2.
|
10
|
+
- 2.4.0
|
11
|
+
- 2.3
|
11
12
|
- 2.2
|
12
|
-
- 2.3.1
|
13
13
|
- rbx-3
|
14
|
-
- jruby
|
14
|
+
- jruby
|
15
15
|
env:
|
16
16
|
global:
|
17
17
|
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
18
18
|
- COVERAGE='true'
|
19
|
-
matrix:
|
20
|
-
allow_failures:
|
21
|
-
- rvm: rbx-3
|
22
19
|
notifications:
|
23
20
|
webhooks:
|
24
21
|
urls:
|
data/.yardopts
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,37 @@
|
|
1
|
+
## v3.0.0 to-be-released
|
2
|
+
|
3
|
+
## Added
|
4
|
+
|
5
|
+
* Support for schemas in view definitions via `schema do ... end` block (evaluated in the context of the canonical schema) (solnic)
|
6
|
+
* Schemas have their own types with adapter-specific APIs (solnic)
|
7
|
+
* Schema attributes include meta properties `source` and `target` (for FKs) (solnic)
|
8
|
+
* Inferred schemas can have explicit attribute definitions for cases where inference didn't work (solnic)
|
9
|
+
* New schema APIs: `#project`, `#rename`, `#exclude`, `#prefix`, `#wrap`, `#merge`, `#append` and `#uniq` (solnic)
|
10
|
+
* New schema attribute APIs: `#name`, `#aliased`, `#aliased?`, `#prefixed`, `#prefixed?`, `#wrapped`, `#wrapped?`, `#source`, `#target`, `#primary_key?`, `#foreign_key?` (solnic)
|
11
|
+
* Schemas are coercible to arrays that include all attribute types (solnic)
|
12
|
+
* Automatic relation view projection via `Schema#call` (abstract method for adapters) (solnic)
|
13
|
+
* `Relation#new(dataset, new_opts)` interface (solnic)
|
14
|
+
* `Relation#[]` interface for convenient access to schema attributes (solnic)
|
15
|
+
* `Command` has now support for `before` and `after` hooks (solnic)
|
16
|
+
* Support for `read` types in schemas, these are used when relation loads its tuples (solnic)
|
17
|
+
* New `Command#before` method for creating a command with before hook(s) at run-time (solnic)
|
18
|
+
* New `Command#after` method for creating a command with after hook(s) at run-time (solnic)
|
19
|
+
* New `Gateway#transaction` method runs code inside a transaction (flash-gordon)
|
20
|
+
|
21
|
+
## Changed
|
22
|
+
|
23
|
+
* [BREAKING] All relations have schemas now, empty by default (solnic)
|
24
|
+
* [BREAKING] `view` DSL is now part of the core relation API (solnic)
|
25
|
+
* [BREAKING] `view` DSL is based on schemas now, `header` was replaced with `schema` (solnic)
|
26
|
+
* [BREAKING] Deprecated `Command.validator` was removed (solnic)
|
27
|
+
* [internal] Renamed `relation` => `target` meta property in FK types (solnic)
|
28
|
+
* [internal] Use deprecations API from dry-core (flash-gordon)
|
29
|
+
* [internal] Use common constants from dry-core (EMPTY_HASH, EMPTY_ARRAY etc.) (flash-gordon)
|
30
|
+
* [internal] Internal ROM modules (array_dataset, enumerable_dataset, auto_curry, and data_proxy) were moved from rom-support to ROM itself (flash-gordon)
|
31
|
+
* [internal] rom-support dependency was removed (flash-gordon)
|
32
|
+
|
33
|
+
[Compare v2.0.2...v3.0.0](https://github.com/rom-rb/rom/compare/v2.0.2...v3.0.0)
|
34
|
+
|
1
35
|
## v2.0.2 2016-11-11
|
2
36
|
|
3
37
|
## Added
|
@@ -9,7 +43,7 @@
|
|
9
43
|
* Custom command input function is no longer overridden by schema hash (solnic)
|
10
44
|
* `Relation::Name#to_s` returns a string properly when there is no alias (solnic)
|
11
45
|
|
12
|
-
[Compare v2.0.1...v2.0.2](https://github.com/rom-rb/rom/compare/v2.0.
|
46
|
+
[Compare v2.0.1...v2.0.2](https://github.com/rom-rb/rom/compare/v2.0.1...v2.0.2)
|
13
47
|
|
14
48
|
## v2.0.1 2016-09-30
|
15
49
|
|
data/Gemfile
CHANGED
@@ -2,6 +2,9 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
+
gem 'rom-mapper', git: 'https://github.com/rom-rb/rom-mapper.git', branch: 'master'
|
6
|
+
gem 'transproc', git: 'https://github.com/solnic/transproc.git', branch: 'master'
|
7
|
+
|
5
8
|
group :console do
|
6
9
|
gem 'pry'
|
7
10
|
gem 'pg', platforms: [:mri]
|
@@ -24,18 +27,30 @@ group :test do
|
|
24
27
|
end
|
25
28
|
|
26
29
|
group :sql do
|
27
|
-
gem 'rom-sql',
|
30
|
+
gem 'rom-sql', git: 'https://github.com/rom-rb/rom-sql.git', branch: 'master'
|
28
31
|
gem 'sequel'
|
29
32
|
gem 'jdbc-sqlite3', platforms: :jruby
|
33
|
+
gem 'jdbc-postgres', platforms: :jruby
|
30
34
|
gem 'sqlite3', platforms: [:mri, :rbx]
|
35
|
+
|
36
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" }
|
37
|
+
|
38
|
+
platform :jruby do
|
39
|
+
github 'jruby/activerecord-jdbc-adapter', branch: 'rails-5' do
|
40
|
+
gem 'activerecord-jdbc-adapter'
|
41
|
+
gem 'activerecord-jdbcpostgresql-adapter'
|
42
|
+
end
|
43
|
+
end
|
31
44
|
end
|
32
45
|
|
33
46
|
group :benchmarks do
|
34
47
|
gem 'activerecord', '~> 5.0'
|
35
48
|
gem 'benchmark-ips', '~> 2.2.0'
|
36
|
-
gem 'rom-repository',
|
49
|
+
gem 'rom-repository', git: 'https://github.com/rom-rb/rom-repository.git', branch: 'master'
|
37
50
|
end
|
38
51
|
|
39
52
|
group :tools do
|
40
53
|
gem 'byebug', platform: :mri
|
54
|
+
gem 'mutant'
|
55
|
+
gem 'mutant-rspec'
|
41
56
|
end
|
data/Rakefile
CHANGED
@@ -11,8 +11,13 @@ task :"spec:isolation" do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
if RUBY_ENGINE != 'ruby'
|
15
|
+
desc "Run CI tasks"
|
16
|
+
task ci: [:spec, :lint]
|
17
|
+
else
|
18
|
+
desc "Run CI tasks"
|
19
|
+
task ci: [:spec, :lint, :"spec:isolation"]
|
20
|
+
end
|
16
21
|
|
17
22
|
Rake::TestTask.new(:lint) do |test|
|
18
23
|
test.description = "Run adapter lint tests against memory adapter"
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rom/initializer'
|
2
|
+
require 'rom/enumerable_dataset'
|
3
|
+
|
4
|
+
module ROM
|
5
|
+
# A helper module that adds data-proxy behavior to an array-like object
|
6
|
+
#
|
7
|
+
# @see EnumerableDataset
|
8
|
+
#
|
9
|
+
# @api public
|
10
|
+
module ArrayDataset
|
11
|
+
extend DataProxy::ClassMethods
|
12
|
+
include EnumerableDataset
|
13
|
+
|
14
|
+
# Extends the class with data-proxy behavior
|
15
|
+
#
|
16
|
+
# @api private
|
17
|
+
def self.included(klass)
|
18
|
+
klass.class_eval do
|
19
|
+
extend Initializer
|
20
|
+
include DataProxy
|
21
|
+
|
22
|
+
param :data
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
forward(
|
27
|
+
:*, :+, :-, :compact, :compact!, :flatten, :flatten!, :length, :pop,
|
28
|
+
:reverse, :reverse!, :sample, :size, :shift, :shuffle, :shuffle!,
|
29
|
+
:slice, :slice!, :sort!, :uniq, :uniq!, :unshift, :values_at
|
30
|
+
)
|
31
|
+
|
32
|
+
[
|
33
|
+
:map!, :combination, :cycle, :delete_if, :keep_if, :permutation, :reject!,
|
34
|
+
:select!, :sort_by!
|
35
|
+
].each do |method|
|
36
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
37
|
+
def #{method}(*args, &block)
|
38
|
+
return to_enum unless block
|
39
|
+
self.class.new(data.send(:#{method}, *args, &block), options)
|
40
|
+
end
|
41
|
+
RUBY
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/rom/association_set.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
-
require '
|
2
|
-
require 'rom/
|
1
|
+
require 'dry/core/inflector'
|
2
|
+
require 'rom/registry'
|
3
3
|
|
4
4
|
module ROM
|
5
5
|
class AssociationSet < ROM::Registry
|
6
6
|
# @api private
|
7
7
|
def try(name, &block)
|
8
|
-
|
9
|
-
|
8
|
+
key = name.to_sym
|
9
|
+
|
10
|
+
if key?(key) || key?(singularize(key))
|
11
|
+
yield(self[key])
|
10
12
|
else
|
11
13
|
false
|
12
14
|
end
|
@@ -19,8 +21,12 @@ module ROM
|
|
19
21
|
if key?(key)
|
20
22
|
super
|
21
23
|
else
|
22
|
-
super(
|
24
|
+
super(singularize(key))
|
23
25
|
end
|
24
26
|
end
|
27
|
+
|
28
|
+
def singularize(key)
|
29
|
+
Dry::Core::Inflector.singularize(key).to_sym
|
30
|
+
end
|
25
31
|
end
|
26
32
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module ROM
|
2
|
+
module AutoCurry
|
3
|
+
def self.extended(klass)
|
4
|
+
klass.define_singleton_method(:method_added) do |name|
|
5
|
+
return if auto_curry_busy?
|
6
|
+
auto_curry_guard { auto_curry(name) }
|
7
|
+
super(name)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def auto_curry_guard
|
12
|
+
@__auto_curry_busy__ = true
|
13
|
+
yield
|
14
|
+
ensure
|
15
|
+
@__auto_curry_busy__ = false
|
16
|
+
end
|
17
|
+
|
18
|
+
def auto_curry_busy?
|
19
|
+
@__auto_curry_busy__ ||= false
|
20
|
+
end
|
21
|
+
|
22
|
+
def auto_curried_methods
|
23
|
+
@__auto_curried_methods__ ||= []
|
24
|
+
end
|
25
|
+
|
26
|
+
def auto_curry(name, &block)
|
27
|
+
arity = instance_method(name).arity
|
28
|
+
|
29
|
+
return unless public_instance_methods.include?(name) && arity != 0
|
30
|
+
|
31
|
+
mod = Module.new
|
32
|
+
|
33
|
+
mod.module_eval do
|
34
|
+
define_method(name) do |*args|
|
35
|
+
response =
|
36
|
+
if arity < 0 || arity == args.size
|
37
|
+
super(*args)
|
38
|
+
else
|
39
|
+
self.class.curried.new(self, name: name, curry_args: args, arity: arity)
|
40
|
+
end
|
41
|
+
|
42
|
+
if block
|
43
|
+
response.instance_exec(&block)
|
44
|
+
else
|
45
|
+
response
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
auto_curried_methods << name
|
51
|
+
|
52
|
+
prepend(mod)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|