mtrack 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Guardfile +1 -1
- data/README.md +1 -0
- data/lib/mtrack/core.rb +22 -3
- data/lib/mtrack/module_mixin.rb +2 -12
- data/lib/mtrack/state.rb +16 -6
- data/lib/mtrack/state/group.rb +4 -0
- data/lib/mtrack/version.rb +1 -1
- data/spec/lib/mtrack/module_mixin_spec.rb +13 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bfca617210cbd6c56886b4eb185dc4fd6953204
|
4
|
+
data.tar.gz: d3af2f661de85f44e958ec5090515b40c032bd44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a186ed9e60cd1dec8355f127ae9b5b19000804726b169b0e23baa49c5a2e4610dfd6d13d0a2abe676c5bd4ec375dbe2f5487b448cc5468a7490b6a72d3d7e49a
|
7
|
+
data.tar.gz: 57a5be4b178c3215f3ea0d58cb4632be748be4b2cc2453193aff60b5c53890090af23154f28f4b964309e467eadea1eb29bace8319df13c5011deeb9499aedc3
|
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -11,6 +11,7 @@
|
|
11
11
|
[travis]: http://travis-ci.org/gdeoliveira/mtrack
|
12
12
|
[codeclimate]: https://codeclimate.com/github/gdeoliveira/mtrack
|
13
13
|
[gemnasium]: https://gemnasium.com/gdeoliveira/mtrack
|
14
|
+
[gemnasium]: https://gemnasium.com/gdeoliveira/mtrack#development-dependencies
|
14
15
|
[inch-ci]: http://inch-ci.org/github/gdeoliveira/mtrack
|
15
16
|
|
16
17
|
MTrack extends the functionality of Modules and Classes and enables them to
|
data/lib/mtrack/core.rb
CHANGED
@@ -13,9 +13,7 @@ module MTrack
|
|
13
13
|
# call-seq:
|
14
14
|
# tracked_methods(group_name = nil) => set
|
15
15
|
#
|
16
|
-
# Returns a set containing the currently tracked methods
|
17
|
-
# +group_name+ parameter can be passed to get the tracked methods of groups
|
18
|
-
# othen than the default +nil+ group.
|
16
|
+
# Returns a set containing the currently tracked methods for a +group_name+.
|
19
17
|
#
|
20
18
|
# class C
|
21
19
|
# track_methods :my_group do
|
@@ -75,5 +73,26 @@ module MTrack
|
|
75
73
|
@__mtrack__.delete_tracked name
|
76
74
|
@__mtrack__.add_undefined name
|
77
75
|
end
|
76
|
+
|
77
|
+
##
|
78
|
+
# call-seq:
|
79
|
+
# track_methods_with_block(group_name) {|| ... } => set
|
80
|
+
#
|
81
|
+
# All the methods defined within the block will be tracked under the
|
82
|
+
# +group_name+ parameter.
|
83
|
+
#
|
84
|
+
# Returns a set containing the methods that were defined within the block.
|
85
|
+
def track_methods_with_block(group_name, &b)
|
86
|
+
old_methods = public_instance_methods(false)
|
87
|
+
|
88
|
+
begin
|
89
|
+
module_eval(&b)
|
90
|
+
ensure
|
91
|
+
tracked = (public_instance_methods(false) - old_methods).map(&:to_sym).to_set
|
92
|
+
@__mtrack__[group_name].merge_tracked tracked unless tracked.empty?
|
93
|
+
end
|
94
|
+
|
95
|
+
tracked
|
96
|
+
end
|
78
97
|
end
|
79
98
|
end
|
data/lib/mtrack/module_mixin.rb
CHANGED
@@ -35,18 +35,8 @@ module MTrack
|
|
35
35
|
def track_methods(group_name = nil, &b)
|
36
36
|
@__mtrack__ ||= State.new
|
37
37
|
extend Core
|
38
|
-
|
39
|
-
|
40
|
-
old_methods = public_instance_methods(false)
|
41
|
-
begin
|
42
|
-
module_eval(&b)
|
43
|
-
ensure
|
44
|
-
tracked = (public_instance_methods(false) - old_methods).map(&:to_sym).to_set
|
45
|
-
@__mtrack__[group_name].merge_tracked tracked unless tracked.empty?
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
tracked || Set.new
|
38
|
+
return track_methods_with_block(group_name, &b) if block_given?
|
39
|
+
Set.new
|
50
40
|
end
|
51
41
|
end
|
52
42
|
end
|
data/lib/mtrack/state.rb
CHANGED
@@ -14,6 +14,9 @@ module MTrack
|
|
14
14
|
#
|
15
15
|
# Creates a new State instance. An optional +super_state+ parameter can be
|
16
16
|
# passed that will be added to #super_states.
|
17
|
+
#
|
18
|
+
# super_state = MTrack::State.new
|
19
|
+
# sub_state = MTrack::State.new(super_state)
|
17
20
|
def initialize(super_state = nil)
|
18
21
|
self.groups = {}
|
19
22
|
self.super_states = super_state ? Set[super_state] : Set.new
|
@@ -24,8 +27,9 @@ module MTrack
|
|
24
27
|
# call-seq:
|
25
28
|
# state[group_name] => group
|
26
29
|
#
|
27
|
-
#
|
28
|
-
#
|
30
|
+
# Accepts a +group_name+ passed as a parameter.
|
31
|
+
#
|
32
|
+
# Returns an existing or a new group associated with +group_name+.
|
29
33
|
def [](group_name)
|
30
34
|
groups[group_name] ||= Group.new
|
31
35
|
end
|
@@ -34,7 +38,9 @@ module MTrack
|
|
34
38
|
# call-seq:
|
35
39
|
# add_super_state(state) => state
|
36
40
|
#
|
37
|
-
# Adds a new state to #super_states.
|
41
|
+
# Adds a new +state+ to the #super_states set.
|
42
|
+
#
|
43
|
+
# Returns passed +state+.
|
38
44
|
def add_super_state(state)
|
39
45
|
super_states.add state
|
40
46
|
state
|
@@ -45,6 +51,8 @@ module MTrack
|
|
45
51
|
# add_undefined(name) => name
|
46
52
|
#
|
47
53
|
# Adds +name+ to the #undefined methods set.
|
54
|
+
#
|
55
|
+
# Returns passed +name+.
|
48
56
|
def add_undefined(name)
|
49
57
|
undefined.add name
|
50
58
|
name
|
@@ -55,6 +63,8 @@ module MTrack
|
|
55
63
|
# delete_tracked(name) => name
|
56
64
|
#
|
57
65
|
# Removes method +name+ from all #groups.
|
66
|
+
#
|
67
|
+
# Returns passed +name+.
|
58
68
|
def delete_tracked(name)
|
59
69
|
groups.each {|k, v| v.delete_tracked name }
|
60
70
|
name
|
@@ -65,6 +75,8 @@ module MTrack
|
|
65
75
|
# delete_undefined(name) => name
|
66
76
|
#
|
67
77
|
# Removes +name+ from the #undefined methods set.
|
78
|
+
#
|
79
|
+
# Returns passed +name+.
|
68
80
|
def delete_undefined(name)
|
69
81
|
undefined.delete name
|
70
82
|
name
|
@@ -74,9 +86,7 @@ module MTrack
|
|
74
86
|
# call-seq:
|
75
87
|
# tracked(group_name = nil) => set
|
76
88
|
#
|
77
|
-
# Returns a set containing the currently tracked methods
|
78
|
-
# +group_name+ parameter can be passed to get the tracked methods of groups
|
79
|
-
# othen than the default +nil+ group.
|
89
|
+
# Returns a set containing the currently tracked methods for a +group_name+.
|
80
90
|
def tracked(group_name = nil)
|
81
91
|
ret_val = merge_super_states group_name
|
82
92
|
ret_val.merge groups[group_name].tracked unless groups[group_name].nil?
|
data/lib/mtrack/state/group.rb
CHANGED
@@ -21,6 +21,8 @@ module MTrack
|
|
21
21
|
# delete_tracked(name) => name
|
22
22
|
#
|
23
23
|
# Removes method +name+ from tracked methods.
|
24
|
+
#
|
25
|
+
# Returns passed +name+.
|
24
26
|
def delete_tracked(name)
|
25
27
|
@tracked.delete name
|
26
28
|
name
|
@@ -31,6 +33,8 @@ module MTrack
|
|
31
33
|
# merge_tracked(names) => names
|
32
34
|
#
|
33
35
|
# Adds method +names+ to tracked methods.
|
36
|
+
#
|
37
|
+
# Returns passed +names+.
|
34
38
|
def merge_tracked(names)
|
35
39
|
@tracked.merge names
|
36
40
|
names
|
data/lib/mtrack/version.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe MTrack::ModuleMixin do
|
4
|
+
describe "#track_methods" do
|
5
|
+
context "no block given" do
|
6
|
+
it "returns an empty set" do
|
7
|
+
ret_val = ::Module.new.module_eval { track_methods :group }
|
8
|
+
expect(ret_val).to be_a(Set)
|
9
|
+
expect(ret_val).to be_empty
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
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: 0.0.
|
4
|
+
version: 0.0.4
|
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-08-
|
11
|
+
date: 2014-08-22 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
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- lib/mtrack/version.rb
|
36
36
|
- mtrack.gemspec
|
37
37
|
- spec/lib/mtrack/core_spec.rb
|
38
|
+
- spec/lib/mtrack/module_mixin_spec.rb
|
38
39
|
- spec/lib/mtrack/state/group_spec.rb
|
39
40
|
- spec/lib/mtrack/state_spec.rb
|
40
41
|
- spec/lib/mtrack/version_spec.rb
|
@@ -67,6 +68,7 @@ specification_version: 4
|
|
67
68
|
summary: Group and track methods on classes and modules.
|
68
69
|
test_files:
|
69
70
|
- spec/lib/mtrack/core_spec.rb
|
71
|
+
- spec/lib/mtrack/module_mixin_spec.rb
|
70
72
|
- spec/lib/mtrack/state/group_spec.rb
|
71
73
|
- spec/lib/mtrack/state_spec.rb
|
72
74
|
- spec/lib/mtrack/version_spec.rb
|