Save gem root
This commit is contained in:
parent
2ec012ca31
commit
b85268434d
2 changed files with 13 additions and 3 deletions
|
@ -2,11 +2,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
gem_name = 'diversipub'
|
||||
gem_root = File.expand_path('..', __dir__).freeze
|
||||
|
||||
begin
|
||||
require gem_name
|
||||
rescue LoadError
|
||||
lib = File.expand_path('../lib', __dir__).freeze
|
||||
lib = File.join(gem_root, 'lib').freeze
|
||||
file = File.join lib, "#{gem_name}.rb"
|
||||
$LOAD_PATH.unshift lib if File.file?(file) && !$LOAD_PATH.include?(lib)
|
||||
require gem_name
|
||||
|
@ -56,6 +57,7 @@ $stdout.sync = true
|
|||
$stderr.sync = true
|
||||
|
||||
main = Diversipub::Main.new(
|
||||
gem_root: gem_root,
|
||||
pwd: Pathname.pwd,
|
||||
program_name: $PROGRAM_NAME,
|
||||
argv: ARGV,
|
||||
|
|
|
@ -5,15 +5,18 @@ module Diversipub
|
|||
# The whole application runner.
|
||||
#
|
||||
class Main
|
||||
attr_reader :pwd, :program_name, :argv, :env, :stdin, :stdout, :stderr
|
||||
attr_reader :gem_root, :pwd, :program_name, :argv, :env,
|
||||
:stdin, :stdout, :stderr
|
||||
|
||||
def initialize(pwd:,
|
||||
def initialize(gem_root:,
|
||||
pwd:,
|
||||
program_name:,
|
||||
argv:,
|
||||
env:,
|
||||
stdin:,
|
||||
stdout:,
|
||||
stderr:)
|
||||
self.gem_root = gem_root
|
||||
self.pwd = pwd
|
||||
self.program_name = program_name
|
||||
self.argv = argv
|
||||
|
@ -25,6 +28,7 @@ module Diversipub
|
|||
end
|
||||
|
||||
def run
|
||||
p gem_root
|
||||
p pwd
|
||||
p program_name
|
||||
p argv
|
||||
|
@ -51,6 +55,10 @@ module Diversipub
|
|||
|
||||
attr_writer :stdin, :stdout, :stderr
|
||||
|
||||
def gem_root=(gem_root)
|
||||
@gem_root = Pathname.new(gem_root).freeze
|
||||
end
|
||||
|
||||
def pwd=(pwd)
|
||||
@pwd = Pathname.new(pwd).freeze
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue