instance_tracker 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +6 -28
- data/lib/instance_tracker/trackable.rb +0 -16
- data/lib/instance_tracker/version.rb +1 -1
- data/spec/plugin/trackable_spec.rb +2 -21
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjBjNjAwNTcyOTdjMTQ4ODE0MTQ5ZTU3YzEwN2M3ZWNjYWQ4YWQwYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YjUyNWVlOWI1ZThlMzE2MTQ5OTNjMWVhMDkzYzNmMWY4M2ViM2RhZQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjlkOTg4MTFmZTljMTJkODMxYTE1MzVhMjIxYWI3YWY4MDBmYTk2YTc3MTY3
|
10
|
+
Y2NkZjg5YzMwOWYwNjIzZmZkMzBiMjZmOTYwN2Q2YWExYzE1NTA5NjhlODdi
|
11
|
+
MjZjNGYxMjZmOTcxMzI0NTBkMzFmMTc3ZWYyOGE2MjY1OGZhN2I=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZGIxNmY0MGVjYWVlYjQyYmJjZmQ1YzdmNmI5NjBhZjFjMGI0NDdiNjk5MGI0
|
14
|
+
ODg3ZDQ1ZGMwOGRmNzkxMTgxNjE1MWRkZTI4Y2MyYmY3YmI1ZGFjNjdmYjQ0
|
15
|
+
MTkyM2VjNTg2NWZkYjFlMWNkMTY2MzljMmZmMmJiZjRiN2UzNzE=
|
data/README.md
CHANGED
@@ -19,46 +19,24 @@ Or install it yourself as:
|
|
19
19
|
## API Summary
|
20
20
|
|
21
21
|
Start by including `InstanceTracker::Trackable` within classes in which
|
22
|
-
you want to track an instance variable
|
23
|
-
|
22
|
+
you want to track an instance variable; this provides the class
|
23
|
+
a `track` class method which allows you to define which instance
|
24
|
+
variable to track.
|
24
25
|
|
25
26
|
```ruby
|
26
27
|
class Foo
|
27
|
-
def initialize(wrapper)
|
28
|
-
@wrapper = wrapper
|
29
|
-
end
|
30
|
-
|
31
28
|
include InstanceTracker::Trackable
|
32
29
|
track :wrapper
|
33
|
-
end
|
34
|
-
```
|
35
|
-
|
36
|
-
This provides the class a `track` class method which allows you to define which
|
37
|
-
instance variable to track.
|
38
|
-
|
39
|
-
|
40
|
-
You are now able to access the `wrapper` by simply calling
|
41
|
-
`trackable_instance` from any instance of your class.
|
42
30
|
|
43
|
-
The included class can also override `after_initialize` (implemented as
|
44
|
-
a simple interface within `InstanceTracker::Trackable`) which will be
|
45
|
-
called as soon as the included class is instantiated.
|
46
|
-
|
47
|
-
```ruby
|
48
|
-
class Foo
|
49
31
|
def initialize(wrapper)
|
50
32
|
@wrapper = wrapper
|
51
33
|
end
|
52
|
-
|
53
|
-
def after_initialize
|
54
|
-
trackable_instance.meaning_of_life = "42"
|
55
|
-
end
|
56
|
-
|
57
|
-
include InstanceTracker::Trackable
|
58
|
-
track :wrapper
|
59
34
|
end
|
60
35
|
```
|
61
36
|
|
37
|
+
You are now able to access the `wrapper` by simply calling
|
38
|
+
`trackable_instance` from any instance of your class.
|
39
|
+
|
62
40
|
## Contributing
|
63
41
|
|
64
42
|
1. Fork it
|
@@ -19,22 +19,6 @@ module InstanceTracker
|
|
19
19
|
|
20
20
|
def included _klass
|
21
21
|
_klass.class_eval do
|
22
|
-
alias_method :initialize_old, :initialize
|
23
|
-
alias_method :after_initialize_old, :after_initialize if method_defined? "after_initialize"
|
24
|
-
|
25
|
-
def initialize
|
26
|
-
initialize_old
|
27
|
-
after_initialize
|
28
|
-
end
|
29
|
-
|
30
|
-
if method_defined? "after_initialize"
|
31
|
-
def after_initialize
|
32
|
-
after_initialize_old
|
33
|
-
end
|
34
|
-
else
|
35
|
-
def after_initialize; end
|
36
|
-
end
|
37
|
-
|
38
22
|
include InstanceMethods
|
39
23
|
extend ClassMethods
|
40
24
|
end
|
@@ -5,13 +5,12 @@ module InstanceTracker
|
|
5
5
|
describe Trackable do
|
6
6
|
|
7
7
|
class SpecHarness
|
8
|
+
include InstanceTracker::Trackable
|
9
|
+
track :context
|
8
10
|
|
9
11
|
def initialize
|
10
12
|
@context = "Foo"
|
11
13
|
end
|
12
|
-
|
13
|
-
include InstanceTracker::Trackable
|
14
|
-
track :context
|
15
14
|
end
|
16
15
|
|
17
16
|
let(:subject) { SpecHarness.new }
|
@@ -21,23 +20,5 @@ module InstanceTracker
|
|
21
20
|
expect(subject.trackable_instance).to eq("Foo")
|
22
21
|
end
|
23
22
|
|
24
|
-
it "should already implement `#after_initialize` to return nil" do
|
25
|
-
expect(subject.after_initialize).to be_nil
|
26
|
-
end
|
27
|
-
|
28
|
-
context "when `#after_initialize` is overriden" do
|
29
|
-
|
30
|
-
it "should call the overriden implementation of `#after_initialize`" do
|
31
|
-
SpecHarness.class_eval do
|
32
|
-
def after_initialize
|
33
|
-
true
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
expect(subject.after_initialize).to be
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
23
|
end
|
43
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: instance_tracker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael de Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|