Module: Gorp

Defined in:
lib/version.rb,
lib/gorp/env.rb,
lib/gorp/edit.rb,
lib/gorp/edit.rb,
lib/gorp/rails.rb,
lib/gorp/rails.rb,
lib/gorp/commands.rb

Defined Under Namespace

Modules: Commands, StringEditingFunctions, VERSION Classes: TestCase

Class Method Summary collapse

Class Method Details

.dump_envObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/gorp/env.rb', line 72

def self.dump_env
  extend Commands
  $x.pre Time.now.httpdate, :class=>'stdout'

  if $rails != 'rails'
    Dir.chdir($rails) do
      log :cmd, 'git log -1'
      $x.pre 'git log -1', :class=>'stdin'
      `git log -1`.strip.split(/\n/).each do |line|
        line.sub! /commit (\w{40})/,
          'commit <a href="http://github.com/rails/rails/commit/\1">\1</a>'
        if $1
          $x.pre(:class=>'stdout') {$x << line.chomp}
        else
          $x.pre line.chomp, :class=>'stdout'
        end
      end
    end
  end

  if File.exist? 'Gemfile'
    if File.read("#$rails/RAILS_VERSION") =~ /^[34]/
      cmd = 'rake about'
    else
      cmd = 'rails about'
    end

    log :cmd, cmd
    $x.pre cmd, :class=>'stdin'
    about = `#{cmd}`.sub(/^(Middleware\s+)(.*)/) {
      term,dfn=$1,$2 
      term+dfn.gsub(', ', ",\n" + ' ' * term.length)
    }
    about.split("\n").each {|line| $x.pre line, :class => :stdout}
  elsif File.exist? 'script/rails'
    cmd 'ruby script/rails application -v'
  else
    cmd Gorp.which_rails($rails) + ' -v'
  end
 
  Dir.chdir(File.join($WORK, $rails_app.to_s)) do
    if $bundle
      cmd 'bundle show'
    else
      cmd 'gem list'
      cmd 'echo $RUBYLIB | sed "s/:/\n/g"'
    end
  end

  cmd 'gem -v'
  cmd "#{$ruby} -v"

  if not `which rvm`.empty?
    if ENV['rvm_version']
      cmd "echo $rvm_version", :as => 'rvm -v' 
    else
      cmd "rvm -v | grep '\\S'", :as => 'rvm -v' 
    end
  elsif not `which rbenv`.empty?
    cmd "rbenv --version"
  end

  if not `which nodejs`.empty?
    cmd "nodejs -v"
  elsif not `which node`.empty?
    cmd "node -v"
  end

  if not `which mysql`.empty?
    cmd "mysql --version"
  end

  log :cmd, 'echo $PATH'
  $x.pre 'echo $PATH', :class=>'stdin'
  ENV['PATH'].split(':').each {|path| $x.pre path, :class => :stdout}

  if not `which lsb_release`.empty?
    cmd "lsb_release -irc"
  elsif File.exist? '/etc/debian_version'
    cmd 'cat /etc/debian_version'
  end

  if not `which sw_vers`.empty?
    cmd "sw_vers"
  end

  if not `which uname`.empty?
    cmd "uname -srm"
  end

  config = Gorp::Config.get
  if config and not config.empty?
    $x.pre 'Gorp.config.get', :class=>'stdin'
    $x.table do
      config.sort.each do |name, value|
        $x.tr do
          $x.td name
          $x.td value.inspect
        end
      end
    end
  end
rescue Exception => e
  $x.pre :class => 'traceback' do
    STDERR.puts e.inspect
    $x.text! "#{e.inspect}\n"
    e.backtrace.each {|line| $x.text! "  #{line}\n"}
  end
end

.log(type, message) ⇒ Object



182
183
184
185
186
# File 'lib/gorp/env.rb', line 182

def self.log type, message
  type = type.to_s.ljust(5).upcase
  $stdout.puts Time.now.strftime("[%Y-%m-%d %H:%M:%S] #{type} #{message}")
  $stdout.flush
end

.path(*segments) ⇒ Object



188
189
190
# File 'lib/gorp/env.rb', line 188

def self.path *segments
  Pathname.new($WORK).join(*segments).relative_path_from(Pathname.new($BASE))
end

.which_rails(rails) ⇒ Object

determine which version of rails is running



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/gorp/rails.rb', line 8

def self.which_rails rails
  railties = File.join(rails, 'railties', 'exe', 'rails')
  rails = railties if File.exists?(railties)

  railties = File.join(rails, 'railties', 'bin', 'rails')
  rails = railties if File.exists?(railties)

  bin = File.join(rails, 'bin', 'rails')
  rails = bin if File.exists?(bin)

  if File.exists?(rails)
    firstline = open(rails) {|file| file.readlines.first}
    rails = 'ruby ' + rails unless firstline =~ /^#!/
  end
  rails
end