Module: Recipe

Includes:
Contracts::Modules
Defined in:
lib/specs.rb,
lib/aspects/as.rb,
lib/aspects/es.rb,
lib/aspects/go.rb,
lib/aspects/hd.rb,
lib/aspects/ie.rb,
lib/aspects/ld.rb,
lib/aspects/oz.rb,
lib/aspects/ack.rb,
lib/aspects/apt.rb,
lib/aspects/cpu.rb,
lib/aspects/lua.rb,
lib/aspects/net.rb,
lib/aspects/npm.rb,
lib/aspects/php.rb,
lib/aspects/ram.rb,
lib/aspects/ssh.rb,
lib/aspects/ssl.rb,
lib/aspects/tap.rb,
lib/aspects/bios.rb,
lib/aspects/brew.rb,
lib/aspects/cask.rb,
lib/aspects/iojs.rb,
lib/aspects/java.rb,
lib/aspects/node.rb,
lib/aspects/perl.rb,
lib/aspects/ruby.rb,
lib/aspects/dmake.rb,
lib/aspects/emacs.rb,
lib/aspects/kafka.rb,
lib/aspects/latex.rb,
lib/aspects/links.rb,
lib/aspects/ocaml.rb,
lib/aspects/opera.rb,
lib/aspects/redis.rb,
lib/aspects/scala.rb,
lib/aspects/shell.rb,
lib/aspects/xcode.rb,
lib/aspects/chrome.rb,
lib/aspects/docker.rb,
lib/aspects/erlang.rb,
lib/aspects/fabric.rb,
lib/aspects/hadoop.rb,
lib/aspects/python.rb,
lib/aspects/safari.rb,
lib/aspects/splint.rb,
lib/aspects/thrift.rb,
lib/aspects/chicken.rb,
lib/aspects/clojure.rb,
lib/aspects/firefox.rb,
lib/aspects/haskell.rb,
lib/aspects/lacheck.rb,
lib/aspects/openssl.rb,
lib/aspects/python3.rb,
lib/aspects/hardware.rb,
lib/aspects/inkscape.rb,
lib/aspects/postgres.rb,
lib/aspects/terminal.rb,
lib/aspects/memcached.rb,
lib/aspects/chocolatey.rb,
lib/aspects/powershell.rb,
lib/aspects/virtualbox.rb,
lib/aspects/thunderbolt.rb

Overview

Module name must be filename, minus .rb, in CamelCase.

Defined Under Namespace

Modules: Package

Class Method Summary collapse

Class Method Details

.ackObject



2
3
4
# File 'lib/aspects/ack.rb', line 2

def self.ack
  'ack --version'
end

.archObject



144
145
146
# File 'lib/specs.rb', line 144

def self.arch
  "ruby -rrbconfig -e \"puts RbConfig::CONFIG['arch']\""
end

.asObject



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/aspects/as.rb', line 2

def self.as
  # Windows
  if Os.windows?
    'as -version'
    # Assume OS is a Unix variant.
    # as hangs by default, waiting for stdin to end;
    # Send EOF via /dev/null.
    #
    # Don't create spurious a.out file.
  else
    'as -o /dev/null -version < /dev/null'
  end
end

.biosObject



2
3
4
5
6
# File 'lib/aspects/bios.rb', line 2

def self.bios
  if Os.windows?
    'systeminfo | findstr /B /C:"BIOS Version"'
  end
end

.boot2dockerObject



6
7
8
# File 'lib/aspects/docker.rb', line 6

def self.boot2docker
  'boot2docker version'
end

.bundlerObject



12
13
14
# File 'lib/aspects/ruby.rb', line 12

def self.bundler
  'bundle --version'
end

.cabalObject



10
11
12
# File 'lib/aspects/haskell.rb', line 10

def self.cabal
  'cabal --version'
end

.chickenObject



14
15
16
# File 'lib/aspects/chicken.rb', line 14

def self.chicken
  [eggs, csi]
end

.chocolateyObject



2
3
4
5
6
# File 'lib/aspects/chocolatey.rb', line 2

def self.chocolatey
  if Os.windows?
    'chocolatey version'
  end
end

.chromeObject



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/aspects/chrome.rb', line 2

def self.chrome
  # Assumes Chrome installed in default directory.
  if Os.mac?
    '/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --version 2>&1 | grep -v Unsure' # Redirect stderr to stdout
  elsif Os.windows?
    'reg query "HKEY_LOCAL_MACHINE\\SOFTWARE\\Google\\Update\\Clients\\{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"'
    # Assumes
    # * binary is google-chrome.
    # * binary is in PATH.
  else
    'google-chrome --version'
  end
end

.classpathObject



10
11
12
13
14
15
16
# File 'lib/aspects/java.rb', line 10

def self.classpath
  if Os.windows? && !Os.mingw?
    'echo %CLASSPATH'
  else
    'echo $CLASSPATH'
  end
end

.cljObject



6
7
8
# File 'lib/aspects/clojure.rb', line 6

def self.clj
  'lein exec -e \'(println "Clojure " (clojure-version))\''
end

.clojureObject



10
11
12
# File 'lib/aspects/clojure.rb', line 10

def self.clojure
  [clj, lein]
end

.command_not_foundObject



116
117
118
119
120
121
122
123
124
# File 'lib/specs.rb', line 116

def self.command_not_found
  # Windows but not MinGW
  if Os.windows? && !Os.mingw?
    'not recognized as an internal or external command'
    # MinGW or other Unix variant.
  else
    'command not found'
  end
end

.cpanObject



2
3
4
# File 'lib/aspects/perl.rb', line 2

def self.cpan
  'cpan --version'
end

.cpuObject



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/aspects/cpu.rb', line 2

def self.cpu
  if Os.windows?
    'wmic cpu get NumberOfCores, NumberOfLogicalProcessors'
  elsif Os.mac?
    [
     'system_profiler | grep Cores: ',
     'system_profiler | grep Processors:'
    ]
  else
    'cat /proc/cpuinfo | grep processor | wc -l'
  end
end

.cscObject



10
11
12
# File 'lib/aspects/chicken.rb', line 10

def self.csc
  'csc -version'
end

.csiObject



6
7
8
# File 'lib/aspects/chicken.rb', line 6

def self.csi
  'csi -version'
end

.dmakeObject



2
3
4
# File 'lib/aspects/dmake.rb', line 2

def self.dmake
  'dmake -V'
end

.dockerObject



10
11
12
13
14
15
16
# File 'lib/aspects/docker.rb', line 10

def self.docker
  if Os.linux?
    [dockerv]
  else
    [dockerv, boot2docker, 'vagrant --version', virtualbox]
  end
end

.dockervObject



2
3
4
# File 'lib/aspects/docker.rb', line 2

def self.dockerv
  'docker version'
end

.eggsObject



2
3
4
# File 'lib/aspects/chicken.rb', line 2

def self.eggs
  'chicken-install -version'
end

.emacsObject



8
9
10
# File 'lib/aspects/emacs.rb', line 8

def self.emacs
  'emacs --version'
end

.erlObject



6
7
8
# File 'lib/aspects/erlang.rb', line 6

def self.erl
  'erl -eval \'erlang:display(erlang:system_info(otp_release)), halt().\' -noshell'
end

.erlangObject



10
11
12
# File 'lib/aspects/erlang.rb', line 10

def self.erlang
  [rebar, erl]
end

.esObject



2
3
4
# File 'lib/aspects/es.rb', line 2

def self.es
  'curl -s http://localhost:9200/ | grep number'
end

.fabricObject



2
3
4
# File 'lib/aspects/fabric.rb', line 2

def self.fabric
  'fab --version'
end

.firefoxObject



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/aspects/firefox.rb', line 2

def self.firefox
  # Assumes Firefox is installed in the default directory.
  if Os.windows?
    'C:\\Program Files (x86)\\Mozilla Firefox\\firefox --version'
  elsif Os.mac?
    '/Applications/Firefox.app/Contents/MacOS/firefox --version'
    # Assumes firefox in PATH.
  else
    'firefox --version'
  end
end

.ghcObject



14
15
16
# File 'lib/aspects/haskell.rb', line 14

def self.ghc
  'ghc --version'
end

.goObject



2
3
4
# File 'lib/aspects/go.rb', line 2

def self.go
  'go version'
end

.hadoopObject



22
23
24
# File 'lib/aspects/hadoop.rb', line 22

def self.hadoop
  [hadoophome, hadoopversion, hadoopcommand]
end

.hadoopcommandObject



18
19
20
# File 'lib/aspects/hadoop.rb', line 18

def self.hadoopcommand
  'hadoop version'
end

.hadoophomeObject



2
3
4
5
6
7
8
# File 'lib/aspects/hadoop.rb', line 2

def self.hadoophome
  if Os.windows? && !Os.mingw?
    'echo %HADOOP_PREFIX%'
  else
    'echo $HADOOP_PREFIX'
  end
end

.hadoopversionObject



10
11
12
13
14
15
16
# File 'lib/aspects/hadoop.rb', line 10

def self.hadoopversion
  if Os.windows? && !Os.mingw?
    'echo %HADOOP_VERSION%'
  else
    'echo $HADOOP_VERSION'
  end
end

.hardwareObject

ModuleName.command returns the appropriate command line instruction for returning the relevant specifications. OS-contextual instructions can be modulated by querying the Os module (see the root specs Ruby code).



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/aspects/hardware.rb', line 5

def self.hardware
  # Use environment variable.
  if Os.windows?
    'systeminfo | findstr /B /C:"System Manufacturer" /C:"System Model"'
    # Produces a noticeable delay.
  elsif Os.mac?
    'system_profiler 2>&1 | grep \'Model Identifier\''
    # Assume:
    # * OS is a Unix variant.
    # * dmidecode is installed.
  else
    'sudo dmidecode -t system | grep \'Manufacturer\\|Product\''
  end
end

.haskellObject



26
27
28
29
30
31
32
# File 'lib/aspects/haskell.rb', line 26

def self.haskell
  if Os.mac?
    [cabal, ghc]
  else
    [cabal, ghc, haskellplatform]
  end
end

.haskellplatformObject



18
19
20
21
22
23
24
# File 'lib/aspects/haskell.rb', line 18

def self.haskellplatform
  if Os.linux?
    Package.apt('haskell-platform')
  else
    'ghc-pkg field haskell-platform version'
  end
end

.hdObject



2
3
4
5
6
7
8
# File 'lib/aspects/hd.rb', line 2

def self.hd
  if Os.windows?
    'fsutil fsinfo drives'
  else
    'df -h'
  end
end

.ieObject



2
3
4
5
6
# File 'lib/aspects/ie.rb', line 2

def self.ie
  if Os.windows?
    'reg query "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Internet Explorer" /v Version'
  end
end

.inkscapeObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/aspects/inkscape.rb', line 2

def self.inkscape
  case Os.os_name
  when :windows
    if Os.x86_64?
      'C:\\Program Files (x86)\\Inkscape\\inkscape --version'
    else
      '"C:\\Program Files\\Inkscape\\inkscape" --version'
    end
  when :mac
    '/Applications/Inkscape.app/Contents/Resources/bin/inkscape --version'
  else
    'inkscape --version'
  end
end

.iojsObject



6
7
8
# File 'lib/aspects/iojs.rb', line 6

def self.iojs
  [npm, iojs_v]
end

.iojs_vObject



2
3
4
# File 'lib/aspects/iojs.rb', line 2

def self.iojs_v
  'iojs --version'
end

.javaObject



34
35
36
# File 'lib/aspects/java.rb', line 34

def self.java
  [mvn, classpath, javahome, oakc, oak]
end

.javahomeObject



18
19
20
21
22
23
24
# File 'lib/aspects/java.rb', line 18

def self.javahome
  if Os.windows? && !Os.mingw?
    'echo %JAVA_HOME%'
  else
    'echo $JAVA_HOME'
  end
end

.kafkaObject



2
3
4
5
6
# File 'lib/aspects/kafka.rb', line 2

def self.kafka
  if Os.mac?
    [Package::brew('kafka')]
  end
end

.lacheckObject



2
3
4
# File 'lib/aspects/lacheck.rb', line 2

def self.lacheck
  'lacheck | grep lacheck.lex'
end

.latexObject



2
3
4
5
6
# File 'lib/aspects/latex.rb', line 2

def self.latex
  if Os.unix?
    'pdflatex --version'
  end
end

.ldObject



2
3
4
# File 'lib/aspects/ld.rb', line 2

def self.ld
  'ld -v'
end

.leinObject



2
3
4
# File 'lib/aspects/clojure.rb', line 2

def self.lein
  'lein --version'
end


2
3
4
# File 'lib/aspects/links.rb', line 2

def self.links
  'links -version'
end

.luaObject



2
3
4
# File 'lib/aspects/lua.rb', line 2

def self.lua
  'lua -v'
end

.mavenObject



2
3
4
# File 'lib/aspects/java.rb', line 2

def self.maven
  mvn
end

.memcachedObject



2
3
4
# File 'lib/aspects/memcached.rb', line 2

def self.memcached
  'echo version | nc localhost 11211'
end

.mvnObject



6
7
8
# File 'lib/aspects/java.rb', line 6

def self.mvn
  'mvn --version'
end

.netObject



2
3
4
# File 'lib/aspects/net.rb', line 2

def self.net
  'ruby -e "require \'net/http\'; puts Net::HTTP.new(\'icanhazip.com\').request(Net::HTTP::Get.new(\'/\', {\'User-Agent\'=>\'curl\'})).body"'
end

.nodeObject



6
7
8
# File 'lib/aspects/node.rb', line 6

def self.node
  [npm, nodejs]
end

.nodejsObject



2
3
4
# File 'lib/aspects/node.rb', line 2

def self.nodejs
  'node --version'
end

.npmObject



8
9
10
# File 'lib/aspects/npm.rb', line 8

def self.npm
  'npm --version'
end

.oakObject



26
27
28
# File 'lib/aspects/java.rb', line 26

def self.oak
  'java -version'
end

.oakcObject



30
31
32
# File 'lib/aspects/java.rb', line 30

def self.oakc
  'javac -version'
end

.ocamlObject



16
17
18
# File 'lib/aspects/ocaml.rb', line 16

def self.ocaml
  [ocamlc, opam]
end

.ocamlcObject



8
9
10
# File 'lib/aspects/ocaml.rb', line 8

def self.ocamlc
  'ocamlc -version'
end

.opamObject



12
13
14
# File 'lib/aspects/ocaml.rb', line 12

def self.opam
  'opam --version'
end

.opensslObject



2
3
4
# File 'lib/aspects/openssl.rb', line 2

def self.openssl
  'openssl version'
end

.operaObject



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/aspects/opera.rb', line 2

def self.opera
  # Assumes opera in PATH.
  if Os.unix? && !Os.mac?
    'opera -version'
    # Opera for Mac/Windows does not support the -version command line option.
    # # Assumes Opera is installed in the default directory.
    # elsif Os.mac?
    #       '/Applications/Opera.app/Contents/MacOS/Opera -version'
    # elsif Os.windows?
    #       'C:\\Program Files (x86)\\Opera\\opera -version'
  end
end

.osObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/specs.rb', line 127

def self.os
  case Os.os_name
  when :windows
    'systeminfo | findstr /B /C:"OS Name" /C:"OS Version"'
  when :mac
    'system_profiler SPSoftwareDataType | grep \'System Version\''
  when :linux
    'cat /etc/*release*'
  when :unix
    'uname -a'
  # Punt.
  else
    'echo $OS'
  end
end

.ozObject



2
3
4
# File 'lib/aspects/oz.rb', line 2

def self.oz
  'ozc -v'
end

.pearObject



2
3
4
# File 'lib/aspects/php.rb', line 2

def self.pear
  'pear version'
end

.perlObject



10
11
12
# File 'lib/aspects/perl.rb', line 10

def self.perl
  [cpan, pl]
end

.phObject



6
7
8
# File 'lib/aspects/php.rb', line 6

def self.ph
  'php --version'
end

.phpObject



10
11
12
# File 'lib/aspects/php.rb', line 10

def self.php
  [pear, ph]
end

.pipObject



8
9
10
# File 'lib/aspects/python.rb', line 8

def self.pip
  'pip --version'
end

.pip3Object



8
9
10
# File 'lib/aspects/python3.rb', line 8

def self.pip3
  'pip3 --version'
end

.plObject



6
7
8
# File 'lib/aspects/perl.rb', line 6

def self.pl
  'perl --version'
end

.postgresObject



6
7
8
# File 'lib/aspects/postgres.rb', line 6

def self.postgres
  'psql --version'
end

.postgresqlObject



2
3
4
# File 'lib/aspects/postgres.rb', line 2

def self.postgresql
  'psql --version'
end

.powershellObject



2
3
4
5
6
# File 'lib/aspects/powershell.rb', line 2

def self.powershell
  if Os.windows?
    '@powershell Get-Host'
  end
end

.pyObject



12
13
14
# File 'lib/aspects/python.rb', line 12

def self.py
  'python --version'
end

.py3Object



12
13
14
# File 'lib/aspects/python3.rb', line 12

def self.py3
  'python3 --version'
end

.pythonObject



16
17
18
# File 'lib/aspects/python.rb', line 16

def self.python
  [pip, py]
end

.python3Object



16
17
18
# File 'lib/aspects/python3.rb', line 16

def self.python3
  [pip3, py3]
end

.ramObject



2
3
4
5
6
7
8
9
10
# File 'lib/aspects/ram.rb', line 2

def self.ram
  if Os.windows?
    'systeminfo | findstr /C:"Total Physical Memory"'
  elsif Os.mac?
    'system_profiler | grep \'Memory:\''
  else
    'grep MemTotal /proc/meminfo'
  end
end

.rbObject



174
175
176
# File 'lib/specs.rb', line 174

def self.rb
  'ruby --version'
end

.rebarObject



2
3
4
# File 'lib/aspects/erlang.rb', line 2

def self.rebar
  'rebar -V'
end

.redisObject



10
11
12
13
14
15
16
17
18
# File 'lib/aspects/redis.rb', line 10

def self.redis
  # In Windows, Redis server is provided as a service
  # instead of a CLI program.
  if Os.windows?
    redis_cli
  else
    [redis_cli, redis_server]
  end
end

.redis_cliObject



2
3
4
# File 'lib/aspects/redis.rb', line 2

def self.redis_cli
  'redis-cli --version'
end

.redis_serverObject



6
7
8
# File 'lib/aspects/redis.rb', line 6

def self.redis_server
  'redis-server --version'
end

.rubyObject



179
180
181
# File 'lib/specs.rb', line 179

def self.ruby
  [rubygems, rb]
end

.ruby1_8?Boolean

Returns:

  • (Boolean)


154
155
156
# File 'lib/specs.rb', line 154

def self.ruby1_8?
  RUBY_VERSION =~ /^1\.8/
end

.ruby1_9?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/specs.rb', line 159

def self.ruby1_9?
  RUBY_VERSION =~ /^1\.9/
end

.ruby2?Boolean

Returns:

  • (Boolean)


164
165
166
# File 'lib/specs.rb', line 164

def self.ruby2?
  RUBY_VERSION =~ /^2/
end

.ruby_vObject



149
150
151
# File 'lib/specs.rb', line 149

def self.ruby_v
  RUBY_VERSION
end

.rubygemsObject



169
170
171
# File 'lib/specs.rb', line 169

def self.rubygems
  'gem --version'
end

.safariObject



2
3
4
5
6
# File 'lib/aspects/safari.rb', line 2

def self.safari
  if Os.mac?
    'system_profiler SPApplicationsDataType | grep \'Safari:\' -A 2'
  end
end

.sbtObject



6
7
8
# File 'lib/aspects/scala.rb', line 6

def self.sbt
  'sbt sbt-version'
end

.scalaObject



10
11
12
# File 'lib/aspects/scala.rb', line 10

def self.scala
  [sbt, scalac]
end

.scalacObject



2
3
4
# File 'lib/aspects/scala.rb', line 2

def self.scalac
  'scalac -version'
end

.shellObject



2
3
4
5
6
7
8
# File 'lib/aspects/shell.rb', line 2

def self.shell
  if Os.windows?
    'echo %cmdextversion%'
  elsif Os.unix?
    'sh --version'
  end
end

.splintObject



2
3
4
# File 'lib/aspects/splint.rb', line 2

def self.splint
  'splint -help version'
end

.sshObject



2
3
4
# File 'lib/aspects/ssh.rb', line 2

def self.ssh
  'ssh -V'
end

.sslObject



2
3
4
# File 'lib/aspects/ssl.rb', line 2

def self.ssl
  'openssl version'
end

.tapObject



2
3
4
# File 'lib/aspects/tap.rb', line 2

def self.tap
  'tap --version'
end

.terminalObject



2
3
4
5
6
# File 'lib/aspects/terminal.rb', line 2

def self.terminal
  if Os.mac?
    'system_profiler -detailLevel full 2>&1 | grep Terminal -A 5 | grep Version -m 1'
  end
end

.thriftObject



2
3
4
# File 'lib/aspects/thrift.rb', line 2

def self.thrift
  'thrift -version'
end

.thunderboltObject



2
3
4
5
6
# File 'lib/aspects/thunderbolt.rb', line 2

def self.thunderbolt
  if Os.mac?
    'system_profiler | grep \'Thunderbolt Version\' | head -n 1'
  end
end

.virtualboxObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/aspects/virtualbox.rb', line 2

def self.virtualbox
  case Os.os_name
  when :windows
    if Os.x86_64?
      '"C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe" --version'
    else
      '"C:\\Program Files (x86)\\Oracle\\VirtualBox\\VBoxManage.exe" --version'
    end
  when :mac
    'vboxwebsrv --help 2>&1 | grep VirtualBox'
  else
    'vboxwebsrv --help 2>&1 | grep VirtualBox'
  end
end

.xcodeObject



2
3
4
5
6
# File 'lib/aspects/xcode.rb', line 2

def self.xcode
  if Os.mac?
    'xcodebuild -version'
  end
end