Class: Autoshell::Base
- Inherits:
-
Object
- Object
- Autoshell::Base
- Includes:
- Environment, Filestuff, Git, Log, Run
- Defined in:
- lib/autoshell.rb
Overview
The core autoshell class
Instance Attribute Summary collapse
-
#env ⇒ Hash
Environment variables in this shell.
-
#home_dir ⇒ String
Directory this shell was started with.
-
#working_dir ⇒ String
(also: #to_s)
Current working directory of this shell.
Attributes included from Log
Attributes included from Git
#branch, #commit_hash_for_checkout
Instance Method Summary collapse
-
#initialize(path = '.', env: {}, logger: nil) ⇒ Base
constructor
Create a new shell object with a working directory and environment vars.
Methods included from Log
Methods included from Git
#archive, #branch_from_repo_url, #checkout_version, #clone, #commit_hash, #git, #git?, #switch, #update
Methods included from Environment
#environment?, #node?, #python?, #ruby?, #setup_environment, #setup_node_environment, #setup_python_environment, #setup_ruby_environment
Methods included from Filestuff
#cd, #copy_to, #cp, #dir?, #exist?, #expand, #glob, #ls, #mime, #mkdir, #mkpdir, #move_to, #mv, #read, #read_binary, #read_json, #read_text, #read_yaml, #rm
Methods included from Run
Constructor Details
#initialize(path = '.', env: {}, logger: nil) ⇒ Base
Create a new shell object with a working directory and environment vars
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/autoshell.rb', line 64 def initialize(path = '.', env: {}, logger: nil) # save the working directory self.working_dir = File.(path.to_s) # Load whitelisted environment variables self.env = ENV.select { |k, _| ALLOWED_ENV.include? k } # Set some defaults self.env['SHELL'] = '/bin/bash' # Since this is likely to be running within a `bundle exec` context, we # expect any original GEM_PATH has been unset, and the ENV is configured # such that we only use what is within this bundle, which probably # doesn't include bundler itself, although we'll actually need to # 'bundle install' in working directories. To keep things sane, just # carry over the _ORIGINAL_GEM_PATH so that bundler is available if !ENV['_ORIGINAL_GEM_PATH'].nil? && ENV['_ORIGINAL_GEM_PATH'].strip.length > 0 && (env['GEM_PATH'].nil? || env['GEM_PATH'].strip.length == 0) self.env['GEM_PATH'] = ENV['_ORIGINAL_GEM_PATH'] end # Update environment variables from option self.env.update env # did we get a logger to use? self.logger = logger if logger end |
Instance Attribute Details
#env ⇒ Hash
Returns environment variables in this shell.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/autoshell.rb', line 49 class Base include Autoshell::Run include Autoshell::Filestuff include Autoshell::Environment include Autoshell::Git include Autoshell::Log attr_accessor :env, :working_dir alias_method :to_s, :working_dir # Create a new shell object with a working directory and environment vars # # @param path [String] Create a new shell at this path # @option env [Hash] :env Environment variables to add to this shell # @option logger [Logger] :logger Logger instance to use def initialize(path = '.', env: {}, logger: nil) # save the working directory self.working_dir = File.(path.to_s) # Load whitelisted environment variables self.env = ENV.select { |k, _| ALLOWED_ENV.include? k } # Set some defaults self.env['SHELL'] = '/bin/bash' # Since this is likely to be running within a `bundle exec` context, we # expect any original GEM_PATH has been unset, and the ENV is configured # such that we only use what is within this bundle, which probably # doesn't include bundler itself, although we'll actually need to # 'bundle install' in working directories. To keep things sane, just # carry over the _ORIGINAL_GEM_PATH so that bundler is available if !ENV['_ORIGINAL_GEM_PATH'].nil? && ENV['_ORIGINAL_GEM_PATH'].strip.length > 0 && (env['GEM_PATH'].nil? || env['GEM_PATH'].strip.length == 0) self.env['GEM_PATH'] = ENV['_ORIGINAL_GEM_PATH'] end # Update environment variables from option self.env.update env # did we get a logger to use? self.logger = logger if logger end end |
#home_dir ⇒ String
Returns directory this shell was started with.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/autoshell.rb', line 49 class Base include Autoshell::Run include Autoshell::Filestuff include Autoshell::Environment include Autoshell::Git include Autoshell::Log attr_accessor :env, :working_dir alias_method :to_s, :working_dir # Create a new shell object with a working directory and environment vars # # @param path [String] Create a new shell at this path # @option env [Hash] :env Environment variables to add to this shell # @option logger [Logger] :logger Logger instance to use def initialize(path = '.', env: {}, logger: nil) # save the working directory self.working_dir = File.(path.to_s) # Load whitelisted environment variables self.env = ENV.select { |k, _| ALLOWED_ENV.include? k } # Set some defaults self.env['SHELL'] = '/bin/bash' # Since this is likely to be running within a `bundle exec` context, we # expect any original GEM_PATH has been unset, and the ENV is configured # such that we only use what is within this bundle, which probably # doesn't include bundler itself, although we'll actually need to # 'bundle install' in working directories. To keep things sane, just # carry over the _ORIGINAL_GEM_PATH so that bundler is available if !ENV['_ORIGINAL_GEM_PATH'].nil? && ENV['_ORIGINAL_GEM_PATH'].strip.length > 0 && (env['GEM_PATH'].nil? || env['GEM_PATH'].strip.length == 0) self.env['GEM_PATH'] = ENV['_ORIGINAL_GEM_PATH'] end # Update environment variables from option self.env.update env # did we get a logger to use? self.logger = logger if logger end end |
#working_dir ⇒ String Also known as: to_s
Returns current working directory of this shell.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/autoshell.rb', line 49 class Base include Autoshell::Run include Autoshell::Filestuff include Autoshell::Environment include Autoshell::Git include Autoshell::Log attr_accessor :env, :working_dir alias_method :to_s, :working_dir # Create a new shell object with a working directory and environment vars # # @param path [String] Create a new shell at this path # @option env [Hash] :env Environment variables to add to this shell # @option logger [Logger] :logger Logger instance to use def initialize(path = '.', env: {}, logger: nil) # save the working directory self.working_dir = File.(path.to_s) # Load whitelisted environment variables self.env = ENV.select { |k, _| ALLOWED_ENV.include? k } # Set some defaults self.env['SHELL'] = '/bin/bash' # Since this is likely to be running within a `bundle exec` context, we # expect any original GEM_PATH has been unset, and the ENV is configured # such that we only use what is within this bundle, which probably # doesn't include bundler itself, although we'll actually need to # 'bundle install' in working directories. To keep things sane, just # carry over the _ORIGINAL_GEM_PATH so that bundler is available if !ENV['_ORIGINAL_GEM_PATH'].nil? && ENV['_ORIGINAL_GEM_PATH'].strip.length > 0 && (env['GEM_PATH'].nil? || env['GEM_PATH'].strip.length == 0) self.env['GEM_PATH'] = ENV['_ORIGINAL_GEM_PATH'] end # Update environment variables from option self.env.update env # did we get a logger to use? self.logger = logger if logger end end |