mtrack 1.0.2 → 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: 9f9c9bb07bed7e3b987ad36fc5a7652a0d16c251
4
- data.tar.gz: b979016ffe198365cc5a8cac84cb55a13833598f
3
+ metadata.gz: e4d96deb7df700e5f8bfa2ba688be09d7aa1073a
4
+ data.tar.gz: 927dded6ddd652b48bb95d59e4ea7971dbd084ec
5
5
  SHA512:
6
- metadata.gz: 0652e5ba511e35770f6235913a33d6d3dff5c73e741c6be565380f7ddc31154f27de449ad77b437f7196493cb44a686f2543d4864adb97223a6eed7c7279a5a0
7
- data.tar.gz: 6ae8c5a491700c4936d3c5579731cf0521b85d2d3e7c768d8a71cd57feacd51ed559f4dbf3c12e77fb805d8df77c9ea9df428bc3acbc02897049a217a50f3817
6
+ metadata.gz: 81679f5a7f76711e69250c4009ec6a752f9e90325db75d969c8ce967105294e754bdbef5feae328d554ffc03f259457f63da9a2540b0046a9838bfa1e40a3dd8
7
+ data.tar.gz: 6dd4234f6fe0efda95ea980dbaa903fe7a02963231815a0a25c9d9a53d935f1ceaae86b5b248e8aabfe346f6d6c6f48641e09d141ef4ea269830045b21e201dc
data/Gemfile CHANGED
@@ -7,7 +7,7 @@ group :development do
7
7
  gem "guard-rubocop", "~> 1.2.0"
8
8
  gem "libnotify", "~> 0.8.4"
9
9
  gem "pry", "~> 0.10.1"
10
- gem "rubocop", "~> 0.27.0"
10
+ gem "rubocop", "~> 0.27.1"
11
11
  end
12
12
 
13
13
  group :development, :test do
data/Guardfile CHANGED
@@ -5,6 +5,8 @@ guard :rspec, :cmd => "rspec -fd" do
5
5
  end
6
6
 
7
7
  guard :rubocop do
8
- watch(/.+\.rb$/)
9
- watch(/(?:.+\/)?\.rubocop\.yml$/) {|m| File.dirname(m[0]) }
8
+ watch(/^.+\.rb$/)
9
+ watch(/^(?:.+\/)?\.rubocop\.yml$/) {|m| File.dirname(m[0]) }
10
+ watch(/^(?:.+\/)?.+\.gemspec$/)
11
+ watch(/^(?:.+\/)?(?:Gem|Rake)file$/)
10
12
  end
@@ -0,0 +1,48 @@
1
+ module MTrack
2
+ ##
3
+ # This module is extended by Mixin and all custom extensions of Mixin. You should not extend this module directly,
4
+ # instead simply include Mixin into your custom extension:
5
+ #
6
+ # module MyExtension
7
+ # include MTrack::Mixin
8
+ # # Define custom methods here.
9
+ # end
10
+ #
11
+ # module M
12
+ # extend MyExtension
13
+ # # You can use MTrack's and MyExtension's methods here.
14
+ # end
15
+ #
16
+ # If you're overriding the +extended+ or +included+ methods in your custom extension always make sure to call +super+,
17
+ # so MTrack can be properly initialized.
18
+ module Extension
19
+ private
20
+
21
+ ##
22
+ # call-seq:
23
+ # extended(submodule) => submodule
24
+ #
25
+ # Initializes a State variable on the Class or Module that extended Mixin.
26
+ #
27
+ # Returns passed +submodule+.
28
+ def extended(submodule)
29
+ super
30
+ submodule.instance_eval { @__mtrack__ ||= State.new }
31
+ submodule
32
+ end
33
+
34
+ ##
35
+ # call-seq:
36
+ # included(submodule) => submodule
37
+ #
38
+ # Initializes +submodule+ as a custom extension of Mixin. The new custom extension +submodule+ can then be extended
39
+ # by a Class or Module just like Mixin, or included further to generate other, more specific custom extensions.
40
+ #
41
+ # Returns passed +submodule+.
42
+ def included(submodule)
43
+ super
44
+ submodule.instance_eval { extend Extension }
45
+ submodule
46
+ end
47
+ end
48
+ end
data/lib/mtrack/mixin.rb CHANGED
@@ -1,23 +1,29 @@
1
+ require "mtrack/extension"
1
2
  require "mtrack/state"
2
3
 
3
4
  module MTrack
4
5
  ##
5
6
  # This module provides the #track_methods method to Classes or Modules that
6
- # mix it in. It also enables the extended Class or Module to pass tracked
7
+ # extend it. It also enables the extended Class or Module to pass tracked
7
8
  # methods to its subclasses and submodules.
8
9
  module Mixin
10
+ extend Extension
11
+
9
12
  class << self
10
13
  private
11
14
 
12
15
  ##
13
16
  # call-seq:
14
- # extended(submodule) => submodule
17
+ # init_heir(submodule, state) => submodule
15
18
  #
16
- # Initializes a State variable on the Class or Module that extended Mixin.
19
+ # Sets +state+ as the super-state of +submodule+ (Class or Module).
17
20
  #
18
21
  # Returns passed +submodule+.
19
- def extended(submodule)
20
- submodule.instance_eval { @__mtrack__ ||= State.new }
22
+ def init_heir(submodule, state)
23
+ submodule.instance_eval do
24
+ extend Mixin
25
+ @__mtrack__.add_super_state state
26
+ end
21
27
  submodule
22
28
  end
23
29
 
@@ -102,12 +108,8 @@ module MTrack
102
108
  #
103
109
  # Returns passed +submodule+.
104
110
  def included(submodule)
105
- state = @__mtrack__
106
- submodule.instance_eval do
107
- extend Mixin
108
- @__mtrack__.add_super_state state
109
- end
110
- submodule
111
+ super
112
+ Mixin.send(:init_heir, submodule, @__mtrack__)
111
113
  end
112
114
 
113
115
  ##
@@ -118,7 +120,10 @@ module MTrack
118
120
  # inherited from the current Class.
119
121
  #
120
122
  # Returns passed +submodule+.
121
- alias_method :inherited, :included
123
+ def inherited(submodule)
124
+ super
125
+ Mixin.send(:init_heir, submodule, @__mtrack__)
126
+ end
122
127
 
123
128
  ##
124
129
  # call-seq:
@@ -129,6 +134,7 @@ module MTrack
129
134
  #
130
135
  # Returns passed +name+.
131
136
  def method_added(name)
137
+ super
132
138
  @__mtrack__.delete_undefined name
133
139
  end
134
140
 
@@ -140,6 +146,7 @@ module MTrack
140
146
  #
141
147
  # Returns passed +name+.
142
148
  def method_removed(name)
149
+ super
143
150
  @__mtrack__.delete_tracked name
144
151
  end
145
152
 
@@ -153,6 +160,7 @@ module MTrack
153
160
  #
154
161
  # Returns passed +name+.
155
162
  def method_undefined(name)
163
+ super
156
164
  @__mtrack__.delete_tracked name
157
165
  @__mtrack__.add_undefined name
158
166
  end
@@ -20,5 +20,5 @@
20
20
  # D.tracked_methods #=> #<Set: {:method_1, :method_2, :method_3}>
21
21
  module MTrack
22
22
  # Current version of MTrack.
23
- VERSION = "1.0.2"
23
+ VERSION = "1.1.0"
24
24
  end
@@ -1,4 +1,4 @@
1
1
  inherit_from:
2
- - ../../.rubocop.yml
2
+ - ../.rubocop.yml
3
3
  Metrics/LineLength:
4
4
  Max: 140
@@ -24,10 +24,39 @@ describe MTrack::Mixin do
24
24
  end
25
25
 
26
26
  describe "hierarchy" do
27
+ let(:base_extension_1) do
28
+ Module.new.tap do |m|
29
+ m.module_eval do
30
+ include MTrack::Mixin
31
+ define_method :base_extension_1_meth, METHOD_DEFINITION
32
+ end
33
+ end
34
+ end
35
+
36
+ let(:base_extension_2) do
37
+ Module.new.tap do |m|
38
+ m.module_eval do
39
+ include MTrack::Mixin
40
+ define_method :base_extension_2_meth, METHOD_DEFINITION
41
+ end
42
+ end
43
+ end
44
+
45
+ let(:sub_extension) do
46
+ be = base_extension_1
47
+ Module.new.tap do |m|
48
+ m.module_eval do
49
+ include be
50
+ define_method :sub_extension_meth, METHOD_DEFINITION
51
+ end
52
+ end
53
+ end
54
+
27
55
  let(:base_module_1) do
56
+ ext = sub_extension
28
57
  Module.new.tap do |m|
29
58
  m.module_eval do
30
- extend MTrack::Mixin
59
+ extend ext
31
60
  define_method :unt_1, METHOD_DEFINITION
32
61
  track_methods { define_method :meth, METHOD_DEFINITION }
33
62
  track_methods :numbers do
@@ -40,9 +69,10 @@ describe MTrack::Mixin do
40
69
  end
41
70
 
42
71
  let(:base_module_2) do
72
+ ext = base_extension_2
43
73
  Module.new.tap do |m|
44
74
  m.module_eval do
45
- extend MTrack::Mixin
75
+ extend ext
46
76
  define_method :unt_2, METHOD_DEFINITION
47
77
  track_methods { define_method :meth, METHOD_DEFINITION }
48
78
  track_methods :numbers do
@@ -159,6 +189,10 @@ describe MTrack::Mixin do
159
189
  subject.module_eval { define_method :meth, METHOD_DEFINITION }
160
190
  expect(subject.tracked_methods).to be_empty
161
191
  end
192
+
193
+ it "has custom extensions as ancestors" do
194
+ expect(subject.singleton_methods.map(&:to_sym)).to include(:base_extension_1_meth, :sub_extension_meth)
195
+ end
162
196
  end
163
197
 
164
198
  context "base module 2" do
@@ -183,6 +217,10 @@ describe MTrack::Mixin do
183
217
  subject.module_eval { define_method :meth, METHOD_DEFINITION }
184
218
  expect(subject.tracked_methods).to be_empty
185
219
  end
220
+
221
+ it "has custom extensions as ancestors" do
222
+ expect(subject.singleton_methods.map(&:to_sym)).to include(:base_extension_2_meth)
223
+ end
186
224
  end
187
225
 
188
226
  context "base module 3" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mtrack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel de Oliveira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-07 00:00:00.000000000 Z
11
+ date: 2014-11-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: MTrack extends the functionality of modules and classes and enables them
14
14
  to define public methods within groups. These methods can then be queried back even
@@ -29,12 +29,13 @@ files:
29
29
  - README.md
30
30
  - Rakefile
31
31
  - lib/mtrack.rb
32
+ - lib/mtrack/extension.rb
32
33
  - lib/mtrack/mixin.rb
33
34
  - lib/mtrack/state.rb
34
35
  - lib/mtrack/state/group.rb
35
36
  - lib/mtrack/version.rb
36
37
  - mtrack.gemspec
37
- - spec/lib/.rubocop.yml
38
+ - spec/.rubocop.yml
38
39
  - spec/lib/mtrack/mixin_spec.rb
39
40
  - spec/lib/mtrack/state/group_spec.rb
40
41
  - spec/lib/mtrack/state_spec.rb
@@ -67,7 +68,7 @@ signing_key:
67
68
  specification_version: 4
68
69
  summary: Group and track methods on classes and modules.
69
70
  test_files:
70
- - spec/lib/.rubocop.yml
71
+ - spec/.rubocop.yml
71
72
  - spec/lib/mtrack/mixin_spec.rb
72
73
  - spec/lib/mtrack/state/group_spec.rb
73
74
  - spec/lib/mtrack/state_spec.rb