island 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f6d18c7a3387bcea03c25fc5ca4914a9a0c45e59
4
+ data.tar.gz: 18efa7901eb139a6f7b1bfca87971ec8e5e2baa2
5
+ SHA512:
6
+ metadata.gz: ca43b82c58b0c232a10ef253db20a19dce00f92880a7ca89f08586df69d7a790f9c78ec98b869d28eb3bb6ab5f5b1b46a0d4fe6fa9ee9c5406005e63331a522a
7
+ data.tar.gz: 1f2f20c626aa04631ffbed5438d9be83b5454edd3578df6814ffa2b32409b9cff0d26e65f5917170cbcbf254224d125c3a05eeccbc65c97d660d6d1c20d8c251
@@ -0,0 +1,18 @@
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
+ fixtures
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'pry-uber', github: 'zph/pry-uber'
4
+
5
+ # Specify your gem's dependencies in island.gemspec
6
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Zander Hill
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,42 @@
1
+ # Island
2
+
3
+ `no one is an island`
4
+
5
+ But scripts should be.
6
+
7
+ Do we need the right version of Perl installed to use ack? No, it's self contained.
8
+ Do we need the right version of Golang installed to use those tools? No, self contained.
9
+
10
+ Shouldn't ruby have a simple way to generate standalone scripts? Island thinks so and will help.
11
+
12
+ Generates standalone ruby scripts from gems.
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ gem 'island'
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install island
27
+
28
+ ## Usage
29
+
30
+ TODO: Write usage instructions here
31
+
32
+ ## TODO
33
+
34
+ - Detect other files to include at beginning, ignore STDLIB
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it ( http://github.com/zph/island/fork )
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'island'
4
+
5
+ repo = "fixtures/infect/"
6
+ # Files and order
7
+ globs = [
8
+ "#{repo}vendor/**/lib/pmap.rb",
9
+ "#{repo}lib/infect/colorize.rb",
10
+ "#{repo}lib/**/*.rb",
11
+ "#{repo}bin/infect",
12
+ ]
13
+
14
+ files = globs.flat_map do |g|
15
+ Dir.glob(g)
16
+ end
17
+
18
+ pmap_reject = ->(line){ !!line[/require 'pmap/] }
19
+ self_reference = ->(line){ !! (line[/require 'infect/] || line[/\.\.\/lib\/infect/]) }
20
+ rejects = [Island::Plugins::SHABANG, pmap_reject, self_reference]
21
+
22
+ puts Island::Creator.call(files, rejects: rejects)
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'island/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "island"
8
+ spec.version = Island::VERSION
9
+ spec.authors = ["Zander Hill"]
10
+ spec.email = ["Zander@civet.ws"]
11
+ spec.summary = %q{Helper for creating standalone ruby scripts with all dependencies.}
12
+ spec.description = %q{Helper for creating standalone ruby scripts with all dependencies.}
13
+ spec.homepage = ""
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_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,8 @@
1
+ require "island/version"
2
+ require 'island/plugins'
3
+ require 'island/creator'
4
+
5
+ require 'set'
6
+
7
+ module Island
8
+ end
@@ -0,0 +1,102 @@
1
+ module Island
2
+
3
+ class Creator
4
+ attr_accessor :files, :content
5
+ def self.call(files, opts={})
6
+ files = Set.new(files)
7
+ rejects = opts.fetch(:rejects) { Plugins::REJECTIONS }
8
+ mods = opts.fetch(:modifications) { Plugins::MODIFICATIONS }
9
+ i = new(files)
10
+ h = i.read_content
11
+ h = i.alter_each_file(h)
12
+ ## process each file
13
+ c = i.blend_files(h)
14
+ r = i.requires(c)
15
+
16
+ i.ensure_dependencies(r, files)
17
+
18
+ c = i.reject_line(c, rejects)
19
+ c = i.modify_lines(c, mods)
20
+ i.join_lines(c)
21
+ end
22
+
23
+ def alter_each_file(h)
24
+ # Act on the array of lines of each file
25
+ # ie prepend ==Start of filename / ==End of filename
26
+ # h.map do |k,v|
27
+
28
+ # end
29
+ h
30
+ end
31
+
32
+ def blend_files(h)
33
+ @content = h.values.flatten
34
+ end
35
+
36
+ def self.requires(files, opts={})
37
+ # TODO: temporary
38
+ i = new(files)
39
+ c = i.read_content
40
+ r = i.requires(c)
41
+ i.ensure_dependencies(r, files)
42
+ end
43
+
44
+ def ensure_dependencies(libs, files)
45
+ to_include = libs.select { |k,v| v == false }.keys
46
+ to_include.flat_map do |l|
47
+ found = files.grep(/#{l}/)
48
+ if found.empty?
49
+ warn "Please include #{l} in files list"
50
+ exit(1)
51
+ end
52
+ found
53
+ end
54
+ end
55
+
56
+ def requires(c)
57
+ r = c.select { |i| i[/^\s?require/]}
58
+ .map { |o| o[/['"](.*)['"]/]; $1 }[0..6]
59
+ h = r.map { |o| stdlib?(o) }.flatten
60
+ Hash[*h]
61
+ end
62
+
63
+ def stdlib?(lib)
64
+ result = false
65
+ s = Thread.new do
66
+ begin
67
+ require lib
68
+ result = true
69
+ rescue LoadError
70
+ result = false
71
+ end
72
+ end
73
+ s.join
74
+ [lib, result]
75
+ end
76
+
77
+ def initialize(files)
78
+ @files = files
79
+ end
80
+
81
+ def read_content(f = files)
82
+ Hash[*f.flat_map { |z| [z, File.open(z).readlines.map(&:chomp)] }]
83
+ end
84
+
85
+ def reject_line(c, plugins = Plugins::REJECTIONS)
86
+ # plugins must eval to true for it to be removed
87
+ c = plugins.each_with_object(c) do |b, obj|
88
+ obj.reject!{ |l| b.call(l) }
89
+ end
90
+ end
91
+
92
+ def modify_lines(c, plugins = Plugins::MODIFICATIONS)
93
+ c = plugins.each_with_object(c) do |b, obj|
94
+ b.call(obj)
95
+ end
96
+ end
97
+
98
+ def join_lines(c = content)
99
+ c.join("\n") + "\n"
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,21 @@
1
+ module Island
2
+
3
+ module Plugins
4
+ SHABANG = ->(line){ !!line[/^#!\//] }
5
+ NEW_SHABANG = "#!/usr/bin/env ruby\n"
6
+ ADD_SHABANG = ->(c){ c.insert(0, NEW_SHABANG) }
7
+ ADD_GENERATED_CODE_DISCLAIMER = ->(c) do
8
+ txt =<<-EOF.gsub(/^\s*/, '')
9
+ #########################################################
10
+ ## Generated Code: do not submit patches.
11
+ ## Submit patches against non-generated version of code.
12
+ #########################################################
13
+ EOF
14
+ c.insert(1, txt)
15
+ end
16
+
17
+ MODIFICATIONS = [ADD_SHABANG, ADD_GENERATED_CODE_DISCLAIMER]
18
+ REJECTIONS = [SHABANG]
19
+ end
20
+
21
+ end
@@ -0,0 +1,3 @@
1
+ module Island
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: island
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Zander Hill
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Helper for creating standalone ruby scripts with all dependencies.
42
+ email:
43
+ - Zander@civet.ws
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - examples/island
54
+ - island.gemspec
55
+ - lib/island.rb
56
+ - lib/island/creator.rb
57
+ - lib/island/plugins.rb
58
+ - lib/island/version.rb
59
+ homepage: ''
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.3.0
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Helper for creating standalone ruby scripts with all dependencies.
83
+ test_files: []
84
+ has_rdoc: