Module: Autoshell::Environment

Included in:
Base
Defined in:
lib/autoshell/environment.rb

Overview

Stuff for working with a development environment

Instance Method Summary collapse

Instance Method Details

#environment?Boolean

Do we have an environment setup?

Returns:

  • (Boolean)

    true if this dir has a bundle, virtualenv or node modules



33
34
35
# File 'lib/autoshell/environment.rb', line 33

def environment?
  dir?('.bundle') || dir?('.virtualenv') || dir?('node_modules')
end

#node?Boolean

Is this a node project?

Returns:

  • (Boolean)

    true if this dir has a package.json



18
19
20
# File 'lib/autoshell/environment.rb', line 18

def node?
  exist? 'package.json'
end

#python?Boolean

Is this a python project?

Returns:

  • (Boolean)

    true if this dir has a requirements.txt



12
13
14
# File 'lib/autoshell/environment.rb', line 12

def python?
  exist? 'requirements.txt'
end

#ruby?Boolean

Is this a ruby project?

Returns:

  • (Boolean)

    true if this dir has a Gemfile



6
7
8
# File 'lib/autoshell/environment.rb', line 6

def ruby?
  exist? 'Gemfile'
end

#setup_environmentString

Setup the environment

Returns:

  • (String)

    output of the environment setup commands



24
25
26
27
28
# File 'lib/autoshell/environment.rb', line 24

def setup_environment
  setup_ruby_environment ||
    setup_python_environment ||
    setup_node_environment
end

#setup_node_environmentString

Setup a node environment

Returns:

  • (String)

    output of the environment setup commands



58
59
60
61
# File 'lib/autoshell/environment.rb', line 58

def setup_node_environment
  return unless node?
  cd { run 'npm', 'install' }
end

#setup_python_environmentString

Setup a python environment

Returns:

  • (String)

    output of the environment setup commands



46
47
48
49
50
51
52
53
54
# File 'lib/autoshell/environment.rb', line 46

def setup_python_environment
  return unless python?
  cd do
    [
      run('virtualenv', '.virtualenv'),
      run('./.virtualenv/bin/pip', '-r', 'requirements.txt')
    ].join("\n")
  end
end

#setup_ruby_environmentString

Setup a ruby environment

Returns:

  • (String)

    output of the environment setup commands



39
40
41
42
# File 'lib/autoshell/environment.rb', line 39

def setup_ruby_environment
  return unless ruby?
  cd { run 'bundle', 'install', '--path', '.bundle', '--deployment' }
end