latent_object_detector 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a791cf6c6b8217cc5cd4535f56b915c40d797881
4
+ data.tar.gz: a22158208a9b31417b0e860fd4fb655d2f2789fc
5
+ SHA512:
6
+ metadata.gz: 65b53dc35b2d1ee74acf7163be98abe10296706e40d6ab8467ff8ef833e34a4ddaca432d1951400bda6c5e5672839779849ebc15a361fa5e03cc49fee2dd68dc
7
+ data.tar.gz: f9cb8c51759b32506b76e17daaa08211cf37107df5f186cc73a2814af1af8da4874d229ebc625b5e94b373368b2a11fa46888bd240780d30802f118bc5d82acd
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - ruby-head
6
+ script: "bundle exec rake test"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in latent_object_detector.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kerri Miller
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Latent Object Detector
2
+
3
+ [<img src="https://secure.travis-ci.org/kerrizor/latent_object_detector.png" />](http://travis-ci.org/kerrizor/latent_object_detector)
4
+
5
+ Based on an original idea from Corey, this gem looks at the methods defined on an object and looks for repeated words contained in the method names, as this can sometimes illuminate latent objects, concepts, or relationships that don't currently exist in the code (but should.)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'latent_object_detector'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install latent_object_detector
20
+
21
+ ## Usage
22
+ ```
23
+ d = LatentObjectDetector.for(User)
24
+ d.potential_objects
25
+ => ["password", "token", "remember"]
26
+ d.suspicious_methods
27
+ => [:change_password, :generate_token, :remember_token?, :remember_me, :uses_deprecated_password?, :password_matches?, :crypt_password, :password_required?, :password_handler]
28
+ ```
29
+ Then go refactor those latent objects!
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = "test/*_test.rb"
7
+ end
data/TODO.md ADDED
@@ -0,0 +1,7 @@
1
+ TODO
2
+ ====
3
+
4
+ Next steps and ideas for more exploration
5
+
6
+ + use stemming and Levenshtein distances to find non-exact matches
7
+ + scan comments for matching words as well
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'latent_object_detector'
5
+ require 'latent_object_detector/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "latent_object_detector"
9
+ spec.version = LatentObjectDetector::VERSION
10
+ spec.authors = ["Corey Ehmke", "Kerri Miller"]
11
+ spec.email = ["corey@idolhands.com", "kerrizor@kerrizor.com"]
12
+ spec.description = %q{Flags frequently used words in method names as
13
+ possible latent concepts.}
14
+ spec.summary = %q{Based on an original idea from Corey, this gem looks
15
+ at the methods defined on an object and looks for
16
+ repeated words contained in the method names, as
17
+ this can sometimes illuminate latent objects,
18
+ concepts, or relationships that don't currently
19
+ exist in the code (but should.)}
20
+ spec.homepage = "https://github.com/kerrizor/latent_object_detector"
21
+ spec.license = "MIT"
22
+
23
+ spec.files = `git ls-files`.split($/)
24
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
25
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.3"
29
+ spec.add_development_dependency "rake"
30
+ end
@@ -0,0 +1,64 @@
1
+ require "latent_object_detector/version"
2
+
3
+ module LatentObjectDetector
4
+ class Detector
5
+ attr_accessor :klass
6
+
7
+ def self.for(klass)
8
+ new(klass)
9
+ end
10
+
11
+ def initialize(klass)
12
+ self.klass = klass
13
+ end
14
+
15
+ def suspicious_methods
16
+ methods_owned_by_klass.select{ |m| (words_in_method(m.to_s) & potential_objects).size > 0 }
17
+ end
18
+
19
+ def potential_objects
20
+ common_words = find_common_words_in(hash_of_words_used_in_methods)
21
+ words_used_more_than_twice(common_words)
22
+ end
23
+
24
+ private
25
+ def words_used_more_than_twice(hash_of_words = {})
26
+ hash_of_words.select{ |k| k.size > 2 }
27
+ end
28
+
29
+ def hash_of_words_used_in_methods
30
+ methods_owned_by_klass.inject({}) do |hash, method|
31
+ hash[method] = words_in_method(method)
32
+ hash
33
+ end
34
+ end
35
+
36
+ def find_common_words_in(hash_of_words = hash_of_words_used_in_methods)
37
+ count_word_frequency(hash_of_words).select{ |k,v| v > 1 }.keys
38
+ end
39
+
40
+ def count_word_frequency(hash_of_words = {})
41
+ hash_of_words.values.flatten.inject({}) do |hash, word|
42
+ hash[word] ||= 0
43
+ hash[word] += 1
44
+ hash
45
+ end
46
+ end
47
+
48
+ def methods_owned_by_klass
49
+ all_instance_methods_of_klass.select{ |method| method_is_owned_by_klass? method }
50
+ end
51
+
52
+ def method_is_owned_by_klass?(method)
53
+ self.klass.new.method(method).owner == self.klass
54
+ end
55
+
56
+ def all_instance_methods_of_klass
57
+ self.klass.instance_methods
58
+ end
59
+
60
+ def words_in_method(name)
61
+ name.to_s.gsub(/[^a-z\_]/i,'').split('_')
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,3 @@
1
+ module LatentObjectDetector
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ class UserExample
4
+ def foo;end
5
+ def bar;end
6
+ def baz;end
7
+ def foo_bar;end
8
+ end
9
+
10
+ class LatentObjectDetectorTest < MiniTest::Unit::TestCase
11
+ def setup
12
+ @detector = LatentObjectDetector::Detector.for(UserExample)
13
+ end
14
+
15
+ def test_for_returns_klass
16
+ assert_kind_of LatentObjectDetector::Detector, @detector
17
+ end
18
+
19
+ def test_potential_objects
20
+ assert_equal ["foo", "bar"], @detector.potential_objects
21
+ end
22
+
23
+ def test_suspicious_methods
24
+ assert_equal [:foo, :bar, :foo_bar], @detector.suspicious_methods
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ require './lib/latent_object_detector'
2
+ require 'minitest/unit'
3
+ require 'minitest/autorun'
4
+ require 'minitest/pride'
5
+
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: latent_object_detector
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Corey Ehmke
8
+ - Kerri Miller
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.3'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ description: |-
43
+ Flags frequently used words in method names as
44
+ possible latent concepts.
45
+ email:
46
+ - corey@idolhands.com
47
+ - kerrizor@kerrizor.com
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - .gitignore
53
+ - .travis.yml
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - TODO.md
59
+ - latent_object_detector.gemspec
60
+ - lib/latent_object_detector.rb
61
+ - lib/latent_object_detector/version.rb
62
+ - test/latent_object_detector_test.rb
63
+ - test/test_helper.rb
64
+ homepage: https://github.com/kerrizor/latent_object_detector
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.0.6
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Based on an original idea from Corey, this gem looks at the methods defined
88
+ on an object and looks for repeated words contained in the method names, as this
89
+ can sometimes illuminate latent objects, concepts, or relationships that don't currently
90
+ exist in the code (but should.)
91
+ test_files:
92
+ - test/latent_object_detector_test.rb
93
+ - test/test_helper.rb