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
@@ -1,95 +0,0 @@
|
|
1
|
-
require 'rom/plugins/relation/view/dsl'
|
2
|
-
|
3
|
-
module ROM
|
4
|
-
module Plugins
|
5
|
-
module Relation
|
6
|
-
module View
|
7
|
-
def self.included(klass)
|
8
|
-
super
|
9
|
-
|
10
|
-
klass.class_eval do
|
11
|
-
extend ClassInterface
|
12
|
-
|
13
|
-
option :view, reader: true
|
14
|
-
option :attributes
|
15
|
-
|
16
|
-
def self.attributes
|
17
|
-
@__attributes__ ||= {}
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# Return column names that will be selected for this relation
|
23
|
-
#
|
24
|
-
# By default we use dataset columns but first we look at configured
|
25
|
-
# attributes by `view` DSL
|
26
|
-
#
|
27
|
-
# @return [Array<Symbol>]
|
28
|
-
#
|
29
|
-
# @api private
|
30
|
-
def attributes(view_name = view)
|
31
|
-
if options.key?(:attributes)
|
32
|
-
options[:attributes]
|
33
|
-
else
|
34
|
-
header = self.class.attributes
|
35
|
-
.fetch(view_name, self.class.attributes.fetch(:base))
|
36
|
-
|
37
|
-
if header.is_a?(Proc)
|
38
|
-
instance_exec(&header)
|
39
|
-
else
|
40
|
-
header
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
module ClassInterface
|
46
|
-
# Define a relation view with a specific header
|
47
|
-
#
|
48
|
-
# With headers defined all the mappers will be inferred automatically
|
49
|
-
#
|
50
|
-
# @example
|
51
|
-
# class Users < ROM::Relation[:sql]
|
52
|
-
# view(:by_name, [:id, :name]) do |name|
|
53
|
-
# where(name: name)
|
54
|
-
# end
|
55
|
-
#
|
56
|
-
# view(:listing, [:id, :name, :email]) do
|
57
|
-
# select(:id, :name, :email).order(:name)
|
58
|
-
# end
|
59
|
-
# end
|
60
|
-
#
|
61
|
-
# @api public
|
62
|
-
def view(*args, &block)
|
63
|
-
if args.size == 1 && block.arity > 0
|
64
|
-
raise ArgumentError, "header must be set as second argument"
|
65
|
-
end
|
66
|
-
|
67
|
-
name, names, relation_block =
|
68
|
-
if args.size == 1
|
69
|
-
DSL.new(*args, &block).call
|
70
|
-
else
|
71
|
-
[*args, block]
|
72
|
-
end
|
73
|
-
|
74
|
-
attributes[name] = names
|
75
|
-
|
76
|
-
if relation_block.arity > 0
|
77
|
-
auto_curry_guard do
|
78
|
-
define_method(name, &relation_block)
|
79
|
-
auto_curry(name) { with(view: name) }
|
80
|
-
end
|
81
|
-
else
|
82
|
-
define_method(name) do
|
83
|
-
instance_exec(&relation_block).with(view: name)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
ROM.plugins do
|
94
|
-
register :view, ROM::Plugins::Relation::View, type: :relation
|
95
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'rom'
|
2
|
-
require 'rom/memory'
|
3
|
-
require 'rom/plugins/relation/view'
|
4
|
-
|
5
|
-
RSpec.describe ROM::Plugins::Relation::View do
|
6
|
-
subject(:relation) { relation_class.new([]) }
|
7
|
-
|
8
|
-
let(:relation_class) do
|
9
|
-
Class.new(ROM::Memory::Relation) do
|
10
|
-
use :view
|
11
|
-
|
12
|
-
view(:base, [:id, :name]) do
|
13
|
-
self
|
14
|
-
end
|
15
|
-
|
16
|
-
view(:ids, [:id]) do
|
17
|
-
self
|
18
|
-
end
|
19
|
-
|
20
|
-
view(:names, [:name]) do |id|
|
21
|
-
self
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe '#attributes' do
|
27
|
-
it 'returns base view attributes by default' do
|
28
|
-
expect(relation.attributes).to eql([:id, :name])
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'returns attributes for a view' do
|
32
|
-
expect(relation.ids.attributes).to eql([:id])
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'returns attributes for a view with args' do
|
36
|
-
expect(relation.names(1).attributes).to eql([:name])
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'returns attributes for a curried view' do
|
40
|
-
expect(relation.names.attributes).to eql([:name])
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'returns correct arity for a curried view' do
|
44
|
-
expect(relation.names.arity).to be(1)
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'returns explicitly set attributes' do
|
48
|
-
expect(relation.with(attributes: [:foo, :bar]).attributes).to eql([:foo, :bar])
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|