Class: ExecutableHooks::Wrapper
- Inherits:
-
Object
- Object
- ExecutableHooks::Wrapper
- Defined in:
- lib/executable-hooks/wrapper.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #calculate_bindir(options) ⇒ Object
- #calculate_destination(bindir) ⇒ Object
- #ensure_custom_shebang ⇒ Object
-
#initialize(options) ⇒ Wrapper
constructor
A new instance of Wrapper.
- #install ⇒ Object
- #install_from(full_gem_path) ⇒ Object
- #uninstall ⇒ Object
Constructor Details
#initialize(options) ⇒ Wrapper
Returns a new instance of Wrapper.
18 19 20 |
# File 'lib/executable-hooks/wrapper.rb', line 18 def initialize() @options = || RegenerateBinstubsCommand. end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
16 17 18 |
# File 'lib/executable-hooks/wrapper.rb', line 16 def @options end |
Class Method Details
.expanded_wrapper_name ⇒ Object
12 13 14 |
# File 'lib/executable-hooks/wrapper.rb', line 12 def self. Gem.default_exec_format % self.wrapper_name end |
.wrapper_name ⇒ Object
8 9 10 |
# File 'lib/executable-hooks/wrapper.rb', line 8 def self.wrapper_name 'ruby_executable_hooks' end |
Instance Method Details
#calculate_bindir(options) ⇒ Object
58 59 60 61 |
# File 'lib/executable-hooks/wrapper.rb', line 58 def calculate_bindir() return [:bin_dir] if [:bin_dir] Gem.respond_to?(:bindir,true) ? Gem.send(:bindir) : File.join(Gem.dir, 'bin') end |
#calculate_destination(bindir) ⇒ Object
63 64 65 |
# File 'lib/executable-hooks/wrapper.rb', line 63 def calculate_destination(bindir) File.(self.class., bindir) end |
#ensure_custom_shebang ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/executable-hooks/wrapper.rb', line 68 def ensure_custom_shebang expected_shebang = "$env #{self.class.}" Gem.configuration[:custom_shebang] ||= expected_shebang if Gem.configuration[:custom_shebang] != expected_shebang warn(" Warning: Found custom_shebang: '#{Gem.configuration[:custom_shebang]}', Expected custom_shebang: '#{expected_shebang}', this can potentially break 'executable-hooks' and gem executables overall! Check your '~/.gemrc' and '/etc/gemrc' for 'custom_shebang' and remove it. ") end end |
#install ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/executable-hooks/wrapper.rb', line 22 def install @bindir = [:bin_dir] if [:bin_dir] ensure_custom_shebang executable_hooks_spec = ExecutableHooks::Specification.find if executable_hooks_spec install_from( executable_hooks_spec.full_gem_path ) end end |
#install_from(full_gem_path) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/executable-hooks/wrapper.rb', line 33 def install_from(full_gem_path) wrapper_path = File.( "bin/#{self.class.wrapper_name}", full_gem_path ) bindir = calculate_bindir() destination = calculate_destination(bindir) if File.exist?(wrapper_path) && !same_file(wrapper_path, destination) FileUtils.mkdir_p(bindir) unless File.exist?(bindir) # exception based on Gem::Installer.generate_bin raise Gem::FilePermissionError.new(bindir) unless File.writable?(bindir) FileUtils.cp(wrapper_path, destination) File.chmod(0775, destination) end end |
#uninstall ⇒ Object
53 54 55 56 |
# File 'lib/executable-hooks/wrapper.rb', line 53 def uninstall destination = calculate_destination(calculate_bindir()) FileUtils.rm_f(destination) if File.exist?(destination) end |