rails_drivers 0.5.0 → 1.0.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: 52e2b19b5bd5e3ef8921b6c64b08c03c9b1b4a568e70384ca1f855b9c140f783
4
- data.tar.gz: 4429a66b2b8237e01a91447898b8a8a2a4efb88f5baa93382f594f0e48c7bcde
3
+ metadata.gz: 2b0f6e72ff1714747fe0c4a3b0d6868236099950af9d3261337d9a352a1d9e1b
4
+ data.tar.gz: 7f69a6821fefa1ac60c738df6523b5608c6d1575a80d9349f5bcb67d476feec5
5
5
  SHA512:
6
- metadata.gz: c1fec26f52e667e09aa237d232dd709b6f4011b48a222762c48b54d5bf19a33145f71d9c6ac3c39d8022b30da32e94042ce25772ed66707af650f91d8aff4b6e
7
- data.tar.gz: '08e1af9dde001c22c9ca03bde90c6c10c14975797d6aa0588f08e98dedce155ab9704e9f1ebdb0b7942eced1e8d1b0f67afec230bdbe2458c2e13a23cf0c6803'
6
+ metadata.gz: a17961dfac581a7be80f473e1dcd1c3c53fc5d855b2452548a3e99571dbe45a9c092da8a27b125de9d1c37dbc2b2d97bb55bf313c3f977a733a26e4415651f49
7
+ data.tar.gz: 45b591eee5e366b08b72d331c22593221c5e93163e89b25761c13652f919fcf99ace3b9637d246d53464c95f1031efb6eee9f4d746bc2ecec9706c0df90ee28c
data/README.md CHANGED
@@ -61,23 +61,23 @@ end
61
61
 
62
62
  Can be executed using `rake driver:my_driver:my_namespace:task_name`.
63
63
 
64
- ### Overrides
64
+ ### Extensions
65
65
 
66
- Sometimes you want to add a method to a core class, but that method will only be used by one driver. This can be achieved by adding files to your driver's `overrides` directory.
66
+ Sometimes you want to add a method to a core class, but that method will only be used by one driver. This can be achieved by adding files to your driver's `extensions` directory.
67
67
 
68
68
  ```ruby
69
69
  # app/models/product.rb
70
70
  # (doesn't have to be a model - can be anything)
71
71
  class Product < ApplicationRecord
72
- # When you include this, every driver's product_override.rb is loaded and
72
+ # When you include this, every driver's product_extension.rb is loaded and
73
73
  # included. Works correctly with autoloading during development.
74
- include RailsDrivers::Overrides
74
+ include RailsDrivers::Extensions
75
75
  end
76
76
 
77
77
 
78
- # drivers/my_driver/overrides/product_override.rb
78
+ # drivers/my_driver/extensions/product_extension.rb
79
79
  module MyDriver
80
- module ProductOverride
80
+ module ProductExtension
81
81
  extend ActiveSupport::Concern
82
82
 
83
83
  def new_method
@@ -91,7 +91,7 @@ end
91
91
  Product.new.new_method
92
92
  ```
93
93
 
94
- For each Override, the accompanying class simply `includes` it, so any methods you define will be available throughout the whole app. To make sure your drivers don't change the core behavior of the app, see [Testing for coupling](#testing-for-coupling).
94
+ For each Extension, the accompanying class simply `includes` it, so any methods you define will be available throughout the whole app. To make sure your drivers don't change the core behavior of the app, see [Testing for coupling](#testing-for-coupling).
95
95
 
96
96
  ### Testing for coupling
97
97
 
@@ -11,6 +11,6 @@ Example:
11
11
  drivers/new_feature/app/models/new_feature
12
12
  drivers/new_feature/app/views/new_feature
13
13
  drivers/new_feature/config
14
- drivers/new_feature/overrides
14
+ drivers/new_feature/extensions
15
15
  drivers/new_feature/spec
16
16
  drivers/new_feature/lib
@@ -10,7 +10,7 @@ class DriverGenerator < Rails::Generators::NamedBase
10
10
  create_file "drivers/#{file_name}/spec/.keep", ''
11
11
  create_file "drivers/#{file_name}/db/migrate/.keep", ''
12
12
  create_file "drivers/#{file_name}/lib/tasks/.keep", ''
13
- create_file "drivers/#{file_name}/overrides/.keep", ''
13
+ create_file "drivers/#{file_name}/extensions/.keep", ''
14
14
 
15
15
  template 'routes.rb.erb', "drivers/#{file_name}/config/routes.rb"
16
16
  template 'initializer.rb.erb', "drivers/#{file_name}/config/initializers/#{file_name}_feature.rb"
data/lib/rails_drivers.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'rails_drivers/version'
4
4
  require 'rails_drivers/setup'
5
5
  require 'rails_drivers/railtie'
6
- require 'rails_drivers/overrides'
6
+ require 'rails_drivers/extensions'
7
7
 
8
8
  module RailsDrivers
9
9
  class << self
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsDrivers
4
+ module Extensions
5
+ extend ActiveSupport::Concern
6
+
7
+ # Including this module results in all available extension modules being
8
+ # included.
9
+ included do
10
+ cattr_reader :driver_extensions
11
+
12
+ possible_extensions = Dir.glob(
13
+ Rails.root.join(
14
+ 'drivers', '*', 'extensions',
15
+ "#{name.underscore}_extension.rb"
16
+ )
17
+ )
18
+
19
+ @@driver_extensions = possible_extensions.map do |path|
20
+ require_dependency path
21
+ %r{drivers/(?<driver_name>[^/]+)/extensions} =~ path
22
+
23
+ extension = "#{driver_name.classify}::#{name}Extension".constantize
24
+ include extension
25
+ extension
26
+ end.freeze
27
+
28
+ singleton_class.prepend CheckForShadowedMethods
29
+ end
30
+
31
+ # This module is prepended to the singleton class of the including class
32
+ # to detect when an extension is attempting to re-define any methods.
33
+ module CheckForShadowedMethods
34
+ def method_added(method_name)
35
+ driver_extensions.each do |extension|
36
+ next unless extension.instance_methods.include?(method_name)
37
+
38
+ Rails.logger.warn "Driver extension method #{extension.name}##{method_name} "\
39
+ "is shadowed by #{name}##{method_name} and will likely not do anything."
40
+ end
41
+
42
+ super(method_name)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsDrivers
4
- VERSION = '0.5.0'
4
+ VERSION = '1.0.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_drivers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nigel Baillie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-28 00:00:00.000000000 Z
11
+ date: 2020-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -101,8 +101,8 @@ files:
101
101
  - lib/generators/driver/templates/module.rb.erb
102
102
  - lib/generators/driver/templates/routes.rb.erb
103
103
  - lib/rails_drivers.rb
104
+ - lib/rails_drivers/extensions.rb
104
105
  - lib/rails_drivers/files.rb
105
- - lib/rails_drivers/overrides.rb
106
106
  - lib/rails_drivers/railtie.rb
107
107
  - lib/rails_drivers/routes.rb
108
108
  - lib/rails_drivers/setup.rb
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RailsDrivers
4
- module Overrides
5
- extend ActiveSupport::Concern
6
-
7
- # Including this module results in all available override modules being
8
- # included.
9
- included do
10
- cattr_reader :driver_overrides
11
-
12
- possible_overrides = Dir.glob(
13
- Rails.root.join(
14
- 'drivers', '*', 'overrides',
15
- "#{name.underscore}_override.rb"
16
- )
17
- )
18
-
19
- @@driver_overrides = possible_overrides.map do |path|
20
- require_dependency path
21
- %r{drivers/(?<driver_name>[^/]+)/overrides} =~ path
22
-
23
- override = "#{driver_name.classify}::#{name}Override".constantize
24
- include override
25
- override
26
- end.freeze
27
-
28
- singleton_class.prepend CheckForShadowedMethods
29
- end
30
-
31
- # This module is prepended to the singleton class of the including class
32
- # to detect when an override is attempting to re-define any methods.
33
- module CheckForShadowedMethods
34
- def method_added(method_name)
35
- driver_overrides.each do |override|
36
- next unless override.instance_methods.include?(method_name)
37
-
38
- Rails.logger.warn "Driver override method #{override.name}##{method_name} "\
39
- "is shadowed by #{name}##{method_name} and will likely not do anything."
40
- end
41
-
42
- super(method_name)
43
- end
44
- end
45
- end
46
- end