rocktumbler 0.1.0

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: 07fc8bc23adbc4dba79640eaeec34420e37fa8d2
4
+ data.tar.gz: 306289cafbb6a7b5b6b4d66a928ee4357ad1c0b4
5
+ SHA512:
6
+ metadata.gz: f69e39b13c1a784474d7da17a7b2780980d42eeac857cd7921758e8a3f600d5a9abf3b050e10749912b9183d6a948044bee2c06f189c73981010a3fb25177e71
7
+ data.tar.gz: 90fc86ddea9f437ed7852167ff4f774c555d21a707f38ff827428e9aa5f1f73d95c60ba58306274b4051094505b913d4cae6de8543198ad26728a93e7c071ce3
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.4
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rocktumbler.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Simon Reed
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Rocktumbler
2
+
3
+ Rocktumbler is a gem that will take your existing Gemfile and rewrite it to insure that it remains formatted and consistent.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rocktumbler'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ tumble
16
+
17
+ This will then rewrite your Gemfile making sure that you use single quotes and gives a brief description of what each gem does.
18
+
19
+ ## Development
20
+
21
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
22
+
23
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
24
+
25
+ TODO: Add tests!
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( https://github.com/simonreed/rocktumbler/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/tumble ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Exit cleanly from an early interrupt
4
+ Signal.trap("INT") { exit 1 }
5
+
6
+ require 'rocktumbler'
7
+ Rocktumbler::Tumbler.new.tumble
@@ -0,0 +1,4 @@
1
+ module Rocktumbler
2
+ class IncomparableGemfileError < StandardError; end
3
+ class GemInformationNotFoundError < StandardError; end
4
+ end
@@ -0,0 +1,48 @@
1
+ require_relative 'exceptions'
2
+
3
+ module Rocktumbler
4
+ class Gem
5
+ def initialize(gem_dependency)
6
+ @gem_dependency = gem_dependency
7
+ end
8
+
9
+ def print(prepend="")
10
+ gem_info = retrieve_gem_information(@gem_dependency.name)
11
+ str = "#{prepend}# #{gem_info.summary}\n"
12
+ str += "#{prepend}# #{gem_info.homepage}\n"
13
+ str += "#{prepend}gem '#{@gem_dependency.name}'"
14
+ str += ",'#{@gem_dependency.requirement}'" if @gem_dependency.requirement.specific?
15
+ str += generate_gem_source(@gem_dependency.source.options) if @gem_dependency.source
16
+ str += ", require: #{!@gem_dependency.autorequire.empty?}" if @gem_dependency.autorequire
17
+ str += "\n\n"
18
+ end
19
+
20
+ def generate_gem_source(source_options)
21
+ return ", github: '#{source_options['github']}'" if source_options['github']
22
+ return ", path: '#{source_options['path']}'" if source_options['path']
23
+ end
24
+
25
+ def retrieve_gem_information(gem_name)
26
+ bundled_gem = Bundler.definition.specs.select{|g| g.name == gem_name}.first
27
+ if bundled_gem
28
+ OpenStruct.new(summary: bundled_gem.summary.slice(0,80), homepage: bundled_gem.homepage)
29
+ else
30
+ rubygems_gem_information(gem_name)
31
+ end
32
+ end
33
+
34
+ def rubygems_gem_information(gem_name)
35
+ begin
36
+ json = open("https://rubygems.org/api/v1/gems/#{gem_name}.json").read
37
+ gem_info = JSON.parse(json)
38
+ OpenStruct.new(summary: gem_info['info'].slice(0,80), homepage: gem_info['homepage_uri'])
39
+ rescue OpenURI::HTTPError => e
40
+ if e.message == '404 Not Found'
41
+ raise GemInformationNotFoundError, "No details found locally or on rubygems for '#{gem_name}'"
42
+ else
43
+ raise e
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,20 @@
1
+ module Rocktumbler
2
+ class Group
3
+
4
+ attr_accessor :name
5
+
6
+ def initialize(name,gem_dependencies)
7
+ @name = name
8
+ @gems = gem_dependencies.map{|g| Rocktumbler::Gem.new(g)}
9
+ end
10
+
11
+ def print
12
+ str = ''
13
+ prepend_spacing = (@name == :default) ? '' : ' '
14
+ str += "\n\ngroup #{@name.to_s.gsub(/[\[\]]/,'')} do\n" if @name != :default
15
+ str += @gems.map{|g|g.print(prepend_spacing)}.join
16
+ str += "end\n" if @name != :default
17
+ return str
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ module Rocktumbler
2
+ class GroupFilter
3
+ def initialize(gem_dependencies)
4
+ @gem_dependencies = gem_dependencies
5
+ end
6
+
7
+ def filter
8
+ gems_by_group = @gem_dependencies.group_by(&:groups)
9
+
10
+ default_gems = gems_by_group.delete([:default])
11
+ default_gems.sort!
12
+ groups = [Rocktumbler::Group.new(:default,default_gems)]
13
+
14
+ gems_by_group.each do | group, gems |
15
+ gems_unique_to_group = gems - default_gems
16
+ gems_unique_to_group.sort!
17
+ gems_unique_to_group.uniq!
18
+ groups << Rocktumbler::Group.new(group,gems_unique_to_group)
19
+ end
20
+
21
+ return groups
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,43 @@
1
+ require_relative 'exceptions'
2
+
3
+ module Rocktumbler
4
+ class Tumbler
5
+ def initialize(location=Bundler.default_gemfile)
6
+ @gemfile_location = location
7
+ @bundler_dependencies = parse_gemfile(@gemfile_location)
8
+ end
9
+
10
+ def tumble(opts={})
11
+ groups = Rocktumbler::GroupFilter.new(@bundler_dependencies).filter
12
+ clean_gemfile_str = groups.map(&:print).join
13
+ compare_to_original_gemfile(clean_gemfile_str)
14
+ write(clean_gemfile_str) unless opts[:skip_write]
15
+ return clean_gemfile_str
16
+ end
17
+
18
+ def compare_to_original_gemfile(clean_gemfile_str)
19
+ temp_gemfile = Tempfile.new('Gemfile.temp')
20
+ temp_gemfile.write(clean_gemfile_str)
21
+ temp_gemfile.close
22
+ temp_bundler_dependencies = parse_gemfile(temp_gemfile.path)
23
+ diff = (@bundler_dependencies - temp_bundler_dependencies)
24
+ if diff.empty?
25
+ return true
26
+ else
27
+ raise IncomparableGemfileError, "Clean Gemfile is not comparable to the existing Gemfile. The following gems are missing : #{diff.map(&:name).to_s}."
28
+ end
29
+ end
30
+
31
+ def write(clean_gemfile_str)
32
+ gemfile = File.open(@gemfile_location,'w')
33
+ gemfile.write(clean_gemfile_str)
34
+ gemfile.close
35
+ end
36
+
37
+ private
38
+
39
+ def parse_gemfile(location)
40
+ Bundler::Dsl.new.eval_gemfile(location)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module Rocktumbler
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'open-uri'
2
+ require 'ostruct'
3
+ require 'tempfile'
4
+ require 'bundler'
5
+
6
+ module Rocktumbler
7
+ autoload :Tumbler, 'rocktumbler/tumbler'
8
+ autoload :Group, 'rocktumbler/group'
9
+ autoload :GroupFilter, 'rocktumbler/group_filter'
10
+ autoload :Gem, 'rocktumbler/gem'
11
+ autoload :Version, 'rocktumbler/version'
12
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rocktumbler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rocktumbler"
8
+ spec.version = Rocktumbler::VERSION
9
+ spec.authors = ["Simon Reed"]
10
+ spec.email = ["simonpreed@gmail.com"]
11
+
12
+ spec.summary = %q{Polish your Gemfile to make sure it remains consistent.}
13
+ spec.description = %q{Polish your Gemfile to make sure it remains consistent.}
14
+ spec.homepage = "https://github.com/simonreed/rocktumbler"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.executables = %w(tumble)
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+
23
+ spec.add_runtime_dependency "bundler", "~> 1.8"
24
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rocktumbler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Simon Reed
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.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.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ description: Polish your Gemfile to make sure it remains consistent.
42
+ email:
43
+ - simonpreed@gmail.com
44
+ executables:
45
+ - tumble
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".travis.yml"
52
+ - CODE_OF_CONDUCT.md
53
+ - Gemfile
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - bin/tumble
58
+ - lib/rocktumbler.rb
59
+ - lib/rocktumbler/exceptions.rb
60
+ - lib/rocktumbler/gem.rb
61
+ - lib/rocktumbler/group.rb
62
+ - lib/rocktumbler/group_filter.rb
63
+ - lib/rocktumbler/tumbler.rb
64
+ - lib/rocktumbler/version.rb
65
+ - rocktumbler.gemspec
66
+ homepage: https://github.com/simonreed/rocktumbler
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.4.2
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Polish your Gemfile to make sure it remains consistent.
90
+ test_files: []