concerning 1.0.3 → 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
  SHA1:
3
- metadata.gz: 46300e9d1f6336b137f30a7ce604b609af70949b
4
- data.tar.gz: 5af204914956c879ab923da970083186eed8ea5a
3
+ metadata.gz: bba544478b9125ab14ef5cbe4c9f76599019ba15
4
+ data.tar.gz: f54ab418712a3135f16c3f2ee4b82cb2c8f5a3a4
5
5
  SHA512:
6
- metadata.gz: 8134f6abaf203e3d1d3e8397ceb14e2868307a07051f0f5dbffb6f72c7f32997537b5ff39361ef58b6aaf180a2039c3166d1967dd410149f5cabea568bfe28b9
7
- data.tar.gz: 99bd868353c2e2d28e5f2b7c22ef2f4c03da6dafd5fbfb58b63325640a0ef61fcaf3005784b2a7eff4b1b27fb6f1ce9f83341320fea565f10c23afb1e8462dd3
6
+ metadata.gz: 015670567443a9a37ef4a204dbbcc4d12dc9e4ea9ee6c6ce42792e860c89afa25ddf2bafe8c3c9cf24420d6d81e0213a75069bf10ea1d2f6c0d79a734e76c5fa
7
+ data.tar.gz: 4ee89b3d9e83bba243fbe1428df4fea1dfe824e2ea30e8d6ec3f66ac898ce0a20ec6430d108a6e4eab2a78dc1edb678397ae8937e808608d760ef83a0f6ecdb3
@@ -5,8 +5,24 @@
5
5
  # This allows libraries which support multiple Rails versions to depend on
6
6
  # `concerning` without worrying about implementation collision. This lib
7
7
  # will step aside if it sees its work is done.
8
+
9
+ require 'active_support/concern'
10
+
11
+ # Check for Concern#class_methods
12
+ if !ActiveSupport::Concern.method_defined?(:class_methods)
13
+ require 'concerning/concern_class_methods'
14
+ end
15
+
16
+ # Check for Module#concerning
8
17
  begin
9
18
  require 'active_support/core_ext/module/concerning'
10
19
  rescue LoadError
11
- require 'concerning/extension'
20
+ require 'concerning/module_concerning'
21
+ end
22
+
23
+ # Check for Kernel#concern
24
+ begin
25
+ require 'active_support/core_ext/kernel/concern'
26
+ rescue LoadError
27
+ require 'concerning/kernel_concern'
12
28
  end
@@ -0,0 +1,11 @@
1
+ module ActiveSupport::Concern
2
+ # Provide a class_methods alternative to ClassMethods since defining
3
+ # a constant within a block doesn't work as folks would expect.
4
+ def class_methods(&class_methods_module_definition)
5
+ mod = const_defined?(:ClassMethods) ?
6
+ const_get(:ClassMethods) :
7
+ const_set(:ClassMethods, Module.new)
8
+
9
+ mod.module_eval(&class_methods_module_definition)
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ module Kernel
2
+ # A shortcut to define a toplevel concern, not within a module.
3
+ def concern(topic, &module_definition)
4
+ ::Object.concern topic, &module_definition
5
+ end
6
+ end
@@ -115,41 +115,28 @@ class Module
115
115
  # * clean up junk drawer classes by encapsulating their concerns
116
116
  # * stop leaning on protected/private for "internal stuff" modularity
117
117
  module Concerning
118
+ # Define a new concern and mix it in.
118
119
  def concerning(topic, &block)
119
120
  include concern(topic, &block)
120
121
  end
121
- end
122
- include Concerning # We do this mixin just for nice RDoc.
123
- end
124
122
 
125
- module Kernel
126
- # A low-cruft shortcut to define a concern.
127
- #
128
- # concern :EventTracking do
129
- # ...
130
- # end
131
- #
132
- # module EventTracking
133
- # extend ActiveSupport::Concern
134
- #
135
- # ...
136
- # end
137
- def concern(topic, &module_definition)
138
- const_set topic, Module.new {
139
- extend ActiveSupport::Concern
140
- module_eval(&module_definition)
141
- }
123
+ # A low-cruft shortcut to define a concern.
124
+ #
125
+ # concern :EventTracking do
126
+ # ...
127
+ # end
128
+ #
129
+ # module EventTracking
130
+ # extend ActiveSupport::Concern
131
+ #
132
+ # ...
133
+ # end
134
+ def concern(topic, &module_definition)
135
+ const_set topic, Module.new {
136
+ extend ActiveSupport::Concern
137
+ module_eval(&module_definition)
138
+ }
139
+ end
142
140
  end
143
- end
144
-
145
- # Provide a class_methods alternative to ClassMethods since defining
146
- # a constant within a block doesn't work as folks would expect.
147
- ActiveSupport::Concern.module_eval do
148
- def class_methods(&class_methods_module_definition)
149
- mod = const_defined?(:ClassMethods) ?
150
- const_get(:ClassMethods) :
151
- const_set(:ClassMethods, Module.new)
152
-
153
- mod.module_eval(&class_methods_module_definition)
154
- end unless method_defined? :class_methods
141
+ include Concerning # We do this mixin just for nice RDoc.
155
142
  end
@@ -0,0 +1 @@
1
+ KERNEL_CONCERN_DEFERRED_TO_ACTIVE_SUPPORT = true
@@ -1 +1 @@
1
- CONCERNING_DEFERRED_TO_ACTIVE_SUPPORT = true
1
+ MODULE_CONCERNING_DEFERRED_TO_ACTIVE_SUPPORT = true
@@ -33,7 +33,7 @@ class ConcernTest < Minitest::Test
33
33
  end
34
34
 
35
35
  def test_may_be_defined_at_toplevel
36
- mod = Kernel.concern(:Foo) { }
36
+ mod = ::TOPLEVEL_BINDING.eval 'concern(:Foo) { }'
37
37
  assert_equal mod, ::Foo
38
38
  assert_kind_of ActiveSupport::Concern, ::Foo
39
39
  assert !Object.ancestors.include?(::Foo), mod.ancestors.inspect
@@ -83,7 +83,8 @@ class ForwardCompatibilityWithRails41Test < Minitest::Test
83
83
  with_stubbed_active_support_in_load_path do
84
84
  require 'concerning'
85
85
  end
86
- assert defined?(::CONCERNING_DEFERRED_TO_ACTIVE_SUPPORT)
86
+ assert defined?(::MODULE_CONCERNING_DEFERRED_TO_ACTIVE_SUPPORT)
87
+ assert defined?(::KERNEL_CONCERN_DEFERRED_TO_ACTIVE_SUPPORT)
87
88
  end
88
89
 
89
90
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: concerning
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Kemper
@@ -44,8 +44,11 @@ executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
- - ./lib/concerning/extension.rb
47
+ - ./lib/concerning/concern_class_methods.rb
48
+ - ./lib/concerning/kernel_concern.rb
49
+ - ./lib/concerning/module_concerning.rb
48
50
  - ./lib/concerning.rb
51
+ - ./test/active_support_stub/active_support/core_ext/kernel/concern.rb
49
52
  - ./test/active_support_stub/active_support/core_ext/module/concerning.rb
50
53
  - ./test/concerning_test.rb
51
54
  homepage: https://github.com/basecamp/concerning
@@ -73,5 +76,6 @@ signing_key:
73
76
  specification_version: 4
74
77
  summary: Separating small concerns
75
78
  test_files:
79
+ - ./test/active_support_stub/active_support/core_ext/kernel/concern.rb
76
80
  - ./test/active_support_stub/active_support/core_ext/module/concerning.rb
77
81
  - ./test/concerning_test.rb