rewriter 0.0.1

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: a87d746bc49558773b5a067a8be7aa0fc37b849f
4
+ data.tar.gz: 586a886938b88509986025e13cd7d9ece9a42b4b
5
+ SHA512:
6
+ metadata.gz: 9c05bb07cbf697d8b422e88ebeab59dd0a76b9f6fab467dd77476e1b91d5436f7e7209eeb1b5c1e36c84bf989b349b1283af297539806790636061b3970d0c96
7
+ data.tar.gz: 6fd945a3c21f3e7268eef0a7e374822b92868331d4c5f79ea3bea1c81716f4732d8839a88b29eb96ba7696bbc097a40a17752ac53c9af88241217d0429ebc2d4
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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+ gem 'rspec'
5
+
6
+ gem 'guard'
7
+ gem 'guard-rspec'
8
+ gem 'guard-bundler'
9
+ gem 'terminal-notifier-guard'
10
+
11
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,12 @@
1
+ guard :rspec, all_on_start: true do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { 'spec' }
5
+ end
6
+
7
+ guard :bundler do
8
+ watch('Gemfile')
9
+ watch('rewriter.gemspec')
10
+ end
11
+
12
+ notification :terminal_notifier
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Vsevolod Romashov
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,28 @@
1
+ # Rewriter
2
+
3
+ A simple utility to parse and reconstruct ruby code to maintain a given coding style.
4
+
5
+ Currently just a proof of concept.
6
+
7
+ ## Installation
8
+
9
+ ``` sh
10
+ $ gem install rewriter
11
+ $ rbenv rehash # if you're using rbenv
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ``` sh
17
+ $ rewrite foo.rb
18
+ ```
19
+
20
+ NOTE: `rewrite` literally rewrites the file in place; use it with a control version system like [git](http://git-scm.com) so you can revert the changes.
21
+
22
+ ## Contributing
23
+
24
+ 1. Fork it
25
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
26
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
27
+ 4. Push to the branch (`git push origin my-new-feature`)
28
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task default: :spec
data/bin/rewrite ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rewriter'
3
+ require 'slop'
4
+ require 'colored'
5
+
6
+ opts = Slop.parse(help: true) do
7
+ banner 'Usage: rewrite foo.rb'
8
+
9
+ run do |opts, args|
10
+ args.each do |path|
11
+ if File.exists?(path)
12
+ Rewriter.rewrite(path)
13
+ puts "File #{path} was processed.".green
14
+ else
15
+ puts "File #{path} was not found.".red
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/rewriter.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'rewriter/version'
2
+
3
+ require 'parser/current'
4
+ require 'unparser'
5
+
6
+ module Rewriter
7
+ class << self
8
+ def rewrite(path)
9
+ with_file(path) do |source|
10
+ ast, comments = Parser::CurrentRuby.parse_with_comments(source)
11
+ Unparser.unparse(ast, comments)
12
+ end
13
+ end
14
+
15
+ def with_file(path)
16
+ original = File.read(path)
17
+ rewritten = yield(original)
18
+
19
+ temp_path = "#{path}.rewritten"
20
+ ::File.open(temp_path, 'w') do |temp_file|
21
+ temp_file.write(rewritten)
22
+ end
23
+
24
+ ::File.rename(temp_path, path)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module Rewriter
2
+ VERSION = '0.0.1'
3
+ end
data/rewriter.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rewriter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rewriter'
8
+ spec.version = Rewriter::VERSION
9
+ spec.authors = ['Vsevolod Romashov']
10
+ spec.email = ['7@7vn.ru']
11
+ spec.description = %q(Ruby code rewriter. Currently just a proof of concept.)
12
+ spec.summary = %q(A simple utility to parse and reconstruct ruby code to maintain a given coding style. Currently just a proof of concept.)
13
+ spec.homepage = 'https://github.com/7even/rewriter'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
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_runtime_dependency 'parser', '~> 2.0'
22
+ spec.add_runtime_dependency 'unparser', '~> 0.1'
23
+ spec.add_runtime_dependency 'slop', '~> 3.4'
24
+ spec.add_runtime_dependency 'colored', '~> 1.2'
25
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rewriter do
4
+ describe ".rewrite" do
5
+ let(:file_path) do
6
+ file = Tempfile.new(['code', '.rb'])
7
+ File.open(file.path, 'w') do |tempfile|
8
+ tempfile.write('some.ruby(:code, {:ugly=>true})')
9
+ end
10
+
11
+ file.path
12
+ end
13
+
14
+ it "rewrites the code in a given file" do
15
+ Rewriter.rewrite(file_path)
16
+
17
+ rewritten = File.read(file_path)
18
+ expect(rewritten).to eq('some.ruby(:code, {:ugly => true})')
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ require 'rewriter'
2
+ require 'tempfile'
3
+
4
+ RSpec.configure do |config|
5
+ config.treat_symbols_as_metadata_keys_with_true_values = true
6
+ config.run_all_when_everything_filtered = true
7
+ config.filter_run :focus
8
+
9
+ config.order = 'random'
10
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rewriter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Vsevolod Romashov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: parser
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: unparser
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: slop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: colored
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
69
+ description: Ruby code rewriter. Currently just a proof of concept.
70
+ email:
71
+ - 7@7vn.ru
72
+ executables:
73
+ - rewrite
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .rspec
79
+ - Gemfile
80
+ - Guardfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/rewrite
85
+ - lib/rewriter.rb
86
+ - lib/rewriter/version.rb
87
+ - rewriter.gemspec
88
+ - spec/rewriter_spec.rb
89
+ - spec/spec_helper.rb
90
+ homepage: https://github.com/7even/rewriter
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.0.14
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: A simple utility to parse and reconstruct ruby code to maintain a given coding
114
+ style. Currently just a proof of concept.
115
+ test_files:
116
+ - spec/rewriter_spec.rb
117
+ - spec/spec_helper.rb