rom 0.5.0 → 0.6.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +19 -15
- data/.rubocop_todo.yml +28 -0
- data/.travis.yml +8 -1
- data/CHANGELOG.md +40 -0
- data/Gemfile +10 -2
- data/Guardfile +12 -10
- data/README.md +42 -43
- data/Rakefile +13 -23
- data/lib/rom.rb +19 -27
- data/lib/rom/command.rb +118 -0
- data/lib/rom/command_registry.rb +13 -27
- data/lib/rom/commands.rb +1 -59
- data/lib/rom/commands/abstract.rb +147 -0
- data/lib/rom/commands/composite.rb +47 -0
- data/lib/rom/commands/create.rb +2 -17
- data/lib/rom/commands/delete.rb +5 -25
- data/lib/rom/commands/result.rb +5 -5
- data/lib/rom/commands/update.rb +3 -27
- data/lib/rom/constants.rb +19 -0
- data/lib/rom/env.rb +85 -35
- data/lib/rom/global.rb +173 -42
- data/lib/rom/header.rb +5 -5
- data/lib/rom/header/attribute.rb +2 -2
- data/lib/rom/lint/enumerable_dataset.rb +52 -0
- data/lib/rom/lint/linter.rb +64 -0
- data/lib/rom/lint/repository.rb +78 -0
- data/lib/rom/lint/spec.rb +20 -0
- data/lib/rom/lint/test.rb +98 -0
- data/lib/rom/mapper.rb +32 -5
- data/lib/rom/mapper/attribute_dsl.rb +240 -0
- data/lib/rom/mapper/dsl.rb +100 -0
- data/lib/rom/mapper/model_dsl.rb +55 -0
- data/lib/rom/mapper_registry.rb +8 -1
- data/lib/rom/memory.rb +4 -0
- data/lib/rom/memory/commands.rb +46 -0
- data/lib/rom/memory/dataset.rb +72 -0
- data/lib/rom/memory/relation.rb +44 -0
- data/lib/rom/memory/repository.rb +62 -0
- data/lib/rom/memory/storage.rb +57 -0
- data/lib/rom/model_builder.rb +44 -5
- data/lib/rom/processor.rb +1 -1
- data/lib/rom/processor/transproc.rb +109 -16
- data/lib/rom/reader.rb +91 -39
- data/lib/rom/relation.rb +165 -26
- data/lib/rom/relation/composite.rb +132 -0
- data/lib/rom/relation/curried.rb +48 -0
- data/lib/rom/relation/lazy.rb +173 -0
- data/lib/rom/relation/loaded.rb +75 -0
- data/lib/rom/relation/registry_reader.rb +23 -0
- data/lib/rom/repository.rb +93 -34
- data/lib/rom/setup.rb +54 -98
- data/lib/rom/setup/finalize.rb +85 -76
- data/lib/rom/setup_dsl/command.rb +36 -0
- data/lib/rom/setup_dsl/command_dsl.rb +34 -0
- data/lib/rom/setup_dsl/mapper.rb +32 -0
- data/lib/rom/setup_dsl/mapper_dsl.rb +30 -0
- data/lib/rom/setup_dsl/relation.rb +21 -0
- data/lib/rom/setup_dsl/setup.rb +75 -0
- data/lib/rom/support/array_dataset.rb +38 -0
- data/lib/rom/support/class_builder.rb +44 -0
- data/lib/rom/support/class_macros.rb +56 -0
- data/lib/rom/support/data_proxy.rb +102 -0
- data/lib/rom/support/enumerable_dataset.rb +58 -0
- data/lib/rom/support/inflector.rb +73 -0
- data/lib/rom/support/options.rb +188 -0
- data/lib/rom/support/registry.rb +4 -8
- data/lib/rom/version.rb +1 -1
- data/rakelib/benchmark.rake +13 -0
- data/rakelib/mutant.rake +16 -0
- data/rakelib/rubocop.rake +18 -0
- data/rom.gemspec +4 -7
- data/spec/integration/commands/create_spec.rb +32 -24
- data/spec/integration/commands/delete_spec.rb +15 -7
- data/spec/integration/commands/update_spec.rb +13 -11
- data/spec/integration/mappers/deep_embedded_spec.rb +4 -11
- data/spec/integration/mappers/definition_dsl_spec.rb +31 -44
- data/spec/integration/mappers/embedded_spec.rb +9 -24
- data/spec/integration/mappers/group_spec.rb +22 -30
- data/spec/integration/mappers/prefixing_attributes_spec.rb +18 -23
- data/spec/integration/mappers/renaming_attributes_spec.rb +23 -38
- data/spec/integration/mappers/symbolizing_attributes_spec.rb +18 -24
- data/spec/integration/mappers/wrap_spec.rb +22 -30
- data/spec/integration/multi_repo_spec.rb +15 -37
- data/spec/integration/relations/reading_spec.rb +82 -14
- data/spec/integration/repositories/extending_relations_spec.rb +50 -0
- data/spec/integration/{adapters → repositories}/setting_logger_spec.rb +6 -5
- data/spec/integration/setup_spec.rb +59 -62
- data/spec/shared/enumerable_dataset.rb +49 -0
- data/spec/shared/one_behavior.rb +26 -0
- data/spec/shared/users_and_tasks.rb +11 -23
- data/spec/spec_helper.rb +16 -7
- data/spec/support/constant_leak_finder.rb +14 -0
- data/spec/test/memory_repository_lint_test.rb +27 -0
- data/spec/unit/rom/command_registry_spec.rb +44 -0
- data/spec/unit/rom/commands/result_spec.rb +14 -0
- data/spec/unit/rom/commands_spec.rb +174 -0
- data/spec/unit/rom/env_spec.rb +40 -7
- data/spec/unit/rom/global_spec.rb +14 -0
- data/spec/unit/rom/{mapper_builder_spec.rb → mapper/dsl_spec.rb} +52 -38
- data/spec/unit/rom/mapper_spec.rb +51 -10
- data/spec/unit/rom/{adapter/memory → memory}/dataset_spec.rb +6 -4
- data/spec/unit/rom/memory/repository_spec.rb +12 -0
- data/spec/unit/rom/memory/storage_spec.rb +45 -0
- data/spec/unit/rom/model_builder_spec.rb +4 -3
- data/spec/unit/rom/processor/transproc_spec.rb +1 -0
- data/spec/unit/rom/reader_spec.rb +97 -24
- data/spec/unit/rom/relation/composite_spec.rb +65 -0
- data/spec/unit/rom/relation/lazy_spec.rb +145 -0
- data/spec/unit/rom/relation/loaded_spec.rb +28 -0
- data/spec/unit/rom/relation_spec.rb +111 -6
- data/spec/unit/rom/repository_spec.rb +59 -9
- data/spec/unit/rom/setup_spec.rb +99 -11
- data/spec/unit/rom/support/array_dataset_spec.rb +59 -0
- data/spec/unit/rom/support/class_builder_spec.rb +42 -0
- data/spec/unit/rom/support/enumerable_dataset_spec.rb +17 -0
- data/spec/unit/rom/support/inflector_spec.rb +89 -0
- data/spec/unit/rom/support/options_spec.rb +119 -0
- metadata +74 -112
- data/lib/rom/adapter.rb +0 -191
- data/lib/rom/adapter/memory.rb +0 -32
- data/lib/rom/adapter/memory/commands.rb +0 -31
- data/lib/rom/adapter/memory/dataset.rb +0 -67
- data/lib/rom/adapter/memory/storage.rb +0 -26
- data/lib/rom/commands/with_options.rb +0 -18
- data/lib/rom/config.rb +0 -70
- data/lib/rom/mapper_builder.rb +0 -52
- data/lib/rom/mapper_builder/mapper_dsl.rb +0 -114
- data/lib/rom/mapper_builder/model_dsl.rb +0 -29
- data/lib/rom/reader_builder.rb +0 -48
- data/lib/rom/relation_builder.rb +0 -62
- data/lib/rom/setup/base_relation_dsl.rb +0 -46
- data/lib/rom/setup/command_dsl.rb +0 -46
- data/lib/rom/setup/mapper_dsl.rb +0 -19
- data/lib/rom/setup/relation_dsl.rb +0 -20
- data/lib/rom/setup/schema_dsl.rb +0 -33
- data/spec/integration/adapters/extending_relations_spec.rb +0 -41
- data/spec/integration/commands/try_spec.rb +0 -27
- data/spec/integration/schema_spec.rb +0 -77
- data/spec/unit/config_spec.rb +0 -60
- data/spec/unit/rom/adapter_spec.rb +0 -79
- data/spec/unit/rom_spec.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 814ed4ee8e88aefe0b86817fb61169b1e35f94ba
|
4
|
+
data.tar.gz: 999033f0c7c9afb931cf8cb18a333026e8b3efae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fac52ead0bcbbe6c2404b59b8520facb25374050e8dbf6d98964aab073896fe8dca05f589d91ad34769f169ca284006f14685d2b4808e18571794bf0a8fd635c
|
7
|
+
data.tar.gz: 866166744b5e93f3fca5c623414579814efd7d6765d2cc695af3437e3b233f720e52f403f7f98b9cb288bc548e45e015f6ab3035692a4a05f57e6bdcbc893d69
|
data/.rubocop.yml
CHANGED
@@ -1,29 +1,24 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
Max: 27
|
1
|
+
# Generated by `rubocop --auto-gen-config`
|
2
|
+
inherit_from: .rubocop_todo.yml
|
4
3
|
|
5
|
-
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
# FIXME: Lower by refactoring biggest offenders
|
10
|
-
Metrics/PerceivedComplexity:
|
11
|
-
Max: 8
|
4
|
+
# Exclude temporary files
|
5
|
+
AllCops:
|
6
|
+
Exclude:
|
7
|
+
- tmp/**/*
|
12
8
|
|
13
9
|
# It’s quite readable when we know what we are doing
|
14
10
|
Lint/AssignmentInCondition:
|
15
11
|
Enabled: false
|
16
12
|
|
13
|
+
# No need to handle LoadError in Rakefile
|
17
14
|
Lint/HandleExceptions:
|
18
15
|
Exclude:
|
19
|
-
-
|
20
|
-
|
21
|
-
|
22
|
-
Max: 120
|
16
|
+
- rakelib/*.rake
|
17
|
+
- spec/spec_helper.rb
|
18
|
+
- benchmarks/setup.rb
|
23
19
|
|
24
20
|
# gemspec is a special snowflake
|
25
21
|
Metrics/LineLength:
|
26
|
-
Max: 84
|
27
22
|
Exclude:
|
28
23
|
- rom.gemspec
|
29
24
|
|
@@ -79,3 +74,12 @@ Style/StringLiterals:
|
|
79
74
|
# Allow def self.foo; @foo; end
|
80
75
|
Style/TrivialAccessors:
|
81
76
|
Enabled: false
|
77
|
+
|
78
|
+
# Allow compact style for specs
|
79
|
+
Style/ClassAndModuleChildren:
|
80
|
+
Exclude:
|
81
|
+
- spec/**/*_spec.rb
|
82
|
+
|
83
|
+
# Allow logical `or`/`and` in conditionals
|
84
|
+
Style/AndOr:
|
85
|
+
EnforcedStyle: conditionals
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2015-02-26 16:54:42 +0100 using RuboCop version 0.29.1.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
# Offense count: 4
|
9
|
+
Metrics/AbcSize:
|
10
|
+
Max: 22
|
11
|
+
|
12
|
+
# Offense count: 1
|
13
|
+
Metrics/CyclomaticComplexity:
|
14
|
+
Max: 7
|
15
|
+
|
16
|
+
# Offense count: 40
|
17
|
+
# Configuration parameters: AllowURI, URISchemes.
|
18
|
+
Metrics/LineLength:
|
19
|
+
Max: 88
|
20
|
+
|
21
|
+
# Offense count: 15
|
22
|
+
# Configuration parameters: CountComments.
|
23
|
+
Metrics/MethodLength:
|
24
|
+
Max: 21
|
25
|
+
|
26
|
+
# Offense count: 1
|
27
|
+
Metrics/PerceivedComplexity:
|
28
|
+
Max: 10
|
data/.travis.yml
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
language: ruby
|
2
|
+
sudo: false
|
3
|
+
cache: bundler
|
2
4
|
env:
|
3
5
|
- CODECLIMATE_REPO_TOKEN=f7c652b65a700fcf1032174afc5ea243b991e48bf73077cc34c148e1c800a2f7
|
4
6
|
bundler_args: --without sql benchmarks console tools
|
5
|
-
script: "bundle exec rake
|
7
|
+
script: "bundle exec rake ci"
|
6
8
|
rvm:
|
7
9
|
- 2.0
|
8
10
|
- 2.1
|
@@ -10,9 +12,14 @@ rvm:
|
|
10
12
|
- rbx-2
|
11
13
|
- jruby
|
12
14
|
- ruby-head
|
15
|
+
- jruby-head
|
16
|
+
env:
|
17
|
+
global:
|
18
|
+
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
13
19
|
matrix:
|
14
20
|
allow_failures:
|
15
21
|
- rvm: ruby-head
|
22
|
+
- rvm: jruby-head
|
16
23
|
notifications:
|
17
24
|
webhooks:
|
18
25
|
urls:
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,43 @@
|
|
1
|
+
## v0.6.0 to-be-released
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
* It is now possible to define custom relation, mapper and command classes during setup (solnic)
|
6
|
+
* New `Env#relation` interface for reading and mapping relations which supports:
|
7
|
+
* `Relation::Lazy` with auto-currying, mapping and composition features (solnic)
|
8
|
+
* `Relation::Composite` allowing data-pipelining with arbitrary objects (solnic)
|
9
|
+
* Passing a block which yields relation with adapter query DSL available (solnic)
|
10
|
+
* Relations can be extended with plugins using Options API (solnic)
|
11
|
+
* Commands are now composable via `>>` operator (solnic)
|
12
|
+
* Mappers support `prefix_separator` option (solnic)
|
13
|
+
* Mappers can be registered under custom names (solnic)
|
14
|
+
* Relation `dataset` name is inferred from the class name by default (gotar)
|
15
|
+
* Relation can be registered under a custom name via `register_as` option (mcls)
|
16
|
+
* Adapters can use helper modules for datasets: `ArrayDataset` and `EnumerableDataset` (solnic)
|
17
|
+
* Adapter interface can now be tested via a lint test (elskwid + solnic + splattael)
|
18
|
+
* `tuple_count` interface in AbstractCommand which can be overridden by adapter (solnic)
|
19
|
+
* Custom Inflector API that auto-detects a specific inflection engine (mjtko)
|
20
|
+
|
21
|
+
### Changed
|
22
|
+
|
23
|
+
* [BREAKING] Command API was simplified - commands should be accessed directly in `.try` block (solnic)
|
24
|
+
* [BREAKING] Schema DSL was **removed** - attributes can be specified only in mapper DSL
|
25
|
+
and default repository can be changed when defining a relation (solnic)
|
26
|
+
* `.setup` interface requires either an adapter identifier or can accept a repository
|
27
|
+
instance (aflatter)
|
28
|
+
* Adapter interface no longer requires specific constructor to be defined (aflatter)
|
29
|
+
* Adapters no longer need to handle connection URIs (aflatter)
|
30
|
+
* Adapter/Repository has been collapsed to *just* `Repository` (solnic)
|
31
|
+
* Relation no longer needs a header object and only operates on an adapters dataset (solnic)
|
32
|
+
* Relation no longer uses on Charlatan with method_missing magic (solnic)
|
33
|
+
* Adapter's dataset no longer requires header (solnic)
|
34
|
+
* Make storage in memory adapter thread-safe #110 (splattael)
|
35
|
+
* An Adapter can provide its own Relation subclass with custom behavior (solnic)
|
36
|
+
* Relation provides its "public interface" using method_added hook (splattael + solnic)
|
37
|
+
* ROM no longer depends on charlatan, concord and inflecto gems (mjtko + solnic)
|
38
|
+
|
39
|
+
[Compare v0.5.0...master](https://github.com/rom-rb/rom/compare/v0.5.0...master)
|
40
|
+
|
1
41
|
## v0.5.0 2014-12-31
|
2
42
|
|
3
43
|
### Added
|
data/Gemfile
CHANGED
@@ -9,6 +9,10 @@ end
|
|
9
9
|
|
10
10
|
group :test do
|
11
11
|
gem 'virtus'
|
12
|
+
gem 'minitest'
|
13
|
+
gem 'thread_safe'
|
14
|
+
gem 'activesupport'
|
15
|
+
gem 'inflecto', '~> 0.0', '>= 0.0.2'
|
12
16
|
|
13
17
|
platforms :rbx do
|
14
18
|
gem 'rubysl-bigdecimal', platforms: :rbx
|
@@ -35,6 +39,10 @@ group :tools do
|
|
35
39
|
gem 'guard-rspec'
|
36
40
|
gem 'guard-rubocop'
|
37
41
|
|
38
|
-
gem '
|
39
|
-
|
42
|
+
gem 'byebug'
|
43
|
+
|
44
|
+
platform :mri do
|
45
|
+
gem 'mutant', '>= 0.7.7'
|
46
|
+
gem 'mutant-rspec'
|
47
|
+
end
|
40
48
|
end
|
data/Guardfile
CHANGED
@@ -1,22 +1,24 @@
|
|
1
1
|
group :red_green_refactor, halt_on_fail: true do
|
2
|
-
guard :rspec, cmd: "rspec" do
|
3
|
-
# run all specs if
|
4
|
-
watch('
|
5
|
-
watch('Gemfile.lock') { 'spec' }
|
6
|
-
watch('spec/spec_helper.rb') { 'spec' }
|
2
|
+
guard :rspec, cmd: "rspec", all_on_start: true do
|
3
|
+
# run all specs if Gemfile.lock is modified
|
4
|
+
watch('Gemfile.lock') { 'spec' }
|
7
5
|
|
8
|
-
# run all specs if
|
9
|
-
watch(%r{\
|
6
|
+
# run all specs if any library code is modified
|
7
|
+
watch(%r{\Alib/.+\.rb\z}) { 'spec' }
|
10
8
|
|
11
|
-
|
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
12
|
|
13
13
|
# run a spec if it is modified
|
14
14
|
watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z})
|
15
15
|
|
16
|
-
notification :tmux, display_message: true
|
16
|
+
notification :tmux, display_message: true if ENV.key?('TMUX')
|
17
17
|
end
|
18
18
|
|
19
19
|
guard :rubocop do
|
20
|
-
|
20
|
+
# run rubocop on modified file
|
21
|
+
watch(%r{\Alib/.+\.rb\z})
|
22
|
+
watch(%r{\Aspec/.+\.rb\z})
|
21
23
|
end
|
22
24
|
end
|
data/README.md
CHANGED
@@ -12,25 +12,23 @@
|
|
12
12
|
[![Dependency Status](https://gemnasium.com/rom-rb/rom.png)][gemnasium]
|
13
13
|
[![Code Climate](https://codeclimate.com/github/rom-rb/rom/badges/gpa.svg)][codeclimate]
|
14
14
|
[![Test Coverage](https://codeclimate.com/github/rom-rb/rom/badges/coverage.svg)][codeclimate]
|
15
|
-
[![Inline docs](http://inch-ci.org/github/rom-rb/rom.svg?branch=master)][inchpages]
|
15
|
+
[![Inline docs](http://inch-ci.org/github/rom-rb/rom.svg?branch=master&style=flat)][inchpages]
|
16
16
|
|
17
|
-
ROM is an experimental Ruby
|
18
|
-
|
19
|
-
|
17
|
+
Ruby Object Mapper (ROM) is an experimental Ruby library with the goal to
|
18
|
+
provide powerful object mapping capabilities without limiting the full power of
|
19
|
+
your datastore.
|
20
20
|
|
21
|
-
|
22
|
-
* Abstract query interfaces are evil and a source of unnecessary complexity
|
23
|
-
* Reading and mutating data are 2 distinct concerns and should be treated separately
|
24
|
-
* It must be **simple** to use the full power of your database
|
21
|
+
Learn more:
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
to simplify accessing and changing the data.
|
23
|
+
* [Introduction](http://rom-rb.org/introduction/)
|
24
|
+
* [Rails tutorial](http://rom-rb.org/tutorials/rails/)
|
29
25
|
|
30
|
-
|
26
|
+
## Adapters
|
31
27
|
|
32
28
|
* [rom-sql](https://github.com/rom-rb/rom-sql)
|
33
29
|
* [rom-mongo](https://github.com/rom-rb/rom-mongo)
|
30
|
+
* [rom-yaml](https://github.com/rom-rb/rom-yaml)
|
31
|
+
* [rom-csv](https://github.com/rom-rb/rom-csv)
|
34
32
|
|
35
33
|
See [issues](https://github.com/rom-rb/rom/issues?q=is%3Aopen+is%3Aissue+label%3Aadapter+label%3Afeature)
|
36
34
|
for a list of adapters that are planned to be added soon.
|
@@ -41,57 +39,57 @@ Integration with other frameworks is planned.
|
|
41
39
|
## Synopsis
|
42
40
|
|
43
41
|
``` ruby
|
44
|
-
|
42
|
+
ROM.setup(:memory)
|
45
43
|
|
46
|
-
|
44
|
+
# This is our domain-specific class
|
45
|
+
class User
|
46
|
+
attr_reader :name, :age
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
Integer :age
|
48
|
+
def initialize(attributes)
|
49
|
+
@name, @age = attributes.values_at(:name, :age)
|
50
|
+
end
|
52
51
|
end
|
53
52
|
|
54
|
-
#
|
55
|
-
|
56
|
-
|
53
|
+
# Here we define user relation which encapsulates accessing user data that
|
54
|
+
# we can map to domain objects
|
55
|
+
class Users < ROM::Relation[:memory]
|
57
56
|
def by_name(name)
|
58
|
-
|
57
|
+
restrict(name: name)
|
59
58
|
end
|
60
59
|
|
61
60
|
def adults
|
62
|
-
|
61
|
+
restrict { |user| user[:age] >= 18 }
|
63
62
|
end
|
64
63
|
end
|
65
64
|
|
66
|
-
#
|
65
|
+
# Even though mappers can be derived from model definitions here's how you
|
66
|
+
# could define it explicitly
|
67
|
+
class UserMapper < ROM::Mapper
|
68
|
+
relation :users
|
67
69
|
|
68
|
-
|
69
|
-
define(:create)
|
70
|
-
end
|
70
|
+
model User
|
71
71
|
|
72
|
-
|
72
|
+
attribute :name
|
73
|
+
attribute :age
|
74
|
+
end
|
73
75
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
76
|
+
# You can define specialized commands that handle creating, updating and deleting
|
77
|
+
# data, those classes can use external input param handlers and validators too
|
78
|
+
class CreateUser < ROM::Commands::Create[:memory]
|
79
|
+
register_as :create
|
80
|
+
relation :users
|
81
|
+
result :one
|
78
82
|
end
|
79
83
|
|
80
|
-
|
84
|
+
# finalize the setup and retrieve object registry (aka ROM env)
|
85
|
+
rom = ROM.finalize.env
|
81
86
|
|
82
87
|
# accessing defined commands
|
83
|
-
|
84
|
-
rom.command(:users).
|
85
|
-
rom.command(:users).try { create(name: "Jane", age: 18) }
|
86
|
-
|
87
|
-
# accessing registered relations
|
88
|
-
users = rom.relations.users
|
89
|
-
|
90
|
-
puts users.by_name("Jane").adults.to_a.inspect
|
91
|
-
# => [{:id=>2, :name=>"Jane", :age=>18}]
|
88
|
+
rom.command(:users).create.call(name: "Joe", age: 17)
|
89
|
+
rom.command(:users).create.call(name: "Jane", age: 18)
|
92
90
|
|
93
91
|
# reading relations using defined mappers
|
94
|
-
puts rom.
|
92
|
+
puts rom.relation(:users) { |r| r.by_name("Jane").adults }.as(:users).to_a.inspect
|
95
93
|
# => [#<User:0x007fdba161cc48 @id=2, @name="Jane", @age=18>]
|
96
94
|
```
|
97
95
|
|
@@ -102,6 +100,7 @@ for details.
|
|
102
100
|
|
103
101
|
## Community
|
104
102
|
|
103
|
+
* [Official Blog](http://rom-rb.org/blog/)
|
105
104
|
* [![Gitter chat](https://badges.gitter.im/rom-rb/chat.png)](https://gitter.im/rom-rb/chat)
|
106
105
|
* [Ruby Object Mapper](https://groups.google.com/forum/#!forum/rom-rb) mailing list
|
107
106
|
|
data/Rakefile
CHANGED
@@ -1,32 +1,22 @@
|
|
1
1
|
require "rspec/core/rake_task"
|
2
|
+
require "rake/testtask"
|
2
3
|
|
3
4
|
RSpec::Core::RakeTask.new(:spec)
|
4
|
-
task default: [:
|
5
|
+
task default: [:ci]
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
RuboCop::RakeTask.new do |task|
|
12
|
-
task.options << "--display-cop-names"
|
7
|
+
desc 'Run specs in isolation'
|
8
|
+
task :"spec:isolation" do
|
9
|
+
FileList["spec/**/*_spec.rb"].each do |spec|
|
10
|
+
sh "rspec", spec
|
13
11
|
end
|
14
|
-
rescue LoadError
|
15
12
|
end
|
16
13
|
|
17
|
-
desc "Run
|
18
|
-
task :
|
19
|
-
subject = ARGV.last
|
20
|
-
if subject == 'mutant'
|
21
|
-
abort "usage: rake mutant SUBJECT\nexample: rake mutant ROM::Header"
|
22
|
-
else
|
23
|
-
opts = {
|
24
|
-
'include' => 'lib',
|
25
|
-
'require' => 'rom',
|
26
|
-
'use' => 'rspec',
|
27
|
-
'ignore-subject' => "#{subject}#respond_to_missing?"
|
28
|
-
}.to_a.map { |k, v| "--#{k} #{v}" }.join(' ')
|
14
|
+
desc "Run CI tasks"
|
15
|
+
task ci: [:spec, :lint, :"spec:isolation"]
|
29
16
|
|
30
|
-
|
31
|
-
|
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
|
32
22
|
end
|
data/lib/rom.rb
CHANGED
@@ -1,45 +1,37 @@
|
|
1
|
-
require '
|
2
|
-
require 'charlatan'
|
3
|
-
require 'inflecto'
|
1
|
+
require 'equalizer'
|
4
2
|
|
5
3
|
require 'rom/version'
|
4
|
+
require 'rom/constants'
|
5
|
+
|
6
|
+
# internal ROM support lib
|
7
|
+
require 'rom/support/inflector'
|
6
8
|
require 'rom/support/registry'
|
9
|
+
require 'rom/support/options'
|
10
|
+
require 'rom/support/class_macros'
|
11
|
+
require 'rom/support/class_builder'
|
7
12
|
|
8
|
-
|
13
|
+
# core parts
|
9
14
|
require 'rom/relation'
|
10
15
|
require 'rom/mapper'
|
11
16
|
require 'rom/reader'
|
17
|
+
require 'rom/command'
|
12
18
|
|
19
|
+
# default mapper processor using Transproc gem
|
13
20
|
require 'rom/processor/transproc'
|
14
21
|
|
15
|
-
|
22
|
+
# support for global-style setup
|
23
|
+
require 'rom/global'
|
24
|
+
require 'rom/setup'
|
16
25
|
|
17
|
-
require
|
18
|
-
require 'rom/
|
26
|
+
# TODO: consider to make this part optional and don't require it here
|
27
|
+
require 'rom/setup_dsl/setup'
|
19
28
|
|
20
|
-
|
29
|
+
# env with registries
|
21
30
|
require 'rom/env'
|
22
31
|
|
23
|
-
require 'rom/global'
|
24
|
-
require 'rom/setup'
|
25
|
-
|
26
32
|
module ROM
|
27
|
-
|
28
|
-
|
29
|
-
TupleCountMismatchError = Class.new(CommandError)
|
30
|
-
NoRelationError = Class.new(StandardError)
|
31
|
-
|
32
|
-
InvalidOptionError = Class.new(StandardError) do
|
33
|
-
def initialize(option, valid_values)
|
34
|
-
super("#{option} should be one of #{valid_values.inspect}")
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
Schema = Class.new(Registry)
|
33
|
+
extend Global
|
34
|
+
|
39
35
|
RelationRegistry = Class.new(Registry)
|
40
36
|
ReaderRegistry = Class.new(Registry)
|
41
|
-
|
42
|
-
EMPTY_HASH = {}.freeze
|
43
|
-
|
44
|
-
extend Global
|
45
37
|
end
|