executable_pathname 1.0.0

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: 8a31bb2ba7bd7c869b1a8ce3c824ad56e38c7b4e
4
+ data.tar.gz: b208c1e54c053fb4645bdc26d123ddf0025b1fac
5
+ SHA512:
6
+ metadata.gz: 67e9e86aa69b8af4ed8f9d70a2f81d0f622cd55a9239d2e533fbb6eb555ffe39cf3e1c5dff4e54c178f7a06a6e6a83608eedc74eba3a0197e86a3de3c1a80a74
7
+ data.tar.gz: de5df95b42f4ba293f84814584251bd0458154c9e879886cfdb8e927a07a5304055c789e963db802974dbb823801b171a08dce4d3180629b423feff59457b131
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at alan.stebbens@procore.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in executable_pathname.gemspec
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Alan Stebbens
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Alan Stebbens
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.
@@ -0,0 +1,111 @@
1
+ # ExecutablePathname
2
+
3
+ The `executable_pathname` gem provides additional methods for inspecting executable pathnames, within a subclass of the Pathname class.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'executable_pathname'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install executable_pathname
20
+
21
+ ## Usage
22
+
23
+ require 'executable_pathname'
24
+
25
+ ### Class Methods
26
+
27
+ .valid_executable?(path)
28
+
29
+ Returns true if `path` is a _valid_ executable file, where validity is
30
+ determined by examining the file, and ensuring that if it is a "hash-bang"
31
+ script, that the hash-bang path exists, or is likely to exist.
32
+
33
+ .path_list
34
+
35
+ Returns the current environment variable `PATH` split into an array.
36
+
37
+ .remote_path_list
38
+
39
+ Returns the remote path list, as an array, which is obtained from the envar `REMOTE_PATH`, if defined, or defaults to `'/bin:/usr/bin:/usr/local/bin'` _(split into an array)_.
40
+
41
+ .new(path)
42
+
43
+ Creates a new instance of an `ExecutablePathname`, with the below instance methods.
44
+
45
+ ### Instance Methods
46
+
47
+ #first_line
48
+
49
+ Returns the first line of the file at `path`, if text.
50
+
51
+ #shbang?
52
+
53
+ Returns true if the first line of the file at `path` starts with `#!`. "shbang" is a contraction of "hash bang".
54
+
55
+ #shbang_paths
56
+
57
+ Returns the paths from the hash-bang line. If the hash-bang line looks like this:
58
+
59
+ #!/path/to/some/file arg1 arg2
60
+
61
+ then the resulting array from `shbang_paths` is `['/path/to/some/file', 'arg1', 'arg2']`.
62
+
63
+ #env_shbang?
64
+
65
+ Returns true if the `first_line` value contains at least two paths, the first of which ends with `/env`
66
+
67
+ #valid_shbang?
68
+
69
+ Returns true if the `first_line` is a valid hash-bang, where validity is
70
+ determined by the actual existence of the first path, or the probable existence
71
+ of the path, based on it being one of the well-known paths from `REMOTE_PATH`.
72
+
73
+ #invalid_shbang?
74
+
75
+ Returns false if the `first_line` value is not a valid hash-bang.
76
+
77
+ #valid_env_shbang?
78
+
79
+ Returns false if the `first_line` value is not a valid `env` hash-bang path.
80
+
81
+ #executable_file?
82
+
83
+ Returns true if the instance is an executable file.
84
+
85
+ #valid_executable?
86
+
87
+ Returns true if the instance is a _valid_ executable file; that is, if the
88
+ hash-bang path exists, or is in a well-known path.
89
+
90
+ #well_known_path?
91
+
92
+ Returns true if the instance path is in one of the REMOTE_PATH directories.
93
+
94
+ #remove_execute_permissions
95
+
96
+ Removes the execute permissions on the instance. An error is raised if the
97
+ instance path does not exist.
98
+
99
+ ## Development
100
+
101
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
102
+
103
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
104
+
105
+ ## Contributing
106
+
107
+ Bug reports and pull requests are welcome on GitHub at https://github.com/aks/executable_pathname. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
108
+
109
+ ## License
110
+
111
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ rescue LoadError
7
+ end
8
+
9
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "executable_pathname"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -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 "executable_pathname/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "executable_pathname"
8
+ spec.version = ExecutablePathname::VERSION
9
+ spec.authors = ["Alan Stebbens"]
10
+ spec.email = ["aks@stebbens.org"]
11
+
12
+ spec.summary = %q{Additional methods for inspecting executable pathnames as subclass to Pathname}
13
+ spec.description = %q{Provide additional methods to inspect executable files, as a Pathname subclass}
14
+ spec.homepage = "https://github.com/aks/executable_pathname"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "bin"
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.15"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.6.0"
27
+ spec.add_development_dependency "activesupport", "~> 5.1.3"
28
+ spec.add_development_dependency "fuubar", "~> 2.2.0"
29
+ spec.add_development_dependency "pry-byebug", "~> 3.5.0"
30
+ end
@@ -0,0 +1,102 @@
1
+ require 'pathname'
2
+
3
+ require "executable_pathname/version"
4
+
5
+ class ExecutablePathname < Pathname
6
+
7
+ # Absolute paths must exist or be in a well-known directory path. Relative
8
+ # paths must exist within one of the PATH directories, or within a well-known
9
+ # directory path
10
+
11
+ # Define the envar REMOTE_PATH as the colon-separated list of well-known
12
+ # directory paths that will be referenced on remote hosts. The default is
13
+ # '/bin:/usr/bin:/usr/local/bin'
14
+
15
+ def self.valid_executable?(name)
16
+ case name
17
+ when %r{^/}, %r{.+/.+}
18
+ pn = new(name)
19
+ return true if pn.valid_executable?
20
+ else
21
+ path_list.each do |dirname|
22
+ pn = new(File.join(dirname, name))
23
+ return true if pn.valid_executable?
24
+ end
25
+ end
26
+ false
27
+ end
28
+
29
+ def self.path_list
30
+ @@path_list ||= ENV['PATH'].split(':')
31
+ end
32
+
33
+ def self.remote_path_list
34
+ (ENV['REMOTE_PATH'] || '/bin:/usr/bin:/usr/local/bin').split(':')
35
+ end
36
+
37
+ def initialize(path)
38
+ super(path)
39
+ @first_line = nil
40
+ @shbang_paths = nil
41
+ end
42
+
43
+ def first_line
44
+ @first_line ||= open { |io|
45
+ line = io.gets
46
+ line.chomp if line
47
+ }
48
+ rescue Errno::ENOENT, Errno::EACCES, IOError
49
+ nil
50
+ end
51
+
52
+ def shbang?
53
+ first_line && first_line[0..1] == '#!'
54
+ end
55
+
56
+ def shbang_paths
57
+ @shbang_paths ||= first_line &&
58
+ case first_line
59
+ when /^#!\s*(\S+)\s+(\S+.)/ then [$1, $2.chomp]
60
+ when /^#!\s*(\S+)/ then [$1.chomp]
61
+ else []
62
+ end
63
+ end
64
+
65
+ def env_shbang?
66
+ shbang_paths && shbang_paths.size > 1 && shbang_paths[0].end_with?('env')
67
+ end
68
+
69
+ def valid_shbang?
70
+ shbang? && (env_shbang? ? valid_env_shbang? : valid_shbang_command?)
71
+ end
72
+
73
+ def invalid_shbang?
74
+ shbang? && (env_shbang? ? !valid_env_shbang? : !valid_shbang_command?)
75
+ end
76
+
77
+ def valid_env_shbang?
78
+ env_shbang? && valid_shbang_command? && shbang_paths.last.split('/').size == 1
79
+ end
80
+
81
+ def valid_shbang_command?
82
+ shbang_paths.size > 0 && ExecutablePathname.valid_executable?(shbang_paths[0])
83
+ end
84
+
85
+ def executable_file?
86
+ exist? && file? && executable?
87
+ end
88
+
89
+ def valid_executable?
90
+ exist? && executable_file? && (!shbang? || valid_shbang?)
91
+ end
92
+
93
+ def well_known_path?
94
+ return false unless exist?
95
+ ExecutablePathname.remote_path_list.any? {|rp| (shbang? ? shbang_paths.first : to_path).start_with?(rp)}
96
+ end
97
+
98
+ def remove_execute_permissions
99
+ chmod(stat.mode & ~0111)
100
+ end
101
+
102
+ end
@@ -0,0 +1,4 @@
1
+ require 'pathname'
2
+ class ExecutablePathname < Pathname
3
+ VERSION = "1.0.0"
4
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: executable_pathname
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Alan Stebbens
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-02 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.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.6.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.6.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 5.1.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 5.1.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: fuubar
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.2.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.2.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.5.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.5.0
97
+ description: Provide additional methods to inspect executable files, as a Pathname
98
+ subclass
99
+ email:
100
+ - aks@stebbens.org
101
+ executables:
102
+ - console
103
+ - setup
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - ".gitignore"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - LICENSE
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - executable_pathname.gemspec
117
+ - lib/executable_pathname.rb
118
+ - lib/executable_pathname/version.rb
119
+ homepage: https://github.com/aks/executable_pathname
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.6.11
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Additional methods for inspecting executable pathnames as subclass to Pathname
143
+ test_files: []