rom-rails 1.0.1 → 1.1.0

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
  SHA256:
3
- metadata.gz: d49f16f68f6a53465583cf3be3306680c2b19965da7d43506a14ec4d94def7ac
4
- data.tar.gz: 967352fe1005f0ca23e02f47e29890d17aea45e1d45f007b99135b6786cf94e0
3
+ metadata.gz: d4eaf43b4a1e3674b9796df9c03afefe43e571d2fa9f27f12474b99e472ff636
4
+ data.tar.gz: f320d87054de5000318c5f5426778d1cba4057ec8331cf0a6861a2713fe84628
5
5
  SHA512:
6
- metadata.gz: ef4005945fd02a77d01e40f4130b50fe01f12ae8cab5271d213db595c660abe9e9fdea3edb54e1961bc2688f491406bd85a28d35a2232e61c44cc115450dcc5a
7
- data.tar.gz: 237d4dfd69c682fcc7b4180f70cf66e4a91b4a55e1941fe2225cd1726313bb7d524c1a5c4ebab3237364853f0b56057038e15d9c4d17a151537dd47413e33b64
6
+ metadata.gz: 84e3f5fbf22a37294507e14d8de2bc2673091f4a8fe2e5b1a0b9eeba84ead0f967bbb7e08d9a805cd97d30a2c8ff5caba70a601ca88fcdabdd1614a67c424110
7
+ data.tar.gz: f77380599becffba851cba0a2c4572a03edc968f21dcc83012df701342d4cd64f7825b275b5768fcbd55094c01e163847b67aafa555562431bcc2b1158378134
data/CHANGELOG.md CHANGED
@@ -1,9 +1,24 @@
1
+ ## v1.1.0 2018-03-18
2
+
3
+ ### Added
4
+
5
+ * Add a new `rom:install` generator (cflipse)
6
+
7
+ ### Changed
8
+
9
+ * Stop breaking rails loading when not yet configured. (cflipse)
10
+ * Repository generator prefers `struct_namespace` over mapper (radar, cflipse)
11
+
12
+ [Compare v1.0.1...v1.1.0](https://github.com/rom-rb/rom-rails/compare/v1.0.1...v1.1.0)
13
+
1
14
  ## v1.0.1 2017-12-22
2
15
 
3
16
  ### Changed
4
17
 
5
18
  * Loosen ROM dependency
6
19
 
20
+ [Compare v1.0.0...v1.0.1](https://github.com/rom-rb/rom-rails/compare/v1.0.0...v1.0.1)
21
+
7
22
  ## v1.0.0 2017-10-18
8
23
 
9
24
  ### Changed
@@ -19,6 +34,8 @@
19
34
  * No longer depends on `rom-model` gem (cflipse)
20
35
  * No longer depends on `charlatan` gem (artofhuman)
21
36
 
37
+ [Compare v0.9.0...v1.0.0](https://github.com/rom-rb/rom-rails/compare/v0.9.0...v1.0.0)
38
+
22
39
  ## v0.9.0 2017-01-30
23
40
 
24
41
  ### Added
@@ -37,6 +54,9 @@
37
54
 
38
55
  * [`rom-support`](https://github.com/rom-rb/rom-support) dependency was replaced with [`dry-core`](https://github.com/dry-rb/dry-core) (solnic + flash-gordon)
39
56
 
57
+
58
+ [Compare v0.8.0...v0.9.0](https://github.com/rom-rb/rom-rails/compare/v0.8.0...v0.9.0)
59
+
40
60
  ## v0.8.0 2016-08-08
41
61
  ### Changed
42
62
 
@@ -47,6 +67,8 @@
47
67
  ### Deprecated
48
68
  * Dropping support for ruby 2.1 and below
49
69
 
70
+ [Compare v0.7.0...v0.8.0](https://github.com/rom-rb/rom-rails/compare/v0.7.0...v0.8.0)
71
+
50
72
  ## v0.7.0 2016-07-27
51
73
 
52
74
  ### Changed
@@ -0,0 +1,20 @@
1
+ require 'types'
2
+
3
+ class ApplicationModel < ROM::Struct
4
+ def self.inherited(base)
5
+ super
6
+
7
+ base.constructor_type :schema
8
+
9
+ base.extend ActiveModel::Naming
10
+ base.include ActiveModel::Conversion
11
+
12
+ base.include Dry::Equalizer(:id)
13
+
14
+ base.attribute :id, Types::ID
15
+ end
16
+
17
+ def persisted?
18
+ id.present?
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ ROM::Rails::Railtie.configure do |config|
2
+ config.gateways[:default] = [:<%= adapter %>, ENV.fetch('DATABASE_URL')]
3
+ end
@@ -0,0 +1,10 @@
1
+ require 'dry/types'
2
+
3
+ module Types
4
+ include Dry::Types.module
5
+
6
+ ID = Coercible::Int.optional.meta(primary_key: true)
7
+
8
+ # Include your own type definitions and coersions here.
9
+ # See http://dry-rb.org/gems/dry-types
10
+ end
@@ -0,0 +1,42 @@
1
+ require 'generators/rom'
2
+
3
+ module ROM
4
+ module Generators
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ def self.namespace
7
+ "rom:#{generator_name}"
8
+ end
9
+
10
+ def self.source_root
11
+ File.expand_path("../install/templates", __FILE__)
12
+ end
13
+
14
+ class_option :adapter,
15
+ banner: '--adapter=adapter',
16
+ desc: "specify an adapter to use", required: true,
17
+ default: "sql"
18
+
19
+ def create_initializer
20
+ template 'initializer.rb.erb',
21
+ File.join('config', 'initializers', 'rom.rb')
22
+ end
23
+
24
+ def add_types_module
25
+ copy_file "types.rb", "lib/types.rb"
26
+ end
27
+
28
+ def add_application_model
29
+ copy_file "application_model.rb", "app/models/application_model.rb"
30
+ end
31
+
32
+
33
+
34
+ private
35
+
36
+ def adapter
37
+ options[:adapter].to_sym
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -1,5 +1,7 @@
1
1
  class <%= model_name %>Repository < ROM::Repository::Root
2
2
  root <%= ":#{relation}" %>
3
3
 
4
- commands :create, update: :by_pk, delete: :by_pk, mapper: :<%= mapper %>
4
+ commands :create, update: :by_pk, delete: :by_pk
5
+
6
+ struct_namespace <%= struct_namespace %>
5
7
  end
@@ -4,6 +4,12 @@ if defined? ROM::Repository
4
4
  module ROM
5
5
  module Generators
6
6
  class RepositoryGenerator < Base
7
+
8
+ class_option :namespace,
9
+ banner: '--namespace=namespace',
10
+ desc: "specify a struct namespace for the relation", required: true,
11
+ default: ::Rails.application.class.name.split("::").first
12
+
7
13
  def create_repository_file
8
14
  template(
9
15
  'repository.rb.erb',
@@ -11,7 +17,11 @@ if defined? ROM::Repository
11
17
  )
12
18
  end
13
19
 
14
- private
20
+ private
21
+
22
+ def struct_namespace
23
+ options[:namespace]
24
+ end
15
25
 
16
26
  def relation
17
27
  class_name.pluralize.underscore
@@ -83,10 +83,11 @@ module ROM
83
83
  def gateways
84
84
  config.rom.gateways[:default] ||= infer_default_gateway if active_record?
85
85
 
86
- raise(
87
- MissingGatewayConfigError,
88
- "seems like you didn't configure any gateways"
89
- ) unless config.rom.gateways.any?
86
+ if config.rom.gateways.empty?
87
+ Rails.logger.warn "It seems that you have not configured any gateways"
88
+
89
+ config.rom.gateways[:default] = [ :memory, "memory://test" ]
90
+ end
90
91
 
91
92
  config.rom.gateways
92
93
  end
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  module Rails
3
- VERSION = '1.0.1'.freeze
3
+ VERSION = '1.1.0'.freeze
4
4
  end
5
5
  end
data/rom-rails.gemspec CHANGED
@@ -26,5 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "rom-repository"
27
27
  spec.add_development_dependency "bundler"
28
28
  spec.add_development_dependency "rake"
29
- spec.add_development_dependency "rubocop", "~> 0.28"
29
+ spec.add_development_dependency "rubocop", "~> 0.50"
30
30
  end
@@ -0,0 +1,95 @@
1
+ require 'generators/rom/install_generator'
2
+
3
+ RSpec.describe ROM::Generators::InstallGenerator, type: :generator do
4
+ destination File.expand_path('../../../../tmp', __FILE__)
5
+
6
+ before(:each) do
7
+ prepare_destination
8
+ end
9
+
10
+ it "installs a setup initializer" do
11
+ run_generator ['install']
12
+
13
+ expect(destination_root).to have_structure {
14
+ directory 'config' do
15
+ directory 'initializers' do
16
+ file 'rom.rb' do
17
+ contains <<-CONTENT.strip_heredoc
18
+ ROM::Rails::Railtie.configure do |config|
19
+ config.gateways[:default] = [:sql, ENV.fetch('DATABASE_URL')]
20
+ end
21
+ CONTENT
22
+ end
23
+ end
24
+ end
25
+ }
26
+ end
27
+
28
+ it "allows overriding the adapter type" do
29
+ run_generator ["install", "--adapter=yaml"]
30
+ initializer = File.read(File.join(destination_root, "config", "initializers", "rom.rb"))
31
+
32
+ expect(initializer).to include("config.gateways[:default] = [:yaml, ENV.fetch('DATABASE_URL')]")
33
+ end
34
+
35
+ it "sets up lib/types" do
36
+ run_generator ["install"]
37
+
38
+ expect(destination_root).to have_structure {
39
+ directory "lib" do
40
+ file "types.rb" do
41
+ contains <<-CONTENT.strip_heredoc
42
+ require 'dry/types'
43
+
44
+ module Types
45
+ include Dry::Types.module
46
+
47
+ ID = Coercible::Int.optional.meta(primary_key: true)
48
+
49
+ # Include your own type definitions and coersions here.
50
+ # See http://dry-rb.org/gems/dry-types
51
+ end
52
+ CONTENT
53
+ end
54
+ end
55
+ }
56
+ end
57
+
58
+ it "sets up ApplicationModel" do
59
+ run_generator ["install"]
60
+
61
+ expect(destination_root).to have_structure {
62
+ directory "app" do
63
+ directory "models" do
64
+ file "application_model.rb" do
65
+ contains <<-CONTENT.strip_heredoc
66
+ require 'types'
67
+
68
+ class ApplicationModel < ROM::Struct
69
+ def self.inherited(base)
70
+ super
71
+
72
+ base.constructor_type :schema
73
+
74
+ base.extend ActiveModel::Naming
75
+ base.include ActiveModel::Conversion
76
+
77
+ base.include Dry::Equalizer(:id)
78
+
79
+ base.attribute :id, Types::ID
80
+ end
81
+
82
+ def persisted?
83
+ id.present?
84
+ end
85
+ end
86
+ CONTENT
87
+ end
88
+
89
+ end
90
+ end
91
+ }
92
+ end
93
+
94
+
95
+ end
@@ -19,7 +19,9 @@ RSpec.describe ROM::Generators::RepositoryGenerator, type: :generator do
19
19
  class UserRepository < ROM::Repository::Root
20
20
  root :users
21
21
 
22
- commands :create, update: :by_pk, delete: :by_pk, mapper: :user
22
+ commands :create, update: :by_pk, delete: :by_pk
23
+
24
+ struct_namespace Dummy
23
25
  end
24
26
  CONTENT
25
27
  end
@@ -39,7 +41,9 @@ RSpec.describe ROM::Generators::RepositoryGenerator, type: :generator do
39
41
  class UserProfileRepository < ROM::Repository::Root
40
42
  root :user_profiles
41
43
 
42
- commands :create, update: :by_pk, delete: :by_pk, mapper: :user_profile
44
+ commands :create, update: :by_pk, delete: :by_pk
45
+
46
+ struct_namespace Dummy
43
47
  end
44
48
  CONTENT
45
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rom-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-22 00:00:00.000000000 Z
11
+ date: 2018-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rom
@@ -134,14 +134,14 @@ dependencies:
134
134
  requirements:
135
135
  - - "~>"
136
136
  - !ruby/object:Gem::Version
137
- version: '0.28'
137
+ version: '0.50'
138
138
  type: :development
139
139
  prerelease: false
140
140
  version_requirements: !ruby/object:Gem::Requirement
141
141
  requirements:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
- version: '0.28'
144
+ version: '0.50'
145
145
  description:
146
146
  email:
147
147
  - piotr.solnica@gmail.com
@@ -164,6 +164,10 @@ files:
164
164
  - lib/generators/rom/commands/templates/delete.rb.erb
165
165
  - lib/generators/rom/commands/templates/update.rb.erb
166
166
  - lib/generators/rom/commands_generator.rb
167
+ - lib/generators/rom/install/templates/application_model.rb
168
+ - lib/generators/rom/install/templates/initializer.rb.erb
169
+ - lib/generators/rom/install/templates/types.rb
170
+ - lib/generators/rom/install_generator.rb
167
171
  - lib/generators/rom/mapper/templates/mapper.rb.erb
168
172
  - lib/generators/rom/mapper_generator.rb
169
173
  - lib/generators/rom/relation/templates/relation.rb.erb
@@ -247,6 +251,7 @@ files:
247
251
  - spec/integration/user_model_mapping_spec.rb
248
252
  - spec/lib/active_record/configuration_spec.rb
249
253
  - spec/lib/generators/commands_generator_spec.rb
254
+ - spec/lib/generators/install_generator_spec.rb
250
255
  - spec/lib/generators/mapper_generator_spec.rb
251
256
  - spec/lib/generators/relation_generator_spec.rb
252
257
  - spec/lib/generators/repository_generator_spec.rb
@@ -271,7 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
271
276
  version: '0'
272
277
  requirements: []
273
278
  rubyforge_project:
274
- rubygems_version: 2.7.2
279
+ rubygems_version: 2.7.6
275
280
  signing_key:
276
281
  specification_version: 4
277
282
  summary: Integrate Ruby Object Mapper with Rails
@@ -343,6 +348,7 @@ test_files:
343
348
  - spec/integration/user_model_mapping_spec.rb
344
349
  - spec/lib/active_record/configuration_spec.rb
345
350
  - spec/lib/generators/commands_generator_spec.rb
351
+ - spec/lib/generators/install_generator_spec.rb
346
352
  - spec/lib/generators/mapper_generator_spec.rb
347
353
  - spec/lib/generators/relation_generator_spec.rb
348
354
  - spec/lib/generators/repository_generator_spec.rb