rom 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a49d8efc969391ec0d48db3e9f41d29299537e44
4
- data.tar.gz: 5c4ba339c27f15887468a364bd89de0c7c722572
3
+ metadata.gz: 29e221f399a6c003c04d45c03b9518d19b5ffd48
4
+ data.tar.gz: 223b1648de818651d5cc89f05e088fefdaf8ec19
5
5
  SHA512:
6
- metadata.gz: b720586dcc0542d8ab45d22209d91898c695a8f509af73f3bb1f967f3952f39f83ed3c9bcb7aa7b4ec87087518e7f9f2f592c4d5a4ad5763a5a3c8f9829389de
7
- data.tar.gz: 1b5f6a9ae2038ea0b539d4e6931a1be194aa13d2cc2b7fbc3a1af03455bc028956f96a4ba39ab4cf94fd551931b86ab425e2c61bef8b13e2c823cd3a0f4ff967
6
+ metadata.gz: 144b7539ca43248fd1c8304b624e5fd46f229016bb5057b20615f95026421b916b66888d223b49b4f5119a5698b44c7f96165fd454922b722387701e0d9eb7ee
7
+ data.tar.gz: 7dee28d63ed1e6a7c7eee538172249d6d8c71cd83b8840c38d86550cc323f2944ef4d68cab49236f69c55ac632fa00f29e06d44439fb2c6a1f1cd9a67e054e97
data/.gitignore CHANGED
@@ -13,6 +13,7 @@ test/version_tmp
13
13
  tmp
14
14
  Gemfile.lock
15
15
  vendor/
16
+ log/
16
17
 
17
18
  .idea/
18
19
 
data/.travis.yml CHANGED
@@ -6,12 +6,11 @@ env:
6
6
  bundler_args: --without sql benchmarks console tools
7
7
  script: "bundle exec rake ci"
8
8
  rvm:
9
- - 2.0
10
9
  - 2.1
11
10
  - 2.2
12
11
  - 2.3.1
13
12
  - rbx-2
14
- - jruby-9.0.5.0
13
+ - jruby-9.1.5.0
15
14
  - ruby-head
16
15
  env:
17
16
  global:
@@ -19,10 +18,7 @@ env:
19
18
  matrix:
20
19
  allow_failures:
21
20
  - rvm: ruby-head
22
- - rvm: jruby-head
23
- include:
24
- - rvm: jruby-head
25
- before_install: gem install bundler --no-ri --no-rdoc
21
+ - rvm: rbx-2
26
22
  notifications:
27
23
  webhooks:
28
24
  urls:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## v2.0.1 2016-09-30
2
+
3
+ ### Added
4
+
5
+ - Support for different auto-registration strategies (janjiss)
6
+ - Support for custom component dir names in auto-registration (AMHOL)
7
+
8
+ ### Fixed
9
+
10
+ - Finalizing schema that is already finalized no longer crashes (flash-gordon)
11
+
12
+ [Compare v2.0.0...v2.0.1](https://github.com/rom-rb/rom/compare/v2.0.0...v2.0.1)
13
+
1
14
  ## v2.0.0 2016-07-27
2
15
 
3
16
  ### Added
data/lib/rom/schema.rb CHANGED
@@ -78,6 +78,8 @@ module ROM
78
78
  #
79
79
  # @api private
80
80
  def finalize!(gateway = nil, &block)
81
+ return self if frozen?
82
+
81
83
  @attributes = inferrer.call(name.dataset, gateway) if inferrer
82
84
  @primary_key = select { |attr| attr.meta[:primary_key] == true }
83
85
  block.call if block
@@ -4,19 +4,29 @@ require 'rom/support/constants'
4
4
  require 'rom/support/inflector'
5
5
  require 'rom/support/options'
6
6
 
7
+ require 'rom/setup/auto_registration_strategies/no_namespace'
8
+ require 'rom/setup/auto_registration_strategies/with_namespace'
9
+ require 'rom/setup/auto_registration_strategies/custom_namespace'
10
+
7
11
  module ROM
8
12
  class AutoRegistration
9
13
  include Options
10
14
 
11
- option :namespace, reader: true, type: [TrueClass, FalseClass], default: true
15
+ option :namespace, reader: true, type: [TrueClass, FalseClass, String], default: true
16
+
17
+ option :component_dirs, reader: true, type: ::Hash, default: {
18
+ relations: :relations,
19
+ mappers: :mappers,
20
+ commands: :commands
21
+ }
12
22
 
13
23
  attr_reader :globs, :directory
14
24
 
15
25
  def initialize(directory, options = EMPTY_HASH)
16
26
  super
17
27
  @directory = Pathname(directory)
18
- @globs = Hash[[:relations, :commands, :mappers].map { |name|
19
- [name, @directory.join("#{name}/**/*.rb")]
28
+ @globs = Hash[component_dirs.map { |component, directory|
29
+ [component, @directory.join("#{directory}/**/*.rb")]
20
30
  }]
21
31
  end
22
32
 
@@ -37,19 +47,23 @@ module ROM
37
47
  def load_entities(entity)
38
48
  Dir[globs[entity]].map do |file|
39
49
  require file
40
- Inflector.constantize(const_name(entity, file))
50
+ klass_name =
51
+ case namespace
52
+ when String
53
+ AutoRegistrationStrategies::CustomNamespace.new(
54
+ namespace: namespace, file: file
55
+ ).call
56
+ when TrueClass
57
+ AutoRegistrationStrategies::WithNamespace.new(
58
+ file: file, directory: directory
59
+ ).call
60
+ when FalseClass
61
+ AutoRegistrationStrategies::NoNamespace.new(
62
+ file: file, directory: directory, entity: component_dirs.fetch(entity)
63
+ ).call
64
+ end
65
+ Inflector.constantize(klass_name)
41
66
  end
42
67
  end
43
-
44
- def const_name(entity, file)
45
- name =
46
- if namespace
47
- file.gsub("#{directory.dirname}/", '')
48
- else
49
- file.gsub("#{directory}/#{entity}/", '')
50
- end.gsub('.rb', '')
51
-
52
- Inflector.camelize(name)
53
- end
54
68
  end
55
69
  end
@@ -0,0 +1,11 @@
1
+ module ROM
2
+ module AutoRegistrationStrategies
3
+ class Base
4
+ include Options
5
+
6
+ option :file, reader: true, type: String
7
+
8
+ EXTENSION_REGEX = /\.rb$/.freeze
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ require 'pathname'
2
+
3
+ require 'rom/support/inflector'
4
+ require 'rom/setup/auto_registration_strategies/base'
5
+
6
+ module ROM
7
+ module AutoRegistrationStrategies
8
+ class CustomNamespace < Base
9
+ option :namespace, reader: true, type: String
10
+
11
+ def call
12
+ "#{namespace}::#{Inflector.camelize(filename)}"
13
+ end
14
+
15
+ private
16
+
17
+ def filename
18
+ Pathname(file).basename('.rb')
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ require 'pathname'
2
+
3
+ require 'rom/support/inflector'
4
+ require 'rom/setup/auto_registration_strategies/base'
5
+
6
+ module ROM
7
+ module AutoRegistrationStrategies
8
+ class NoNamespace < Base
9
+ option :directory, reader: true, type: Pathname
10
+ option :entity, reader: true, type: Symbol
11
+
12
+ def call
13
+ Inflector.camelize(
14
+ file.sub(/^#{directory}\/#{entity}\//, '').sub(EXTENSION_REGEX, '')
15
+ )
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ require 'pathname'
2
+
3
+ require 'rom/support/inflector'
4
+ require 'rom/setup/auto_registration_strategies/base'
5
+
6
+ module ROM
7
+ module AutoRegistrationStrategies
8
+ class WithNamespace < Base
9
+ option :directory, reader: true, type: Pathname
10
+
11
+ def call
12
+ Inflector.camelize(
13
+ file.sub(/^#{directory.dirname}\//, '').sub(EXTENSION_REGEX, '')
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
data/lib/rom/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ROM
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '2.0.1'.freeze
3
3
  end
@@ -0,0 +1,2 @@
1
+ class CreateUser
2
+ end
@@ -0,0 +1,2 @@
1
+ class UserList
2
+ end
@@ -0,0 +1,2 @@
1
+ class Users
2
+ end
@@ -0,0 +1,6 @@
1
+ module My
2
+ module Namespace
3
+ class CreateUser
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module My
2
+ module Namespace
3
+ class UserList
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module My
2
+ module Namespace
3
+ class Users
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Persistence
2
+ module MyCommands
3
+ class CreateUser
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Persistence
2
+ module MyMappers
3
+ class UserList
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Persistence
2
+ module MyRelations
3
+ class Users
4
+ end
5
+ end
6
+ end
@@ -145,4 +145,18 @@ describe 'Configuring ROM' do
145
145
  .to eql([Test::User.new(name: 'Jane')])
146
146
  end
147
147
  end
148
+
149
+ it 'allows to use a relation with a schema in multiple containers' do
150
+ class Test::UserRelation < ROM::Relation[:memory]
151
+ dataset :users
152
+
153
+ schema do
154
+ attribute :id, Types::Int.meta(primary_key: true)
155
+ end
156
+ end
157
+
158
+ 2.times do
159
+ ROM.container(:memory) { |c| c.register_relation(Test::UserRelation) }
160
+ end
161
+ end
148
162
  end
@@ -0,0 +1,152 @@
1
+ require 'rom/setup'
2
+
3
+ RSpec.describe ROM::Setup, '#auto_registration' do
4
+ subject(:setup) { ROM::Setup.new }
5
+
6
+ context 'with default component_dirs' do
7
+ context 'with namespace turned on' do
8
+ before do
9
+ setup.auto_registration(SPEC_ROOT.join('fixtures/lib/persistence').to_s)
10
+ end
11
+
12
+ describe '#relations' do
13
+ it 'loads files and returns constants' do
14
+ expect(setup.relation_classes).to eql([Persistence::Relations::Users])
15
+ end
16
+ end
17
+
18
+ describe '#commands' do
19
+ it 'loads files and returns constants' do
20
+ expect(setup.command_classes).to eql([Persistence::Commands::CreateUser])
21
+ end
22
+ end
23
+
24
+ describe '#mappers' do
25
+ it 'loads files and returns constants' do
26
+ expect(setup.mapper_classes).to eql([Persistence::Mappers::UserList])
27
+ end
28
+ end
29
+ end
30
+
31
+ context 'with namespace turned off' do
32
+ before do
33
+ setup.auto_registration(SPEC_ROOT.join('fixtures/app'), namespace: false)
34
+ end
35
+
36
+ describe '#relations' do
37
+ it 'loads files and returns constants' do
38
+ expect(setup.relation_classes).to eql([Users])
39
+ end
40
+ end
41
+
42
+ describe '#commands' do
43
+ it 'loads files and returns constants' do
44
+ expect(setup.command_classes).to eql([CreateUser])
45
+ end
46
+ end
47
+
48
+ describe '#mappers' do
49
+ it 'loads files and returns constants' do
50
+ expect(setup.mapper_classes).to eql([UserList])
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ context 'with custom component_dirs' do
57
+ context 'with namespace turned on' do
58
+ before do
59
+ setup.auto_registration(
60
+ SPEC_ROOT.join('fixtures/lib/persistence').to_s,
61
+ component_dirs: {
62
+ relations: :my_relations,
63
+ mappers: :my_mappers,
64
+ commands: :my_commands
65
+ }
66
+ )
67
+ end
68
+
69
+ describe '#relations' do
70
+ it 'loads files and returns constants' do
71
+ expect(setup.relation_classes).to eql([Persistence::MyRelations::Users])
72
+ end
73
+ end
74
+
75
+ describe '#commands' do
76
+ it 'loads files and returns constants' do
77
+ expect(setup.command_classes).to eql([Persistence::MyCommands::CreateUser])
78
+ end
79
+ end
80
+
81
+ describe '#mappers' do
82
+ it 'loads files and returns constants' do
83
+ expect(setup.mapper_classes).to eql([Persistence::MyMappers::UserList])
84
+ end
85
+ end
86
+ end
87
+
88
+ context 'with namespace turned off' do
89
+ before do
90
+ setup.auto_registration(
91
+ SPEC_ROOT.join('fixtures/app'),
92
+ component_dirs: {
93
+ relations: :my_relations,
94
+ mappers: :my_mappers,
95
+ commands: :my_commands
96
+ },
97
+ namespace: false
98
+ )
99
+ end
100
+
101
+ describe '#relations' do
102
+ it 'loads files and returns constants' do
103
+ expect(setup.relation_classes).to eql([Users])
104
+ end
105
+ end
106
+
107
+ describe '#commands' do
108
+ it 'loads files and returns constants' do
109
+ expect(setup.command_classes).to eql([CreateUser])
110
+ end
111
+ end
112
+
113
+ describe '#mappers' do
114
+ it 'loads files and returns constants' do
115
+ expect(setup.mapper_classes).to eql([UserList])
116
+ end
117
+ end
118
+ end
119
+
120
+ context 'with custom namespace' do
121
+ before do
122
+ setup.auto_registration(
123
+ SPEC_ROOT.join('fixtures/custom'),
124
+ component_dirs: {
125
+ relations: :relations,
126
+ mappers: :mappers,
127
+ commands: :commands
128
+ },
129
+ namespace: 'My::Namespace'
130
+ )
131
+ end
132
+
133
+ describe '#relations' do
134
+ it 'loads files and returns constants' do
135
+ expect(setup.relation_classes).to eql([My::Namespace::Users])
136
+ end
137
+ end
138
+
139
+ describe '#commands' do
140
+ it 'loads files and returns constants' do
141
+ expect(setup.command_classes).to eql([My::Namespace::CreateUser])
142
+ end
143
+ end
144
+
145
+ describe '#mappers' do
146
+ it 'loads files and returns constants' do
147
+ expect(setup.mapper_classes).to eql([My::Namespace::UserList])
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rom
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-27 00:00:00.000000000 Z
11
+ date: 2016-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -197,6 +197,10 @@ files:
197
197
  - lib/rom/schema/dsl.rb
198
198
  - lib/rom/setup.rb
199
199
  - lib/rom/setup/auto_registration.rb
200
+ - lib/rom/setup/auto_registration_strategies/base.rb
201
+ - lib/rom/setup/auto_registration_strategies/custom_namespace.rb
202
+ - lib/rom/setup/auto_registration_strategies/no_namespace.rb
203
+ - lib/rom/setup/auto_registration_strategies/with_namespace.rb
200
204
  - lib/rom/setup/finalize.rb
201
205
  - lib/rom/setup/finalize/finalize_commands.rb
202
206
  - lib/rom/setup/finalize/finalize_mappers.rb
@@ -211,9 +215,18 @@ files:
211
215
  - rom.gemspec
212
216
  - spec/fixtures/app/commands/create_user.rb
213
217
  - spec/fixtures/app/mappers/user_list.rb
218
+ - spec/fixtures/app/my_commands/create_user.rb
219
+ - spec/fixtures/app/my_mappers/user_list.rb
220
+ - spec/fixtures/app/my_relations/users.rb
214
221
  - spec/fixtures/app/relations/users.rb
222
+ - spec/fixtures/custom/commands/create_user.rb
223
+ - spec/fixtures/custom/mappers/user_list.rb
224
+ - spec/fixtures/custom/relations/users.rb
215
225
  - spec/fixtures/lib/persistence/commands/create_user.rb
216
226
  - spec/fixtures/lib/persistence/mappers/user_list.rb
227
+ - spec/fixtures/lib/persistence/my_commands/create_user.rb
228
+ - spec/fixtures/lib/persistence/my_mappers/user_list.rb
229
+ - spec/fixtures/lib/persistence/my_relations/users.rb
217
230
  - spec/fixtures/lib/persistence/relations/users.rb
218
231
  - spec/integration/command_registry_spec.rb
219
232
  - spec/integration/commands/create_spec.rb
@@ -270,7 +283,6 @@ files:
270
283
  - spec/support/mutant.rb
271
284
  - spec/test/memory_repository_lint_test.rb
272
285
  - spec/unit/rom/association_set_spec.rb
273
- - spec/unit/rom/auto_registration_spec.rb
274
286
  - spec/unit/rom/commands/graph_spec.rb
275
287
  - spec/unit/rom/commands/lazy_spec.rb
276
288
  - spec/unit/rom/commands/result_spec.rb
@@ -300,6 +312,7 @@ files:
300
312
  - spec/unit/rom/relation/schema_spec.rb
301
313
  - spec/unit/rom/relation_spec.rb
302
314
  - spec/unit/rom/schema_spec.rb
315
+ - spec/unit/rom/setup/auto_registration_spec.rb
303
316
  homepage: http://rom-rb.org
304
317
  licenses:
305
318
  - MIT
@@ -1,54 +0,0 @@
1
- require 'spec_helper'
2
- require 'rom/setup/auto_registration'
3
-
4
- RSpec.describe ROM::Setup, '#auto_registration' do
5
- let(:setup) { ROM::Setup.new }
6
-
7
- context 'with namespace turned on' do
8
- before do
9
- setup.auto_registration(SPEC_ROOT.join('fixtures/lib/persistence').to_s)
10
- end
11
-
12
- describe '#relations' do
13
- it 'loads files and returns constants' do
14
- expect(setup.relation_classes).to eql([Persistence::Relations::Users])
15
- end
16
- end
17
-
18
- describe '#commands' do
19
- it 'loads files and returns constants' do
20
- expect(setup.command_classes).to eql([Persistence::Commands::CreateUser])
21
- end
22
- end
23
-
24
- describe '#mappers' do
25
- it 'loads files and returns constants' do
26
- expect(setup.mapper_classes).to eql([Persistence::Mappers::UserList])
27
- end
28
- end
29
- end
30
-
31
- context 'with namespace turned off' do
32
- before do
33
- setup.auto_registration(SPEC_ROOT.join('fixtures/app'), namespace: false)
34
- end
35
-
36
- describe '#relations' do
37
- it 'loads files and returns constants' do
38
- expect(setup.relation_classes).to eql([Users])
39
- end
40
- end
41
-
42
- describe '#commands' do
43
- it 'loads files and returns constants' do
44
- expect(setup.command_classes).to eql([CreateUser])
45
- end
46
- end
47
-
48
- describe '#mappers' do
49
- it 'loads files and returns constants' do
50
- expect(setup.mapper_classes).to eql([UserList])
51
- end
52
- end
53
- end
54
- end