rom 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -1
  3. data/.travis.yml +5 -3
  4. data/CHANGELOG.md +38 -0
  5. data/Gemfile +2 -14
  6. data/README.md +11 -17
  7. data/lib/rom.rb +2 -0
  8. data/lib/rom/association_set.rb +26 -0
  9. data/lib/rom/command.rb +50 -45
  10. data/lib/rom/command_registry.rb +26 -3
  11. data/lib/rom/commands/class_interface.rb +52 -19
  12. data/lib/rom/commands/composite.rb +5 -0
  13. data/lib/rom/commands/delete.rb +1 -5
  14. data/lib/rom/commands/graph.rb +11 -0
  15. data/lib/rom/commands/lazy.rb +2 -0
  16. data/lib/rom/commands/update.rb +1 -5
  17. data/lib/rom/configuration.rb +2 -0
  18. data/lib/rom/container.rb +3 -3
  19. data/lib/rom/global.rb +1 -23
  20. data/lib/rom/memory/commands.rb +2 -0
  21. data/lib/rom/memory/relation.rb +3 -0
  22. data/lib/rom/memory/storage.rb +4 -7
  23. data/lib/rom/memory/types.rb +9 -0
  24. data/lib/rom/pipeline.rb +26 -12
  25. data/lib/rom/plugin_registry.rb +2 -2
  26. data/lib/rom/plugins/command/schema.rb +26 -0
  27. data/lib/rom/plugins/configuration/configuration_dsl.rb +2 -1
  28. data/lib/rom/plugins/relation/key_inference.rb +18 -3
  29. data/lib/rom/plugins/relation/registry_reader.rb +3 -1
  30. data/lib/rom/plugins/relation/view.rb +11 -6
  31. data/lib/rom/relation.rb +76 -16
  32. data/lib/rom/relation/class_interface.rb +44 -3
  33. data/lib/rom/relation/curried.rb +13 -4
  34. data/lib/rom/relation/graph.rb +15 -5
  35. data/lib/rom/relation/loaded.rb +42 -6
  36. data/lib/rom/relation/name.rb +102 -0
  37. data/lib/rom/relation_registry.rb +5 -0
  38. data/lib/rom/schema.rb +87 -0
  39. data/lib/rom/schema/dsl.rb +58 -0
  40. data/lib/rom/setup/auto_registration.rb +2 -2
  41. data/lib/rom/setup/finalize.rb +5 -5
  42. data/lib/rom/setup/finalize/{commands.rb → finalize_commands.rb} +2 -22
  43. data/lib/rom/setup/finalize/{mappers.rb → finalize_mappers.rb} +0 -0
  44. data/lib/rom/setup/finalize/finalize_relations.rb +60 -0
  45. data/lib/rom/types.rb +18 -0
  46. data/lib/rom/version.rb +1 -1
  47. data/log/.gitkeep +0 -0
  48. data/rom.gemspec +4 -2
  49. data/spec/integration/command_registry_spec.rb +13 -0
  50. data/spec/integration/commands/delete_spec.rb +0 -17
  51. data/spec/integration/commands/graph_builder_spec.rb +1 -1
  52. data/spec/integration/commands/graph_spec.rb +1 -1
  53. data/spec/integration/commands/update_spec.rb +0 -19
  54. data/spec/integration/commands_spec.rb +10 -3
  55. data/spec/integration/multi_repo_spec.rb +1 -1
  56. data/spec/integration/relations/default_dataset_spec.rb +27 -4
  57. data/spec/integration/setup_spec.rb +1 -4
  58. data/spec/shared/command_behavior.rb +17 -7
  59. data/spec/shared/container.rb +2 -2
  60. data/spec/shared/gateway_only.rb +1 -1
  61. data/spec/spec_helper.rb +5 -6
  62. data/spec/unit/rom/association_set_spec.rb +23 -0
  63. data/spec/unit/rom/auto_registration_spec.rb +1 -1
  64. data/spec/unit/rom/commands/lazy_spec.rb +8 -0
  65. data/spec/unit/rom/commands_spec.rb +45 -7
  66. data/spec/unit/rom/configurable_spec.rb +1 -1
  67. data/spec/unit/rom/container_spec.rb +6 -0
  68. data/spec/unit/rom/create_container_spec.rb +1 -1
  69. data/spec/unit/rom/environment_spec.rb +1 -1
  70. data/spec/unit/rom/memory/commands_spec.rb +43 -0
  71. data/spec/unit/rom/plugins/relation/key_inference_spec.rb +70 -12
  72. data/spec/unit/rom/plugins/relation/view_spec.rb +4 -0
  73. data/spec/unit/rom/relation/graph_spec.rb +10 -0
  74. data/spec/unit/rom/relation/lazy_spec.rb +3 -3
  75. data/spec/unit/rom/relation/loaded_spec.rb +15 -0
  76. data/spec/unit/rom/relation/name_spec.rb +51 -0
  77. data/spec/unit/rom/relation/schema_spec.rb +117 -0
  78. data/spec/unit/rom/relation_spec.rb +37 -7
  79. data/spec/unit/rom/schema_spec.rb +10 -0
  80. metadata +51 -12
  81. data/lib/rom/setup/finalize/relations.rb +0 -53
  82. data/spec/unit/rom/global_spec.rb +0 -18
  83. data/spec/unit/rom/registry_spec.rb +0 -38
@@ -1,53 +0,0 @@
1
- require 'rom/relation_registry'
2
-
3
- module ROM
4
- class Finalize
5
- class FinalizeRelations
6
- # Build relation registry of specified descendant classes
7
- #
8
- # This is used by the setup
9
- #
10
- # @param [Hash] gateways
11
- # @param [Array] relation_classes a list of relation descendants
12
- #
13
- # @api private
14
- def initialize(gateways, relation_classes)
15
- @gateways = gateways
16
- @relation_classes = relation_classes
17
- end
18
-
19
- # @return [Hash]
20
- #
21
- # @api private
22
- def run!
23
- registry = {}
24
-
25
- @relation_classes.each do |klass|
26
- # TODO: raise a meaningful error here and add spec covering the case
27
- # where klass' gateway points to non-existant repo
28
- gateway = @gateways.fetch(klass.gateway)
29
- ds_proc = klass.dataset_proc || -> { self }
30
- dataset = gateway.dataset(klass.dataset).instance_exec(&ds_proc)
31
-
32
- relation = klass.new(dataset, __registry__: registry)
33
-
34
- name = klass.register_as
35
-
36
- if registry.key?(name)
37
- raise RelationAlreadyDefinedError,
38
- "Relation with `register_as #{name.inspect}` registered more " \
39
- "than once"
40
- end
41
-
42
- registry[name] = relation
43
- end
44
-
45
- registry.each_value do |relation|
46
- relation.class.finalize(registry, relation)
47
- end
48
-
49
- RelationRegistry.new(registry)
50
- end
51
- end
52
- end
53
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ROM do
4
- include_context 'container'
5
-
6
- describe '.env' do
7
- it 'is nil by default' do
8
- container
9
-
10
- expect(ROM.env).to be(nil)
11
- end
12
-
13
- it 'is assignable' do
14
- ROM.env = container
15
- expect(ROM.env).to be(container)
16
- end
17
- end
18
- end
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ROM::Registry do
4
- subject(:registry) { registry_class.new(mars: mars) }
5
-
6
- let(:mars) { double('mars') }
7
-
8
- let(:registry_class) do
9
- Class.new(ROM::Registry) do
10
- def self.name
11
- 'Candy'
12
- end
13
- end
14
- end
15
-
16
- describe '#fetch' do
17
- it 'returns registered elemented identified by name' do
18
- expect(registry[:mars]).to be(mars)
19
- end
20
-
21
- it 'raises error when element is not found' do
22
- expect { registry[:twix] }.to raise_error(
23
- ROM::Registry::ElementNotFoundError,
24
- ":twix doesn't exist in Candy registry"
25
- )
26
- end
27
- end
28
-
29
- describe '.element_name' do
30
- it 'returns registered elemented identified by element_name' do
31
- expect(registry[:mars]).to be(mars)
32
- end
33
-
34
- it 'raises no-method error when element is not there' do
35
- expect { registry.twix }.to raise_error(NoMethodError)
36
- end
37
- end
38
- end