rom 2.0.2 → 5.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +122 -324
  3. data/LICENSE +17 -17
  4. data/README.md +91 -22
  5. data/lib/rom/version.rb +3 -1
  6. data/lib/rom.rb +4 -46
  7. metadata +42 -245
  8. data/.gitignore +0 -24
  9. data/.rspec +0 -3
  10. data/.rubocop.yml +0 -87
  11. data/.rubocop_todo.yml +0 -46
  12. data/.travis.yml +0 -28
  13. data/CODE_OF_CONDUCT.md +0 -13
  14. data/CONTRIBUTING.md +0 -1
  15. data/Gemfile +0 -41
  16. data/Guardfile +0 -24
  17. data/Rakefile +0 -22
  18. data/lib/rom/association_set.rb +0 -26
  19. data/lib/rom/command.rb +0 -173
  20. data/lib/rom/command_registry.rb +0 -153
  21. data/lib/rom/commands/class_interface.rb +0 -148
  22. data/lib/rom/commands/composite.rb +0 -54
  23. data/lib/rom/commands/create.rb +0 -13
  24. data/lib/rom/commands/delete.rb +0 -14
  25. data/lib/rom/commands/graph/builder.rb +0 -176
  26. data/lib/rom/commands/graph/class_interface.rb +0 -62
  27. data/lib/rom/commands/graph/input_evaluator.rb +0 -62
  28. data/lib/rom/commands/graph.rb +0 -103
  29. data/lib/rom/commands/lazy/create.rb +0 -23
  30. data/lib/rom/commands/lazy/delete.rb +0 -27
  31. data/lib/rom/commands/lazy/update.rb +0 -34
  32. data/lib/rom/commands/lazy.rb +0 -99
  33. data/lib/rom/commands/result.rb +0 -96
  34. data/lib/rom/commands/update.rb +0 -14
  35. data/lib/rom/commands.rb +0 -3
  36. data/lib/rom/configuration.rb +0 -88
  37. data/lib/rom/configuration_dsl/command.rb +0 -43
  38. data/lib/rom/configuration_dsl/command_dsl.rb +0 -35
  39. data/lib/rom/configuration_dsl/mapper.rb +0 -37
  40. data/lib/rom/configuration_dsl/mapper_dsl.rb +0 -44
  41. data/lib/rom/configuration_dsl/relation.rb +0 -26
  42. data/lib/rom/configuration_dsl.rb +0 -78
  43. data/lib/rom/configuration_plugin.rb +0 -17
  44. data/lib/rom/constants.rb +0 -30
  45. data/lib/rom/container.rb +0 -231
  46. data/lib/rom/create_container.rb +0 -61
  47. data/lib/rom/environment.rb +0 -70
  48. data/lib/rom/gateway.rb +0 -154
  49. data/lib/rom/global/plugin_dsl.rb +0 -49
  50. data/lib/rom/global.rb +0 -60
  51. data/lib/rom/lint/enumerable_dataset.rb +0 -54
  52. data/lib/rom/lint/gateway.rb +0 -94
  53. data/lib/rom/lint/linter.rb +0 -78
  54. data/lib/rom/lint/spec.rb +0 -20
  55. data/lib/rom/lint/test.rb +0 -98
  56. data/lib/rom/mapper_registry.rb +0 -35
  57. data/lib/rom/memory/commands.rb +0 -58
  58. data/lib/rom/memory/dataset.rb +0 -98
  59. data/lib/rom/memory/gateway.rb +0 -64
  60. data/lib/rom/memory/relation.rb +0 -49
  61. data/lib/rom/memory/storage.rb +0 -59
  62. data/lib/rom/memory/types.rb +0 -9
  63. data/lib/rom/memory.rb +0 -4
  64. data/lib/rom/pipeline.rb +0 -106
  65. data/lib/rom/plugin.rb +0 -17
  66. data/lib/rom/plugin_base.rb +0 -31
  67. data/lib/rom/plugin_registry.rb +0 -173
  68. data/lib/rom/plugins/command/schema.rb +0 -37
  69. data/lib/rom/plugins/configuration/configuration_dsl.rb +0 -17
  70. data/lib/rom/plugins/relation/key_inference.rb +0 -46
  71. data/lib/rom/plugins/relation/registry_reader.rb +0 -32
  72. data/lib/rom/plugins/relation/view/dsl.rb +0 -32
  73. data/lib/rom/plugins/relation/view.rb +0 -95
  74. data/lib/rom/relation/class_interface.rb +0 -230
  75. data/lib/rom/relation/composite.rb +0 -46
  76. data/lib/rom/relation/curried.rb +0 -104
  77. data/lib/rom/relation/graph.rb +0 -115
  78. data/lib/rom/relation/loaded.rb +0 -118
  79. data/lib/rom/relation/materializable.rb +0 -66
  80. data/lib/rom/relation/name.rb +0 -102
  81. data/lib/rom/relation.rb +0 -172
  82. data/lib/rom/relation_registry.rb +0 -9
  83. data/lib/rom/schema/dsl.rb +0 -58
  84. data/lib/rom/schema.rb +0 -89
  85. data/lib/rom/setup/auto_registration.rb +0 -69
  86. data/lib/rom/setup/auto_registration_strategies/base.rb +0 -11
  87. data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +0 -22
  88. data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +0 -19
  89. data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +0 -18
  90. data/lib/rom/setup/finalize/finalize_commands.rb +0 -47
  91. data/lib/rom/setup/finalize/finalize_mappers.rb +0 -36
  92. data/lib/rom/setup/finalize/finalize_relations.rb +0 -60
  93. data/lib/rom/setup/finalize.rb +0 -146
  94. data/lib/rom/setup.rb +0 -55
  95. data/lib/rom/support/configurable.rb +0 -80
  96. data/lib/rom/types.rb +0 -18
  97. data/log/.gitkeep +0 -0
  98. data/rakelib/benchmark.rake +0 -15
  99. data/rakelib/mutant.rake +0 -19
  100. data/rakelib/rubocop.rake +0 -18
  101. data/rom.gemspec +0 -26
  102. data/spec/fixtures/app/commands/create_user.rb +0 -2
  103. data/spec/fixtures/app/mappers/user_list.rb +0 -2
  104. data/spec/fixtures/app/my_commands/create_user.rb +0 -2
  105. data/spec/fixtures/app/my_mappers/user_list.rb +0 -2
  106. data/spec/fixtures/app/my_relations/users.rb +0 -2
  107. data/spec/fixtures/app/relations/users.rb +0 -2
  108. data/spec/fixtures/custom/commands/create_user.rb +0 -6
  109. data/spec/fixtures/custom/mappers/user_list.rb +0 -6
  110. data/spec/fixtures/custom/relations/users.rb +0 -6
  111. data/spec/fixtures/lib/persistence/commands/create_user.rb +0 -6
  112. data/spec/fixtures/lib/persistence/mappers/user_list.rb +0 -6
  113. data/spec/fixtures/lib/persistence/my_commands/create_user.rb +0 -6
  114. data/spec/fixtures/lib/persistence/my_mappers/user_list.rb +0 -6
  115. data/spec/fixtures/lib/persistence/my_relations/users.rb +0 -6
  116. data/spec/fixtures/lib/persistence/relations/users.rb +0 -6
  117. data/spec/integration/command_registry_spec.rb +0 -60
  118. data/spec/integration/commands/create_spec.rb +0 -177
  119. data/spec/integration/commands/delete_spec.rb +0 -67
  120. data/spec/integration/commands/error_handling_spec.rb +0 -25
  121. data/spec/integration/commands/graph_builder_spec.rb +0 -213
  122. data/spec/integration/commands/graph_spec.rb +0 -288
  123. data/spec/integration/commands/update_spec.rb +0 -109
  124. data/spec/integration/commands_spec.rb +0 -67
  125. data/spec/integration/mappers/combine_spec.rb +0 -117
  126. data/spec/integration/mappers/deep_embedded_spec.rb +0 -44
  127. data/spec/integration/mappers/definition_dsl_spec.rb +0 -206
  128. data/spec/integration/mappers/embedded_spec.rb +0 -62
  129. data/spec/integration/mappers/exclude_spec.rb +0 -27
  130. data/spec/integration/mappers/fold_spec.rb +0 -71
  131. data/spec/integration/mappers/group_spec.rb +0 -163
  132. data/spec/integration/mappers/overwrite_attributes_value_spec.rb +0 -51
  133. data/spec/integration/mappers/prefix_separator_spec.rb +0 -52
  134. data/spec/integration/mappers/prefix_spec.rb +0 -48
  135. data/spec/integration/mappers/prefixing_attributes_spec.rb +0 -37
  136. data/spec/integration/mappers/registering_custom_mappers_spec.rb +0 -28
  137. data/spec/integration/mappers/renaming_attributes_spec.rb +0 -125
  138. data/spec/integration/mappers/reusing_mappers_spec.rb +0 -43
  139. data/spec/integration/mappers/step_spec.rb +0 -119
  140. data/spec/integration/mappers/symbolizing_attributes_spec.rb +0 -77
  141. data/spec/integration/mappers/unfold_spec.rb +0 -92
  142. data/spec/integration/mappers/ungroup_spec.rb +0 -126
  143. data/spec/integration/mappers/unwrap_spec.rb +0 -93
  144. data/spec/integration/mappers/wrap_spec.rb +0 -155
  145. data/spec/integration/memory/commands/create_spec.rb +0 -23
  146. data/spec/integration/memory/commands/delete_spec.rb +0 -23
  147. data/spec/integration/memory/commands/update_spec.rb +0 -23
  148. data/spec/integration/multi_env_spec.rb +0 -69
  149. data/spec/integration/multi_repo_spec.rb +0 -46
  150. data/spec/integration/relations/default_dataset_spec.rb +0 -38
  151. data/spec/integration/relations/inheritance_spec.rb +0 -37
  152. data/spec/integration/relations/reading_spec.rb +0 -169
  153. data/spec/integration/relations/registry_dsl_spec.rb +0 -45
  154. data/spec/integration/repositories/extending_relations_spec.rb +0 -58
  155. data/spec/integration/repositories/setting_logger_spec.rb +0 -34
  156. data/spec/integration/setup_spec.rb +0 -160
  157. data/spec/shared/command_behavior.rb +0 -28
  158. data/spec/shared/command_graph.rb +0 -50
  159. data/spec/shared/container.rb +0 -9
  160. data/spec/shared/enumerable_dataset.rb +0 -52
  161. data/spec/shared/gateway_only.rb +0 -6
  162. data/spec/shared/materializable.rb +0 -36
  163. data/spec/shared/no_container.rb +0 -16
  164. data/spec/shared/one_behavior.rb +0 -26
  165. data/spec/shared/proxy.rb +0 -0
  166. data/spec/shared/users_and_tasks.rb +0 -10
  167. data/spec/spec_helper.rb +0 -52
  168. data/spec/support/constant_leak_finder.rb +0 -14
  169. data/spec/support/mutant.rb +0 -10
  170. data/spec/support/types.rb +0 -5
  171. data/spec/test/memory_repository_lint_test.rb +0 -27
  172. data/spec/unit/rom/association_set_spec.rb +0 -23
  173. data/spec/unit/rom/commands/graph_spec.rb +0 -191
  174. data/spec/unit/rom/commands/lazy_spec.rb +0 -307
  175. data/spec/unit/rom/commands/result_spec.rb +0 -70
  176. data/spec/unit/rom/commands_spec.rb +0 -165
  177. data/spec/unit/rom/configurable_spec.rb +0 -49
  178. data/spec/unit/rom/configuration_spec.rb +0 -61
  179. data/spec/unit/rom/container_spec.rb +0 -99
  180. data/spec/unit/rom/create_container_spec.rb +0 -151
  181. data/spec/unit/rom/environment_spec.rb +0 -123
  182. data/spec/unit/rom/gateway_spec.rb +0 -146
  183. data/spec/unit/rom/mapper_registry_spec.rb +0 -25
  184. data/spec/unit/rom/memory/commands_spec.rb +0 -43
  185. data/spec/unit/rom/memory/dataset_spec.rb +0 -31
  186. data/spec/unit/rom/memory/relation_spec.rb +0 -109
  187. data/spec/unit/rom/memory/repository_spec.rb +0 -12
  188. data/spec/unit/rom/memory/storage_spec.rb +0 -45
  189. data/spec/unit/rom/plugin_spec.rb +0 -150
  190. data/spec/unit/rom/plugins/command/schema_spec.rb +0 -66
  191. data/spec/unit/rom/plugins/relation/key_inference_spec.rb +0 -85
  192. data/spec/unit/rom/plugins/relation/view_spec.rb +0 -51
  193. data/spec/unit/rom/relation/composite_spec.rb +0 -89
  194. data/spec/unit/rom/relation/curried_spec.rb +0 -52
  195. data/spec/unit/rom/relation/graph_spec.rb +0 -92
  196. data/spec/unit/rom/relation/lazy/combine_spec.rb +0 -165
  197. data/spec/unit/rom/relation/lazy_spec.rb +0 -214
  198. data/spec/unit/rom/relation/loaded_spec.rb +0 -53
  199. data/spec/unit/rom/relation/name_spec.rb +0 -58
  200. data/spec/unit/rom/relation/schema_spec.rb +0 -117
  201. data/spec/unit/rom/relation_spec.rb +0 -237
  202. data/spec/unit/rom/schema_spec.rb +0 -10
  203. data/spec/unit/rom/setup/auto_registration_spec.rb +0 -152
data/.gitignore DELETED
@@ -1,24 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- coverage
6
- InstalledFiles
7
- lib/bundler/man
8
- pkg
9
- rdoc
10
- spec/reports
11
- test/tmp
12
- test/version_tmp
13
- tmp
14
- Gemfile.lock
15
- vendor/
16
- log/
17
-
18
- .idea/
19
-
20
- # YARD artifacts
21
- .yardoc
22
- _yardoc
23
- doc/
24
- .ruby-version
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --color
2
- --order random
3
- --require ./spec/spec_helper.rb
data/.rubocop.yml DELETED
@@ -1,87 +0,0 @@
1
- # Generated by `rubocop --auto-gen-config`
2
- inherit_from: .rubocop_todo.yml
3
-
4
- # Exclude temporary files
5
- AllCops:
6
- Exclude:
7
- - tmp/**/*
8
- - vendor/**/*
9
-
10
- Style/BlockDelimiters:
11
- EnforcedStyle: semantic
12
- FunctionalMethods:
13
- - let
14
- - let!
15
- - subject
16
- - watch
17
- - before
18
-
19
- # No need to handle LoadError in Rakefile
20
- Lint/HandleExceptions:
21
- Exclude:
22
- - rakelib/*.rake
23
- - spec/spec_helper.rb
24
- - benchmarks/setup.rb
25
-
26
- # gemspec is a special snowflake
27
- Metrics/LineLength:
28
- Exclude:
29
- - rom.gemspec
30
-
31
- # The enforced style doesn’t match Vim’s defaults
32
- Style/AlignParameters:
33
- Enabled: false
34
-
35
- # UTF-8 is perfectly fine in comments
36
- Style/AsciiComments:
37
- Enabled: false
38
-
39
- # Documentation checked by Inch CI
40
- Style/Documentation:
41
- Enabled: false
42
-
43
- # Early returns have their vices
44
- Style/GuardClause:
45
- Enabled: false
46
-
47
- # Need to be skipped for >-> usage
48
- Style/Lambda:
49
- Enabled: false
50
-
51
- # Multiline block chains are ok
52
- Style/MultilineBlockChain:
53
- Enabled: false
54
-
55
- # Multiline operation chains are indented
56
- Style/MultilineOperationIndentation:
57
- EnforcedStyle: indented
58
-
59
- # Result::Success and Result::Failure use > for callbacks
60
- Style/OpMethod:
61
- Exclude:
62
- - lib/rom/command_registry.rb
63
-
64
- # Don’t introduce semantic fail/raise distinction
65
- Style/SignalException:
66
- EnforcedStyle: only_raise
67
-
68
- # Need to be skipped for >-> usage
69
- Style/SpaceAroundOperators:
70
- Enabled: false
71
-
72
- # Accept both single and double quotes
73
- Style/StringLiterals:
74
- Enabled: false
75
-
76
- # Allow def self.foo; @foo; end
77
- Style/TrivialAccessors:
78
- Enabled: false
79
-
80
- # Allow compact style for specs
81
- Style/ClassAndModuleChildren:
82
- Exclude:
83
- - spec/**/*_spec.rb
84
-
85
- # Allow logical `or`/`and` in conditionals
86
- Style/AndOr:
87
- EnforcedStyle: conditionals
data/.rubocop_todo.yml DELETED
@@ -1,46 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2015-09-26 16:17:55 +0200 using RuboCop version 0.34.2.
4
- # The point is for the user to remove these configuration records
5
- # one by one as the offenses are removed from the code base.
6
- # Note that changes in the inspected code, or installation of new
7
- # versions of RuboCop, may require this file to be generated again.
8
-
9
- # Offense count: 3
10
- Lint/NestedMethodDefinition:
11
- Exclude:
12
- - 'lib/rom/relation/class_interface.rb'
13
- - 'spec/unit/rom/commands_spec.rb'
14
-
15
- # Offense count: 13
16
- Metrics/AbcSize:
17
- Max: 38
18
-
19
- # Offense count: 3
20
- Metrics/CyclomaticComplexity:
21
- Max: 9
22
-
23
- # Offense count: 65
24
- # Configuration parameters: AllowURI, URISchemes.
25
- Metrics/LineLength:
26
- Max: 113
27
-
28
- # Offense count: 20
29
- # Configuration parameters: CountComments.
30
- Metrics/MethodLength:
31
- Max: 42
32
-
33
- # Offense count: 3
34
- Metrics/PerceivedComplexity:
35
- Max: 11
36
-
37
- # Offense count: 1
38
- # Configuration parameters: EnforcedStyle, SupportedStyles.
39
- Style/MethodName:
40
- Enabled: false
41
-
42
- # Offense count: 1
43
- # Configuration parameters: Methods.
44
- Style/SingleLineBlockParams:
45
- Exclude:
46
- - 'lib/rom/commands/graph/class_interface.rb'
data/.travis.yml DELETED
@@ -1,28 +0,0 @@
1
- language: ruby
2
- dist: trusty
3
- sudo: required
4
- cache: bundler
5
- bundler_args: --without sql benchmarks console tools
6
- script: "bundle exec rake ci"
7
- after_success:
8
- - '[ "$TRAVIS_RUBY_VERSION" = "2.3.1" ] && [ "$TRAVIS_BRANCH" = "master" ] && bundle exec codeclimate-test-reporter'
9
- rvm:
10
- - 2.1
11
- - 2.2
12
- - 2.3.1
13
- - rbx-3
14
- - jruby-9.1.5.0
15
- env:
16
- global:
17
- - JRUBY_OPTS='--dev -J-Xmx1024M'
18
- - COVERAGE='true'
19
- matrix:
20
- allow_failures:
21
- - rvm: rbx-3
22
- notifications:
23
- webhooks:
24
- urls:
25
- - https://webhooks.gitter.im/e/39e1225f489f38b0bd09
26
- on_success: change
27
- on_failure: always
28
- on_start: false
data/CODE_OF_CONDUCT.md DELETED
@@ -1,13 +0,0 @@
1
- # Contributor Code of Conduct
2
-
3
- As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
-
5
- We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
-
7
- Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
-
9
- Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
-
11
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
-
13
- This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/CONTRIBUTING.md DELETED
@@ -1 +0,0 @@
1
- For information about contributing please refer to [Contribute](http://rom-rb.org/contribute) section on ROM website.
data/Gemfile DELETED
@@ -1,41 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- group :console do
6
- gem 'pry'
7
- gem 'pg', platforms: [:mri]
8
- end
9
-
10
- group :test do
11
- gem 'dry-equalizer'
12
- gem 'dry-struct'
13
- gem 'minitest'
14
- gem 'inflecto', '~> 0.0', '>= 0.0.2'
15
-
16
- platforms :mri do
17
- gem 'codeclimate-test-reporter', require: false
18
- gem 'simplecov', require: false
19
- end
20
-
21
- platforms :rbx do
22
- gem 'rubysl-bigdecimal'
23
- end
24
- end
25
-
26
- group :sql do
27
- gem 'rom-sql', github: 'rom-rb/rom-sql', branch: 'master'
28
- gem 'sequel'
29
- gem 'jdbc-sqlite3', platforms: :jruby
30
- gem 'sqlite3', platforms: [:mri, :rbx]
31
- end
32
-
33
- group :benchmarks do
34
- gem 'activerecord', '~> 5.0'
35
- gem 'benchmark-ips', '~> 2.2.0'
36
- gem 'rom-repository', github: 'rom-rb/rom-repository', branch: 'master'
37
- end
38
-
39
- group :tools do
40
- gem 'byebug', platform: :mri
41
- end
data/Guardfile DELETED
@@ -1,24 +0,0 @@
1
- group :red_green_refactor, halt_on_fail: true do
2
- guard :rspec, cmd: "rspec", all_on_start: true do
3
- # run all specs if Gemfile.lock is modified
4
- watch('Gemfile.lock') { 'spec' }
5
-
6
- # run all specs if any library code is modified
7
- watch(%r{\Alib/.+\.rb\z}) { 'spec' }
8
-
9
- # run all specs if supporting files are modified
10
- watch('spec/spec_helper.rb') { 'spec' }
11
- watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { 'spec' }
12
-
13
- # run a spec if it is modified
14
- watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z})
15
-
16
- notification :tmux, display_message: true if ENV.key?('TMUX')
17
- end
18
-
19
- guard :rubocop do
20
- # run rubocop on modified file
21
- watch(%r{\Alib/.+\.rb\z})
22
- watch(%r{\Aspec/.+\.rb\z})
23
- end
24
- end
data/Rakefile DELETED
@@ -1,22 +0,0 @@
1
- require "rspec/core/rake_task"
2
- require "rake/testtask"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
- task default: [:ci]
6
-
7
- desc 'Run specs in isolation'
8
- task :"spec:isolation" do
9
- FileList["spec/**/*_spec.rb"].each do |spec|
10
- sh "COVERAGE=false bundle exec rspec #{spec}"
11
- end
12
- end
13
-
14
- desc "Run CI tasks"
15
- task ci: [:spec, :lint, :"spec:isolation"]
16
-
17
- Rake::TestTask.new(:lint) do |test|
18
- test.description = "Run adapter lint tests against memory adapter"
19
- test.test_files = FileList.new('spec/test/*_test.rb')
20
- test.libs << 'test'
21
- test.verbose = true
22
- end
@@ -1,26 +0,0 @@
1
- require 'rom/support/registry'
2
- require 'rom/support/inflector'
3
-
4
- module ROM
5
- class AssociationSet < ROM::Registry
6
- # @api private
7
- def try(name, &block)
8
- if key?(name)
9
- yield(self[name])
10
- else
11
- false
12
- end
13
- end
14
-
15
- # @api private
16
- def [](name)
17
- key = name.to_sym
18
-
19
- if key?(key)
20
- super
21
- else
22
- super(Inflector.singularize(key))
23
- end
24
- end
25
- end
26
- end
data/lib/rom/command.rb DELETED
@@ -1,173 +0,0 @@
1
- require 'rom/support/deprecations'
2
- require 'rom/support/options'
3
- require 'rom/pipeline'
4
-
5
- require 'rom/commands/class_interface'
6
- require 'rom/commands/composite'
7
- require 'rom/commands/graph'
8
- require 'rom/commands/lazy'
9
-
10
- module ROM
11
- # Abstract command class
12
- #
13
- # Provides a constructor accepting relation with options and basic behavior
14
- # for calling, currying and composing commands.
15
- #
16
- # Typically command subclasses should inherit from specialized
17
- # Create/Update/Delete, not this one.
18
- #
19
- # @abstract
20
- #
21
- # @private
22
- class Command
23
- DEFAULT_VALIDATOR = proc {}
24
-
25
- include Dry::Equalizer(:relation, :options)
26
- include Commands
27
- include Pipeline::Operator
28
-
29
- extend ClassMacros
30
- extend ClassInterface
31
-
32
- include Options
33
-
34
- defines :adapter, :relation, :result, :input, :validator, :register_as, :restrictable
35
-
36
- option :type, allow: [:create, :update, :delete]
37
- option :source, reader: true
38
- option :result, reader: true, allow: [:one, :many]
39
- option :validator, reader: true
40
- option :input, reader: true
41
- option :curry_args, type: Array, reader: true, default: EMPTY_ARRAY
42
-
43
- input Hash
44
- validator DEFAULT_VALIDATOR
45
- result :many
46
-
47
- # @deprecated
48
- #
49
- # @api public
50
- def self.validator(vp = nil)
51
- if defined?(@validator) && vp.nil?
52
- @validator
53
- else
54
- unless vp.equal?(DEFAULT_VALIDATOR)
55
- Deprecations.announce(
56
- "#{name}.validator",
57
- 'Please handle validation before calling commands'
58
- )
59
- end
60
- super
61
- end
62
- end
63
-
64
- # @attr_reader [Relation] relation The command's relation
65
- attr_reader :relation
66
-
67
- # @api private
68
- def initialize(relation, options = EMPTY_HASH)
69
- super
70
- @relation = relation
71
- @source = options[:source] || relation
72
- end
73
-
74
- # Return name of this command's relation
75
- #
76
- # @return [ROM::Relation::Name]
77
- #
78
- # @api public
79
- def name
80
- relation.name
81
- end
82
-
83
- # Return gateway of this command's relation
84
- #
85
- # @return [Symbol]
86
- #
87
- # @api public
88
- def gateway
89
- relation.gateway
90
- end
91
-
92
- # Execute the command
93
- #
94
- # @abstract
95
- #
96
- # @return [Array] an array with inserted tuples
97
- #
98
- # @api private
99
- def execute(*)
100
- raise(
101
- NotImplementedError,
102
- "#{self.class}##{__method__} must be implemented"
103
- )
104
- end
105
-
106
- # Call the command and return one or many tuples
107
- #
108
- # @api public
109
- def call(*args, &block)
110
- tuples = execute(*(curry_args + args), &block)
111
-
112
- if one?
113
- tuples.first
114
- else
115
- tuples
116
- end
117
- end
118
- alias_method :[], :call
119
-
120
- # Curry this command with provided args
121
- #
122
- # Curried command can be called without args
123
- #
124
- # @return [Command]
125
- #
126
- # @api public
127
- def curry(*args)
128
- if curry_args.empty? && args.first.is_a?(Graph::InputEvaluator)
129
- Lazy[self].new(self, *args)
130
- else
131
- self.class.build(relation, options.merge(curry_args: args))
132
- end
133
- end
134
- alias_method :with, :curry
135
-
136
- # @api public
137
- def combine(*others)
138
- Graph.new(self, others)
139
- end
140
-
141
- # @api private
142
- def lazy?
143
- false
144
- end
145
-
146
- # @api private
147
- def graph?
148
- false
149
- end
150
-
151
- # @api private
152
- def one?
153
- result.equal?(:one)
154
- end
155
-
156
- # @api private
157
- def many?
158
- result.equal?(:many)
159
- end
160
-
161
- # @api private
162
- def new(new_relation)
163
- self.class.build(new_relation, options.merge(source: relation))
164
- end
165
-
166
- private
167
-
168
- # @api private
169
- def composite_class
170
- Command::Composite
171
- end
172
- end
173
- end
@@ -1,153 +0,0 @@
1
- require 'rom/commands/result'
2
-
3
- module ROM
4
- # Specialized registry class for commands
5
- #
6
- # @api public
7
- class CommandRegistry
8
- include Commands
9
- include Options
10
-
11
- CommandNotFoundError = Class.new(KeyError)
12
-
13
- # Name of the relation from which commands are under
14
- #
15
- # @return [String]
16
- #
17
- # @api private
18
- attr_reader :relation_name
19
-
20
- # Internal command registry
21
- #
22
- # @return [Registry]
23
- #
24
- # @api private
25
- attr_reader :registry
26
-
27
- option :mappers, reader: true
28
- option :mapper, reader: true
29
-
30
- # @api private
31
- def initialize(relation_name, elements, options = EMPTY_HASH)
32
- super
33
-
34
- @relation_name = relation_name
35
- @registry =
36
- if elements.is_a?(Registry)
37
- elements
38
- else
39
- Registry.new(elements, self.class.name)
40
- end
41
- end
42
-
43
- # Try to execute a command in a block
44
- #
45
- # @yield [command] Passes command to the block
46
- #
47
- # @example
48
- #
49
- # rom.command(:users).try { create(name: 'Jane') }
50
- # rom.command(:users).try { update(:by_id, 1).call(name: 'Jane Doe') }
51
- # rom.command(:users).try { delete(:by_id, 1) }
52
- #
53
- # @return [Commands::Result]
54
- #
55
- # @api public
56
- def try(&block)
57
- response = block.call
58
-
59
- if response.is_a?(Command) || response.is_a?(Composite)
60
- try { response.call }
61
- else
62
- Result::Success.new(response)
63
- end
64
- rescue CommandError => e
65
- Result::Failure.new(e)
66
- end
67
-
68
- # Return a command from the registry
69
- #
70
- # If mapper is set command will be turned into a composite command with
71
- # auto-mapping
72
- #
73
- # @example
74
- # create_user = rom.command(:users)[:create]
75
- # create_user[name: 'Jane']
76
- #
77
- # # with mapping, assuming :entity mapper is registered for :users relation
78
- # create_user = rom.command(:users).as(:entity)[:create]
79
- # create_user[name: 'Jane'] # => result is send through :entity mapper
80
- #
81
- # @param [Symbol] name The name of a registered command
82
- #
83
- # @return [Command,Command::Composite]
84
- #
85
- # @api public
86
- def [](name)
87
- command = fetch_command(name)
88
- mapper = options[:mapper]
89
-
90
- if mapper
91
- command.curry >> mapper
92
- else
93
- command
94
- end
95
- end
96
-
97
- # Specify a mapper that should be used for commands from this registry
98
- #
99
- # @example
100
- # entity_commands = rom.command(:users).as(:entity)
101
- #
102
- #
103
- # @param [Symbol] mapper_name The name of a registered mapper
104
- #
105
- # @return [CommandRegistry]
106
- #
107
- # @api public
108
- def as(mapper_name)
109
- with(mapper: mappers[mapper_name])
110
- end
111
-
112
- # Return new instance of this registry with updated options
113
- #
114
- # @return [CommandRegistry]
115
- #
116
- # @api private
117
- def with(new_options)
118
- self.class.new(relation_name, registry, options.merge(new_options))
119
- end
120
-
121
- private
122
-
123
- # Fetch a command from the registry and raise a specialized error
124
- # in case the command is not found
125
- #
126
- # @api private
127
- def fetch_command(name)
128
- registry.fetch(name) do
129
- raise CommandNotFoundError.new(
130
- "There is no :#{name} command for :#{relation_name} relation"
131
- )
132
- end
133
- end
134
-
135
- # Allow checking if a certain command is available using dot-notation
136
- #
137
- # @api private
138
- def respond_to_missing?(name, include_private = false)
139
- registry.key?(name) || super
140
- end
141
-
142
- # Allow retrieving commands using dot-notation
143
- #
144
- # @api private
145
- def method_missing(name, *)
146
- if registry.key?(name)
147
- self[name]
148
- else
149
- super
150
- end
151
- end
152
- end
153
- end