concerning 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/concerning.rb +11 -125
- data/lib/concerning/module_extension.rb +147 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 454efdfc441f4945f845b6c1d73cbd5359c1d921
|
4
|
+
data.tar.gz: 1fb3b505754eed97217ae9661d152bec8ab2a674
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8d1462bf277d70644c760e45947e76813bcea4f76ad7828959d4bf55ff75787ffa90cc0dfb283618ae4a32c8ea3ad6427b2ac4cb3cfd5588d773dad76a74fae
|
7
|
+
data.tar.gz: b0726d7cfdb19e3f0b1febc8dcbac4ffb3dc96a622fb31abd27a82ccc289402473a55b54b560309dbdffc675a38fb65ebc4e10d7231531c5fd5ecea3cfbcf506
|
data/lib/concerning.rb
CHANGED
@@ -1,126 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
# class Todo
|
13
|
-
# # Other todo implementation
|
14
|
-
# # ...
|
15
|
-
#
|
16
|
-
# ## Event tracking
|
17
|
-
# has_many :events
|
18
|
-
#
|
19
|
-
# before_create :track_creation
|
20
|
-
# after_destroy :track_deletion
|
21
|
-
#
|
22
|
-
# private
|
23
|
-
# def track_creation
|
24
|
-
# # ...
|
25
|
-
# end
|
26
|
-
# end
|
27
|
-
#
|
28
|
-
#
|
29
|
-
# Trying on a noisy embedded module:
|
30
|
-
#
|
31
|
-
# class Todo
|
32
|
-
# # Other todo implementation
|
33
|
-
# # ...
|
34
|
-
#
|
35
|
-
# module EventTracking
|
36
|
-
# extend ActiveSupport::Concern
|
37
|
-
#
|
38
|
-
# included do
|
39
|
-
# has_many :events
|
40
|
-
# before_create :track_creation
|
41
|
-
# after_destroy :track_deletion
|
42
|
-
# end
|
43
|
-
#
|
44
|
-
# private
|
45
|
-
# def track_creation
|
46
|
-
# # ...
|
47
|
-
# end
|
48
|
-
# end
|
49
|
-
# include EventTracking
|
50
|
-
# end
|
51
|
-
#
|
52
|
-
#
|
53
|
-
# Once our chunk of behavior starts pushing the scroll-to-understand it
|
54
|
-
# boundary, we give in and move it to a separate file. At this size, the
|
55
|
-
# overhead feels in good proportion to the size of our extraction, despite
|
56
|
-
# diluting our at-a-glance sense of how things really work.
|
57
|
-
#
|
58
|
-
# Mix-in noise exiled to its own file:
|
59
|
-
#
|
60
|
-
# class Todo
|
61
|
-
# # Other todo implementation
|
62
|
-
# # ...
|
63
|
-
#
|
64
|
-
# include TodoEventTracking
|
65
|
-
# end
|
66
|
-
#
|
67
|
-
#
|
68
|
-
# Introducing Module#concerning.
|
69
|
-
#
|
70
|
-
# By quieting the mix-in noise, we arrive at a natural, low-ceremony way to
|
71
|
-
# do bite-sized modularity:
|
72
|
-
#
|
73
|
-
# class Todo
|
74
|
-
# # Other todo implementation
|
75
|
-
# # ...
|
76
|
-
#
|
77
|
-
# concerning :EventTracking do
|
78
|
-
# included do
|
79
|
-
# has_many :events
|
80
|
-
# before_create :track_creation
|
81
|
-
# after_destroy :track_deletion
|
82
|
-
# end
|
83
|
-
#
|
84
|
-
# private
|
85
|
-
# def track_creation
|
86
|
-
# # ...
|
87
|
-
# end
|
88
|
-
# end
|
89
|
-
# end
|
90
|
-
#
|
91
|
-
# Todo.ancestors
|
92
|
-
# # => Todo, Todo::EventTracking, Object
|
93
|
-
#
|
94
|
-
#
|
95
|
-
# This small step forward has some wonderful ripple effects. We can:
|
96
|
-
# * grok the behaviors that compose our class in one glance
|
97
|
-
# * clean up junk drawer classes by encapsulating their concerns
|
98
|
-
# * stop leaning on protected/private for "internal stuff" modularity
|
99
|
-
module Concerning
|
100
|
-
# Define a new concern and mix it in.
|
101
|
-
def concerning(topic, &block)
|
102
|
-
include concern(topic, &block)
|
103
|
-
end
|
104
|
-
|
105
|
-
# A low-cruft shortcut to define a concern.
|
106
|
-
#
|
107
|
-
# concern :EventTracking do
|
108
|
-
# ...
|
109
|
-
# end
|
110
|
-
#
|
111
|
-
# module EventTracking
|
112
|
-
# extend ActiveSupport::Concern
|
113
|
-
#
|
114
|
-
# ...
|
115
|
-
# end
|
116
|
-
def concern(topic, &module_definition)
|
117
|
-
require 'active_support/concern'
|
118
|
-
|
119
|
-
const_set topic, Module.new {
|
120
|
-
extend ActiveSupport::Concern
|
121
|
-
module_eval(&module_definition)
|
122
|
-
}
|
123
|
-
end
|
124
|
-
end
|
125
|
-
include Concerning
|
1
|
+
# This library was merged to Rails 4.1.
|
2
|
+
#
|
3
|
+
# Prefer Active Support's implementation if it's available.
|
4
|
+
#
|
5
|
+
# This allows libraries which support multiple Rails versions to depend on
|
6
|
+
# `concerning` without worrying about implementation collision. This lib
|
7
|
+
# will step aside if it sees its work is done.
|
8
|
+
begin
|
9
|
+
require 'active_support/core_ext/module/concerning'
|
10
|
+
rescue LoadError
|
11
|
+
require 'concerning/module_extension'
|
126
12
|
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
class Module
|
2
|
+
# We often find ourselves with a medium-sized chunk of behavior that we'd
|
3
|
+
# like to extract, but only mix in to a single class.
|
4
|
+
#
|
5
|
+
# We typically choose to leave the implementation directly in the class,
|
6
|
+
# perhaps with a comment, because the mental and visual overhead of defining
|
7
|
+
# a module, making it a Concern, and including it is just too great.
|
8
|
+
#
|
9
|
+
#
|
10
|
+
# Using comments as lightweight modularity:
|
11
|
+
#
|
12
|
+
# class Todo
|
13
|
+
# # Other todo implementation
|
14
|
+
# # ...
|
15
|
+
#
|
16
|
+
# ## Event tracking
|
17
|
+
# has_many :events
|
18
|
+
#
|
19
|
+
# before_create :track_creation
|
20
|
+
# after_destroy :track_deletion
|
21
|
+
#
|
22
|
+
# def self.next_by_event
|
23
|
+
# # ...
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# private
|
27
|
+
# def track_creation
|
28
|
+
# # ...
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
#
|
33
|
+
# Trying on a noisy embedded module:
|
34
|
+
#
|
35
|
+
# class Todo
|
36
|
+
# # Other todo implementation
|
37
|
+
# # ...
|
38
|
+
#
|
39
|
+
# module EventTracking
|
40
|
+
# extend ActiveSupport::Concern
|
41
|
+
#
|
42
|
+
# included do
|
43
|
+
# has_many :events
|
44
|
+
# before_create :track_creation
|
45
|
+
# after_destroy :track_deletion
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# module ClassMethods
|
49
|
+
# def next_by_event
|
50
|
+
# # ...
|
51
|
+
# end
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# private
|
55
|
+
# def track_creation
|
56
|
+
# # ...
|
57
|
+
# end
|
58
|
+
# end
|
59
|
+
# include EventTracking
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
#
|
63
|
+
# Once our chunk of behavior starts pushing the scroll-to-understand it
|
64
|
+
# boundary, we give in and move it to a separate file. At this size, the
|
65
|
+
# overhead feels in good proportion to the size of our extraction, despite
|
66
|
+
# diluting our at-a-glance sense of how things really work.
|
67
|
+
#
|
68
|
+
# Mix-in noise exiled to its own file:
|
69
|
+
#
|
70
|
+
# class Todo
|
71
|
+
# # Other todo implementation
|
72
|
+
# # ...
|
73
|
+
#
|
74
|
+
# include TodoEventTracking
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
#
|
78
|
+
# Introducing Module#concerning.
|
79
|
+
#
|
80
|
+
# By quieting the mix-in noise, we arrive at a natural, low-ceremony way to
|
81
|
+
# do bite-sized modularity:
|
82
|
+
#
|
83
|
+
# class Todo
|
84
|
+
# # Other todo implementation
|
85
|
+
# # ...
|
86
|
+
#
|
87
|
+
# concerning :EventTracking do
|
88
|
+
# included do
|
89
|
+
# has_many :events
|
90
|
+
# before_create :track_creation
|
91
|
+
# after_destroy :track_deletion
|
92
|
+
# end
|
93
|
+
#
|
94
|
+
# class_methods do
|
95
|
+
# def next_by_event
|
96
|
+
# # ...
|
97
|
+
# end
|
98
|
+
# end
|
99
|
+
#
|
100
|
+
# private
|
101
|
+
# def track_creation
|
102
|
+
# # ...
|
103
|
+
# end
|
104
|
+
# end
|
105
|
+
# end
|
106
|
+
#
|
107
|
+
# Todo.ancestors
|
108
|
+
# # => Todo, Todo::EventTracking, Object
|
109
|
+
#
|
110
|
+
#
|
111
|
+
# This small step forward has some wonderful ripple effects. We can:
|
112
|
+
# * grok the behaviors that compose our class in one glance
|
113
|
+
# * clean up junk drawer classes by encapsulating their concerns
|
114
|
+
# * stop leaning on protected/private for "internal stuff" modularity
|
115
|
+
module Concerning
|
116
|
+
# Define a new concern and mix it in.
|
117
|
+
def concerning(topic, &block)
|
118
|
+
include concern(topic, &block)
|
119
|
+
end
|
120
|
+
|
121
|
+
# Add class methods via the concern.
|
122
|
+
def class_methods(&block)
|
123
|
+
const_set :ClassMethods, Module.new(&block)
|
124
|
+
end
|
125
|
+
|
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
|
+
require 'active_support/concern'
|
139
|
+
|
140
|
+
const_set topic, Module.new {
|
141
|
+
extend ActiveSupport::Concern
|
142
|
+
module_eval(&module_definition)
|
143
|
+
}
|
144
|
+
end
|
145
|
+
end
|
146
|
+
include Concerning
|
147
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: concerning
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Kemper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -39,13 +39,14 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description:
|
42
|
-
email: jeremy@
|
42
|
+
email: jeremy@basecamp.com
|
43
43
|
executables: []
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
46
46
|
files:
|
47
|
+
- ./lib/concerning/module_extension.rb
|
47
48
|
- ./lib/concerning.rb
|
48
|
-
homepage: https://github.com/
|
49
|
+
homepage: https://github.com/basecamp/concerning
|
49
50
|
licenses:
|
50
51
|
- MIT
|
51
52
|
metadata: {}
|
@@ -65,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
66
|
version: '0'
|
66
67
|
requirements: []
|
67
68
|
rubyforge_project:
|
68
|
-
rubygems_version: 2.
|
69
|
+
rubygems_version: 2.1.11
|
69
70
|
signing_key:
|
70
71
|
specification_version: 4
|
71
72
|
summary: Separating small concerns
|