refactor 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 237c531a5ad2b86c4ef7cf3276e448f23fb26a5f
4
+ data.tar.gz: 6299ca36877ccbaa5e7b39ec8c6045defb3c06c7
5
+ SHA512:
6
+ metadata.gz: 871c020fcbccbe84385e59fb5276509a9d157ae77a39ffdc0991b4826aa039bc1a351edabe0122743c55fc5e152c92ed80e4f89d1d2abf5d87698cb0ea1ccde9
7
+ data.tar.gz: d163e31206b0fd386b6baaab416be47bc32cf9c118e20ff8b87d689501dac8b72d0c6383017179e7ee1d32bc93ac90c07dab594ef2e328193aecf8e613f9164b
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in refactor.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Aidan Feldman
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.
@@ -0,0 +1,15 @@
1
+ # Refactor
2
+
3
+ A command line tool to help refactor your code.
4
+
5
+ ## Usage
6
+
7
+ Make sure your code is backed up (e.g. under version control and fully committed) first!
8
+
9
+ ```bash
10
+ gem install refactor
11
+ # Then, from your project (sub)directory:
12
+ refactor FROM TO
13
+ ```
14
+
15
+ where `FROM` and `TO` can each be a name that `has_underscores`, is `CamelCased`, `has-dashes`, or is `"separated with spaces between quotes"`. It will replace the `FROM` with the `TO` in the corresponding format.
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative File.join('..', 'lib', 'refactor')
4
+
5
+ from = ARGV[0] || raise("Needs a FROM argument.")
6
+ to = ARGV[1] || raise("Needs a TO argument.")
7
+ Refactor.run(from, to)
@@ -0,0 +1,68 @@
1
+ require 'active_support/core_ext/string/inflections'
2
+ require 'fileutils'
3
+
4
+ require_relative 'refactor/version'
5
+
6
+ module Refactor
7
+ def run(from, to)
8
+ from_camelized = from.camelize
9
+ from_dashed = from.dasherize
10
+ from_humanized = from.humanize
11
+ from_underscored = from.underscore
12
+ to_camelized = to.camelize
13
+ to_dashed = to.dasherize
14
+ to_underscored = to.underscore
15
+
16
+ camelized_regex = /(?<=\b|_)#{Regexp.quote(from_camelized)}(?=\b|_)/
17
+ dashed_regex = /(?<=\b|_)#{Regexp.quote(from_dashed)}(?=\b|_)/
18
+ underscored_regex = /(?<=\b|_)#{Regexp.quote(from_underscored)}(?=\b|_)/
19
+
20
+ # all files in current directory
21
+ Dir.glob('**/*') do |old_path|
22
+ # ignore certain directories
23
+ unless old_path =~ %r{\A(coverage|pkg|tmp|vendor)(\z|/)}
24
+ # only check the basename so that the directory doesn't get renamed twice
25
+ old_basename = File.basename(old_path)
26
+ new_basename = old_basename.dup
27
+ new_basename.gsub!(dashed_regex, to_dashed)
28
+ new_basename.gsub!(underscored_regex, to_underscored)
29
+
30
+ if new_basename == old_basename
31
+ # no change
32
+ new_path = old_path
33
+ else
34
+ # rename file
35
+ new_path = File.join(File.dirname(old_path), new_basename)
36
+ puts "#{old_path} –> #{new_path}"
37
+ FileUtils.mv(old_path, new_path)
38
+ end
39
+
40
+ if File.file?(new_path)
41
+ # replace within file
42
+ old_text = File.read(new_path)
43
+
44
+ new_text = old_text.dup
45
+ new_text.gsub!(camelized_regex, to_camelized)
46
+ new_text.gsub!(dashed_regex, to_dashed)
47
+ new_text.gsub!(underscored_regex, to_underscored)
48
+
49
+ unless new_text == old_text
50
+ # rewrite existing file
51
+ File.write(new_path, new_text)
52
+ end
53
+
54
+ # show possible matches in body
55
+ line_num = 0
56
+ new_text.each_line do |old_line|
57
+ new_line = old_line.gsub(/#{Regexp.quote(from_humanized)}/i, "\e[33m\\0\e[0m")
58
+ unless new_line == old_line
59
+ puts "\e[36m#{new_path}:#{line_num}\e[0m #{new_line}"
60
+ end
61
+ line_num += 1
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ module_function :run
68
+ end
@@ -0,0 +1,3 @@
1
+ module Refactor
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'refactor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "refactor"
8
+ spec.version = Refactor::VERSION
9
+ spec.authors = ["Aidan Feldman"]
10
+ spec.email = ["aidan.feldman@gmail.com"]
11
+ spec.summary = %q{A command line tool to help refactor your code.}
12
+ # spec.description = %q{TODO: Write a longer description. Optional.}
13
+ spec.homepage = "https://github.com/afeld/refactor"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "activesupport", "~> 4.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Refactor do
4
+ it 'has a version number' do
5
+ expect(Refactor::VERSION).not_to be nil
6
+ end
7
+
8
+ it 'does something useful' do
9
+ expect(false).to eq(true)
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'refactor'
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refactor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aidan Feldman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - aidan.feldman@gmail.com
72
+ executables:
73
+ - refactor
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .rspec
79
+ - .travis.yml
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/refactor
85
+ - lib/refactor.rb
86
+ - lib/refactor/version.rb
87
+ - refactor.gemspec
88
+ - spec/refactor_spec.rb
89
+ - spec/spec_helper.rb
90
+ homepage: https://github.com/afeld/refactor
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.2.2
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: A command line tool to help refactor your code.
114
+ test_files:
115
+ - spec/refactor_spec.rb
116
+ - spec/spec_helper.rb