instance_tracker 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e07a37fdbc098d6c237777fb8a8fe015a282cdb7
4
- data.tar.gz: d29f55338021f42da49ef5b255221add952eec30
5
- SHA512:
6
- metadata.gz: 8ae681ade48cc0a46b1f89150731ef971da8907491789058df97479af2e2f6e0d97bf9389221a9205e0728f713644b6497f2339d0ed089c87dbd66d59cc2aafe
7
- data.tar.gz: 02296562de4f8bf331da08f5c181927d1cdd27e18804591a1288d5764962a6d61974512b78f36a94e48eef33079f0ac7eccb702fae1c7528424c46bc26df55af
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ N2ZkNjc1YzUwMGE1MGRhMGUxMmFkZDExYzk3NDY2MGU3YjU0ODVhYw==
5
+ data.tar.gz: !binary |-
6
+ ZDUzNmI5ODZhNzZkZTk5YTUxZDBhYTdiYmE5ZjJmMDA2ZDYwZGExOA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NzVhNmNlYjY3ZmI1ZjMxYWI1ZWVkMTgxMzQzNjE5ZDNjMTJiMTZjZmU4MGJm
10
+ MzliNTM3ZTFlZTZhZjRjNjIwZTJlY2VkZGNjNDRhMjg1MzRmMjNjMjcxZjgw
11
+ NWVhNjViODc1NjRiZjZlNTBhZTE1YzEwMzIxNWI1NTlkNTZlM2Q=
12
+ data.tar.gz: !binary |-
13
+ Mzc4M2I3ZjkyNzcwYzZhN2EwYWE4M2EzYzI4YjkyNzg5MmU2MDIzMTVhZGQ2
14
+ NTc3NzE5OGZlMDZiYzIwMGU2ZDhiZmM2ZTM1YWY5NzVmZmQ0MjNhNzIxZjAx
15
+ ODRjYmViMjVhNTAyYWE3MzdhZGUwNTBiZjI2NDI5MGE2OTQ4ODU=
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.0.0-p247
1
+ 1.9.3-p392
data/README.md CHANGED
@@ -19,24 +19,46 @@ 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; this provides the class
23
- a `track` class method which allows you to define which instance
24
- variable to track.
22
+ you want to track an instance variable. This should occur after the
23
+ call to `initialize`.
25
24
 
26
25
  ```ruby
27
26
  class Foo
28
- include InstanceTracker::Trackable
29
- track :wrapper
30
-
31
27
  def initialize(wrapper)
32
28
  @wrapper = wrapper
33
29
  end
30
+
31
+ include InstanceTracker::Trackable
32
+ track :wrapper
34
33
  end
35
34
  ```
36
35
 
36
+ This provides the class a `track` class method which allows you to define which
37
+ instance variable to track.
38
+
39
+
37
40
  You are now able to access the `wrapper` by simply calling
38
41
  `trackable_instance` from any instance of your class.
39
42
 
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
+ def initialize(wrapper)
50
+ @wrapper = wrapper
51
+ end
52
+
53
+ def after_initialize
54
+ trackable_instance.meaning_of_life = "42"
55
+ end
56
+
57
+ include InstanceTracker::Trackable
58
+ track :wrapper
59
+ end
60
+ ```
61
+
40
62
  ## Contributing
41
63
 
42
64
  1. Fork it
@@ -19,6 +19,22 @@ 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
+
22
38
  include InstanceMethods
23
39
  extend ClassMethods
24
40
  end
@@ -1,3 +1,3 @@
1
1
  module InstanceTracker
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -5,12 +5,13 @@ module InstanceTracker
5
5
  describe Trackable do
6
6
 
7
7
  class SpecHarness
8
- include InstanceTracker::Trackable
9
- track :context
10
8
 
11
9
  def initialize
12
10
  @context = "Foo"
13
11
  end
12
+
13
+ include InstanceTracker::Trackable
14
+ track :context
14
15
  end
15
16
 
16
17
  let(:subject) { SpecHarness.new }
@@ -20,5 +21,23 @@ module InstanceTracker
20
21
  expect(subject.trackable_instance).to eq("Foo")
21
22
  end
22
23
 
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
+
23
42
  end
24
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instance_tracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael de Silva
@@ -28,84 +28,84 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mocha
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ! '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ! '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: guard-rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ! '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ! '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: yard
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ! '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ! '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: A Simple Ruby DSL for Instance Tracking
@@ -139,12 +139,12 @@ require_paths:
139
139
  - lib
140
140
  required_ruby_version: !ruby/object:Gem::Requirement
141
141
  requirements:
142
- - - '>='
142
+ - - ! '>='
143
143
  - !ruby/object:Gem::Version
144
144
  version: 1.9.3
145
145
  required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  requirements:
147
- - - '>='
147
+ - - ! '>='
148
148
  - !ruby/object:Gem::Version
149
149
  version: '0'
150
150
  requirements: []