inheritance_module_eval 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,12 +2,21 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
- .idea/
5
+ .idea/*
6
6
  doc/
7
- log/*.log
8
- /tmp/
9
- tmp/
7
+ log/*
8
+ tmp/*
10
9
  db/*.sqlite3
11
10
  /coverage
12
11
  /coverage.data
13
12
  /.yardoc
13
+ .rvmrc
14
+
15
+ ## generic files to ignore
16
+ *~
17
+ *.lock
18
+ *.DS_Store
19
+ *.swp
20
+ *.out
21
+ *.swo
22
+ *.md.html
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,161 @@
1
+ Contributing to Inheritance Module Eval
2
+ ==========================
3
+ Inheritance Module Eval is an open source project. Anyone can use the code, but more importantly, anyone can contribute. This is a
4
+ group effort and we value your input. Please consider making a contribution to help improve the Inheritance Module Eval. This
5
+ guide covers:
6
+
7
+ * How to file a ticket when you discover a bug
8
+ * How to contribute fixes and improvements to the core
9
+ * Information on how to improve the documentation
10
+
11
+ 1. Who can Contribute?
12
+ ----------------------
13
+ Inheritance Module Eval is an open source project and as such contributions are always welcome. Our community is one which
14
+ encourages involvement from all developers regardless of their ability level. We ask that you be patient with the
15
+ other members of the community and maintain a respectful attitude towards other people’s work. Open source is a
16
+ great way to learn a new technology so don’t be afraid to jump right in, even if you are new to Ruby/Rails.
17
+
18
+ 2. Before you Contribute
19
+ ------------------------
20
+ Open source projects tend to be a collaborative effort. Since many people are relying upon Inheritance Module Eval for their real
21
+ world applications, changes to the code can have major implications. Before you write a bug fix or code a new
22
+ feature, you should find out if anybody is interested in your proposed change. You may find that the thing you’re
23
+ trying to “fix” is actually desired behavior. You might also discover that someone else is working on it. Either
24
+ way you can save yourself valuable time by announcing your intentions before starting work.
25
+
26
+ ### 2.1. Notification via Ticket
27
+
28
+ You can also search existing bug reports/issues and file a new one if you do not find an issue relevant to your
29
+ proposed change. See Filing an Issue for more details.
30
+
31
+ The important thing is that you communicate your intention in advance of doing a lot of work. Simple bug fixes and
32
+ non-controversial changes do not require this approach but you can save some time by suggesting an improvement and
33
+ having it rejected before you write a bunch of the code.
34
+
35
+ 3. Filing an Issue
36
+ -----------------
37
+ If you would like to file a bug report, please create an issue in our Github Issues Tracker. You should do a basic
38
+ search of the issues database before creating a new issue to ensure that you are not creating a duplicate issue.
39
+
40
+ Please do not assign labels or create new labels to your issue. We will assign the appropriate labels to ensure your
41
+ ticket is handled in the appropriate manner.
42
+
43
+ ### 3.1. Providing a Patch
44
+
45
+ If you are filing and issue and supplying a patch at the same time, please file a Pull Request instead. The pull
46
+ request will also create an issue at the same time but its superior to just creating an issue because the code and
47
+ issue can be linked.
48
+
49
+ If the ticket already exists, however, and you want to supply a patch after the fact,
50
+ you can simply reference the issue number in your commit message. For example, if your commit fixed issue #123 you
51
+ could use the following commit message:
52
+
53
+ Fixed a problem with Facebook authentication.
54
+
55
+ [Fixes #123]
56
+ Github will automatically detect this commit message when you push it and link the issue. Please see the detailed
57
+ Github Issues blog post for more details.
58
+
59
+ ### 3.2. Feature Requests
60
+
61
+ We’re interested in hearing your ideas for new features but creating feature requests in the Issue Tracker is not
62
+ the proper way to ask for a feature. A feature request is any idea you have to improve the software experience that
63
+ is not strictly related to a bug or error of omission.
64
+
65
+ Feature requests that are accompanied by source code are always welcome. In this case you should read the next
66
+ section on Creating a Pull Request.
67
+
68
+ Feature requests without accompanying code will be closed. We simply cannot respond efficiently to feature requests
69
+ through our Issue Tracker. If you want to suggest a feature, please use the mailing list or the user voice forum.
70
+
71
+ ### 3.3. How We Prioritize Issues
72
+
73
+ We try our best to respond to all of the questions and issues our users have. We use the following criteria to
74
+ prioritize issues:
75
+
76
+ * Does this bug effect the latest stable release?
77
+ * Is there a patch associated with the issue?
78
+ * Is ther a test included in the patch?
79
+ * Has someone else verified the bug?
80
+ * Are there details on how to reproduce the problem?
81
+ * We give highest priority to issues where the answer is “yes” to all of these questions. Next highest priority is for
82
+ issues that answer “yes” to most of these questions, particularly the first few criteria.
83
+
84
+ You need to include a brief description of the problem and simple steps needed to reproduce it. If you fail to
85
+ supply this minimum level of information your issue will likely be ignored.
86
+
87
+
88
+ 4. Creating a Pull Request
89
+ --------------------------
90
+
91
+ If you are going to contribute code to the Inheritance Module Eval project, the best mechanism for doing this is to create a pull
92
+ request in Github. If you’re unfamiliar with the general concept of pull requests you may want to read more on pull
93
+ requests in Github.
94
+
95
+ If your code is associated with an existing issue then you can provide a patch instead of creating a pull request.
96
+
97
+ ### 4.1. Creating a Fork
98
+
99
+ The official Inheritance Module Eval source code is maintained in Github under the AlexParamonov/inheritance_module_eval
100
+
101
+ You simply need to “fork” the project and then start hacking.
102
+
103
+ See the Github guide on creating forks for more details.
104
+
105
+ ### 4.2. Topic Branches
106
+
107
+ Git branches are “cheap.” Creating branches in Git is incredibly easy and its an ideal way to isolate a specific set
108
+ of changes. You may be fixing several things at one time but by keeping your changes isolated it will help us to
109
+ find and apply only the changes we’re interested in. You should create a clean branch based on the latest
110
+ inheritance_module_eval/master when doing this. It is important you follow these steps exactly,
111
+ it will prevent you from accidentally including unrelated changes from your local repository into the branch.
112
+
113
+ For example, if we were submitting a patch to fix an issue with the CSS in the flash error message you could create
114
+ a branch as follows:
115
+
116
+ $ git remote add upstream git://github.com/AlexParamonov/inheritance_module_eval.git
117
+ $ git fetch upstream
118
+ $ git checkout -b fix-css-for-error-flash --track upstream/master
119
+
120
+ The fetch command will grab all of the latest commits from the Inheritance Module Eval master branch. Don’t worry,
121
+ it doesn’t alter your working repository in a harmful way. The track part of the command will tell git that this
122
+ branch should track with the remote version of the upstream master. This is another way of saying that the branch
123
+ should be based on a clean copy of the latest official source code (without any of your unrelated local changes.)
124
+
125
+ You can then do work locally on this topic branch and push it up to your Github fork when you are done. So in our
126
+ previous example we do something like:
127
+
128
+ $ git push origin fix-css-for-error-flash
129
+
130
+ Of course if you want the fix for yourself to use in your own local code you should probably merge it down to your
131
+ own personal master branch that you’re using for development
132
+
133
+ $ git checkout master
134
+ $ git merge fix-css-for-error-flash
135
+
136
+ You should probably also clean up after yourself a little. The branch has been pushed to Github and you’ve merged it
137
+ locally so you don’t really need a local copy of the branch laying around.
138
+
139
+ $ git branch -D fix-css-for-error-flash
140
+
141
+ ### 4.3. Including a Test
142
+
143
+ Ideally your pull request will also include a test that verifies a bug (or the absence of the new feature) before
144
+ your fix and also verifies proper functionality when you are finished. Please read the Testing Guide for more
145
+ information on writing and running your tests.
146
+
147
+ Pull requests with tests are given top priority. Failure to include a test will likely delay acceptance of your patch.
148
+
149
+ ### 4.4. Creating the Pull Request
150
+
151
+ Once your code is ready to go and you have pushed your topic branch to Github then you are ready to create the pull
152
+ request and notify the Inheritance Module Eval team that your contribution is ready. You do this by browsing your project in
153
+ Github and changing to the topic branch you just pushed. Once you are on the topic branch simply create a pull
154
+ request by pressing the “Pull Request” button.
155
+
156
+ The Github guide on pull requests describes this in more detail with screenshots if you’re still confused on this
157
+ part.
158
+
159
+ 5 Contributing to the Documentation
160
+ -----------------------------------
161
+ Improvements to the documentation is encouraged.
data/LICENSE CHANGED
@@ -1,7 +1,16 @@
1
1
  Copyright (c) 2011 Alexander N Paramonov
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
4
+ documentation files (the "Software"), to deal in the Software without restriction,
5
+ including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
6
+ and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
7
+ subject to the following conditions:
4
8
 
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ Software.
6
11
 
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
16
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  Inheritance module_eval
2
2
  =======================
3
- Inheritance module_eval saves inheritance structure of dynamically created methods.
4
- Allows to redefine dynamic method in the same class or in any child class, and call original method by super keyword
3
+ Allows to create methods with same name inside particular class/object by pushing them down by inheritance tree.
4
+ So method "field" may call other "field" in same class by calling super keyword instead of just redefine it.
5
5
 
6
6
  Installation
7
7
  ------------
8
- gem inheritance_module_eval
8
+ gem install inheritance_module_eval
9
9
 
10
10
  Usage
11
11
  -----
@@ -33,6 +33,7 @@ Below is some simple example of inheritance_module_eval usage:
33
33
 
34
34
  # Some dummy class that uses #instance_module_eval
35
35
  class Content
36
+ # defines simple getter and setter
36
37
  self.field(name)
37
38
  instance_module_eval %{
38
39
  def #{name}
@@ -53,8 +54,9 @@ Below is some simple example of inheritance_module_eval usage:
53
54
  field :content
54
55
  field :etc
55
56
 
57
+ # you desided, that title for article should be titelized
58
+ # from now you dont need to call alias_method or reimplement method anymore!
56
59
  # you can use inheritance!
57
- # you dont need to call alias_method anymore!
58
60
  # make it simple
59
61
  def title
60
62
  super.to_s.titelize
@@ -80,6 +82,11 @@ tested with Ruby
80
82
 
81
83
  see [build history](http://travis-ci.org/#!/AlexParamonov/inheritance_module_eval/builds)
82
84
 
85
+ Contributing
86
+ -------------
87
+ see [contributing guide](http://github.com/AlexParamonov/inheritance_module_eval/blob/master/CONTRIBUTING.md)
88
+
83
89
  Copyright
84
90
  ---------
85
- Copyright © 2011 Alexander N Paramonov. See LICENSE for details.
91
+ Copyright © 2011-2012 Alexander N Paramonov.
92
+ Released under the MIT License. See the LICENSE file for further details.
data/Rakefile CHANGED
@@ -1,5 +1,12 @@
1
+ # encoding: utf-8
2
+ # GEMS
1
3
  require "bundler/gem_tasks"
2
- require 'rspec'
4
+
5
+ # SPECS
6
+ require 'rspec/core'
3
7
  require 'rspec/core/rake_task'
4
- RSpec::Core::RakeTask.new(:spec)
5
- task :default => [:spec]
8
+ RSpec::Core::RakeTask.new(:spec) do |spec|
9
+ spec.pattern = FileList['spec/**/*_spec.rb']
10
+ end
11
+ #Rake::Task["spec"].execute
12
+ task :default => :spec
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.email = ["alexander.n.paramonov@gmail.com"]
10
10
  s.homepage = "http://github.com/AlexParamonov/inheritance_module_eval"
11
11
  s.summary = %q{inheritance safe module_eval.}
12
- s.description = %q{saves inheritance structure of dynamically created methods.
13
- Allows to redefine dynamic method in the same class or in any child class, and call original method by super keyword}
12
+ s.description = %q{Allows to create methods with same name inside particular class/object by pushing them down by inheritance tree.
13
+ So method "field" may call other "field" in same class by calling super keyword instead of just redefine it.}
14
14
 
15
15
  s.rubyforge_project = "inheritance_module_eval"
16
16
 
@@ -1,3 +1,3 @@
1
1
  module InheritanceModuleEval
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -1,79 +1,57 @@
1
1
  require "inheritance_module_eval"
2
2
 
3
- class Parent
4
-
5
- end
6
-
7
- class Child < Parent
8
-
9
- end
10
3
  describe InheritanceModuleEval do
11
4
  describe "add dynamic methods" do
12
- before(:each) do
13
- @test_object = Class.new
5
+ let(:test_class){ Class.new }
6
+ let(:say_hi_block) do
7
+ Proc.new do
8
+ def say_hi
9
+ "hi"
10
+ end
11
+ end
12
+ end
13
+ let(:say_hi_string) do
14
+ %{
15
+ def say_hi
16
+ 'hi'
17
+ end
18
+ }
14
19
  end
15
20
 
16
21
  it "should delegate to module_eval" do
17
22
  mock_module = mock(:mock_module)
18
- @test_object.stub(:include)
19
- @test_object.stub(:extend)
23
+ test_class.stub(:include)
24
+ test_class.stub(:extend)
20
25
  Module.stub(:new).and_return(mock_module)
21
26
 
22
27
  mock_module.should_receive(:module_eval).once
23
-
24
- InheritanceModuleEval.instance_eval_on @test_object do
25
- def say_hi
26
- puts hi
27
- end
28
- end
28
+ InheritanceModuleEval.instance_eval_on test_class, &say_hi_block
29
29
 
30
30
  mock_module.should_receive(:module_eval).once
31
-
32
- InheritanceModuleEval.class_eval_on @test_object do
33
- def say_hi
34
- puts hi
35
- end
36
- end
31
+ InheritanceModuleEval.class_eval_on test_class, &say_hi_block
37
32
  end
38
33
 
39
34
  describe "instance methods" do
40
35
  it "should eval a string" do
41
- InheritanceModuleEval.instance_eval_on @test_object, %{
42
- def say_hi
43
- puts 'hi'
44
- end
45
- }
46
- @test_object.new.should respond_to :say_hi
47
-
36
+ InheritanceModuleEval.instance_eval_on test_class, say_hi_string
37
+ test_class.new.should respond_to :say_hi
48
38
  end
39
+
49
40
  it "should eval a block" do
50
- InheritanceModuleEval.instance_eval_on @test_object do
51
- def say_hi
52
- puts 'hi'
53
- end
54
- end
55
- @test_object.new.should respond_to :say_hi
41
+ InheritanceModuleEval.instance_eval_on test_class, &say_hi_block
42
+ test_class.new.should respond_to :say_hi
56
43
  end
57
44
  end
58
45
 
59
46
  describe "class_methods" do
60
47
  it "should eval a string" do
61
- InheritanceModuleEval.class_eval_on @test_object do
62
- def say_hi
63
- puts 'hi'
64
- end
65
- end
66
-
67
- @test_object.should respond_to :say_hi
48
+ InheritanceModuleEval.class_eval_on test_class, say_hi_string
49
+ test_class.should respond_to :say_hi
68
50
  end
51
+
69
52
  it "should eval a block" do
70
- InheritanceModuleEval.class_eval_on @test_object do
71
- def say_hi
72
- puts 'hi'
73
- end
74
- end
75
-
76
- @test_object.should respond_to :say_hi
53
+ InheritanceModuleEval.class_eval_on test_class, &say_hi_block
54
+ test_class.should respond_to :say_hi
77
55
  end
78
56
  end
79
57
 
@@ -82,27 +60,20 @@ describe InheritanceModuleEval do
82
60
  describe "define already defined method in a class" do
83
61
  context "redefine it after class declaration" do
84
62
  it "should has lower priority then method, declared in a class" do
85
- klass = Class.new
86
- klass.class_eval do
87
- def say_hi
88
- "hi from method" << " " << super
89
- end
90
- end
91
-
92
- InheritanceModuleEval.instance_eval_on klass do
63
+ test_class.class_eval do
93
64
  def say_hi
94
- "hi from eval"
65
+ "hi from method" << " and just super " << super
95
66
  end
96
67
  end
97
68
 
98
- klass.new.say_hi.should == "hi from method hi from eval"
69
+ InheritanceModuleEval.instance_eval_on test_class, &say_hi_block
70
+ test_class.new.say_hi.should == "hi from method and just super hi"
99
71
  end
100
72
  end
101
73
 
102
74
  context "redefine it before class declaration" do
103
75
  it "should has lower priority then method, declared in a class" do
104
- klass = Class.new
105
- klass.class_eval do
76
+ test_class.class_eval do
106
77
  InheritanceModuleEval.instance_eval_on self do
107
78
  def say_hi
108
79
  "tiny hi"
@@ -113,14 +84,13 @@ describe InheritanceModuleEval do
113
84
  super.upcase
114
85
  end
115
86
  end
116
- klass.new.say_hi.should == "TINY HI"
87
+ test_class.new.say_hi.should == "TINY HI"
117
88
  end
118
89
  end
119
90
 
120
91
  describe "redefine as much as you want" do
121
- it "should push dynamic method up in the inheritance tree" do
122
- klass = Class.new
123
- klass.class_eval do
92
+ it "should push dynamic method down by the inheritance tree" do
93
+ test_class.class_eval do
124
94
  InheritanceModuleEval.instance_eval_on self do
125
95
  def say_hi
126
96
  [5]
@@ -149,7 +119,7 @@ describe InheritanceModuleEval do
149
119
  [1] + super
150
120
  end
151
121
  end
152
- klass.new.say_hi.should == [1, 2, 3, 4, 5]
122
+ test_class.new.say_hi.should == [1, 2, 3, 4, 5]
153
123
  end
154
124
  end
155
125
 
@@ -158,24 +128,24 @@ describe InheritanceModuleEval do
158
128
  test_module = Module.new
159
129
  test_module.module_eval do
160
130
  def say_hi
161
- ["hi from module"]
131
+ "hi from module"
162
132
  end
163
133
  end
164
134
 
165
- klass = Class.new
166
- klass.class_eval do
135
+ test_class.class_eval do
167
136
  include test_module
168
137
  InheritanceModuleEval.instance_eval_on self do
169
138
  def say_hi
170
- ["hi from eval"] + super
139
+ "hi from eval" << ", " << super
171
140
  end
172
141
  end
173
142
 
174
143
  def say_hi
175
- ["hi from method"] + super
144
+ "hi from method" << ", " << super
176
145
  end
177
146
  end
178
- klass.new.say_hi.should == ["hi from method", "hi from eval", "hi from module"]
147
+
148
+ test_class.new.say_hi.should == "hi from method, hi from eval, hi from module"
179
149
  end
180
150
  end
181
151
  end
@@ -184,7 +154,7 @@ describe InheritanceModuleEval do
184
154
 
185
155
  describe "#get_module_for" do
186
156
  it "should return Module" do
187
- InheritanceModuleEval.send :get_module_for, "'hi'"
157
+ expect{ InheritanceModuleEval.send :get_module_for, "'hi'"}.to_not raise_error
188
158
  end
189
159
 
190
160
  it "should raise ArgumentError if no code given" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inheritance_module_eval
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-14 00:00:00.000000000Z
12
+ date: 2012-01-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &12174720 !ruby/object:Gem::Requirement
16
+ requirement: &20407580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.6'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *12174720
24
+ version_requirements: *20407580
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &12174300 !ruby/object:Gem::Requirement
27
+ requirement: &20407080 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,11 +32,12 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *12174300
36
- description: ! 'saves inheritance structure of dynamically created methods.
35
+ version_requirements: *20407080
36
+ description: ! 'Allows to create methods with same name inside particular class/object
37
+ by pushing them down by inheritance tree.
37
38
 
38
- Allows to redefine dynamic method in the same class or in any child class, and call
39
- original method by super keyword'
39
+ So method "field" may call other "field" in same class by calling super keyword
40
+ instead of just redefine it.'
40
41
  email:
41
42
  - alexander.n.paramonov@gmail.com
42
43
  executables: []
@@ -46,6 +47,7 @@ files:
46
47
  - .gitignore
47
48
  - .rspec
48
49
  - .travis.yml
50
+ - CONTRIBUTING.md
49
51
  - Gemfile
50
52
  - HISTORY.md
51
53
  - LICENSE
@@ -77,9 +79,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
79
  version: '0'
78
80
  requirements: []
79
81
  rubyforge_project: inheritance_module_eval
80
- rubygems_version: 1.8.11
82
+ rubygems_version: 1.8.13
81
83
  signing_key:
82
84
  specification_version: 3
83
85
  summary: inheritance safe module_eval.
84
86
  test_files: []
85
- has_rdoc: