Class: Laborantin::Commands::Describe

Inherits:
Laborantin::Command show all
Defined in:
lib/laborantin/runner/commands/describe.rb

Constant Summary collapse

FORMATS =
['default', 'txt', 'html']
HTML_TPL =
<<ERB
<html>
<head>
</head>
<body>
  <h1>Laborantin's description</h1>
  <p>Project located at: <%= runner.root_dir %> </p>
  <h2>List of environments</h2>
  <ul>
  <% Environment.all.each do |env| %>
    <li><%= env.name %>
    (<%= env.description %>)
    </li>
  <% end %>
  </ul>
  <h2>List of scenarios</h2>
  <ul>
  <% Scenario.all.each do |sc| %>
    <li><%= sc.name %>
    (<%= sc.description %>)
      <ul>
      <% sc.parameters.each_pair do |name, spec| %>
        <li><%= name %></li>
        <ul>
          <li><%= spec.description %></li>
          <li><%= spec.values.inspect %></li>
        </ul>
      <% end %>
      </ul>
    </li>
  <% end %>
  </ul>
  <h2>List of analyses</h2>
  <ul>
  <% Analysis.all.each do |a| %>
    <li><%= a.name %>
    (<%= a.description %>)
    <ul>
    <% a.analyses.each do |hash| %>
      <li>
        <%= hash[:str] %>
      </li>
    <% end %>
    </ul>
    </li>
  <% end %>
  </ul>
</body>
</html>
ERB
TXT_TPL =
<<ERB
Available environments:
<% Environment.all.each do |env| %>
  * <%= env.name %> (<%= env.description %>)
<% end %>
Available scenarios:
<% Scenario.all.each do |sc| %>
  * <%= sc.name %> (<%= sc.description %>)
    <% sc.parameters.each_pair do |name, spec| %>
    + <%= name %> (<%= spec.description %>) | <%= spec.values.inspect %>
    <% end %>
  <% end %>
Available analyses:
<% Analysis.all.each do |a| %>
  * <%= a.name %> (<%= a.description %>)
    <% a.analyses.each do |hash| %>
    <% if hash[:params][:type] %>
    + <%= hash[:str] %> (<%= hash[:params][:type] %>)
    <% else %>
    + <%= hash[:str] %> 
    <% end %>
    <% end %>
<% end %>
ERB

Instance Attribute Summary

Attributes inherited from Laborantin::Command

#args, #opts, #runner

Attributes included from Metaprog::Completeable

#completion_block

Instance Method Summary collapse

Methods inherited from Laborantin::Command

describe, each, execute, inherited, #initialize, option, plumbery!, plumbery?, porcelain?, #puts, #run

Methods included from Metaprog::Completeable

#complete, #completion_propositions_iterating_on

Constructor Details

This class inherits a constructor from Laborantin::Command

Instance Method Details

#analysesObject



106
107
108
# File 'lib/laborantin/runner/commands/describe.rb', line 106

def analyses
  Analysis.all
end

#close_outObject



94
95
96
# File 'lib/laborantin/runner/commands/describe.rb', line 94

def close_out
  @out.close unless stdout?
end

#environmentsObject



98
99
100
# File 'lib/laborantin/runner/commands/describe.rb', line 98

def environments
  Environment.all
end

#format_strObject



197
198
199
200
201
202
203
204
# File 'lib/laborantin/runner/commands/describe.rb', line 197

def format_str
  case opts[:format]
  when 'html'
    html_format
  else
    default_format
  end
end

#html_formatObject



187
188
189
# File 'lib/laborantin/runner/commands/describe.rb', line 187

def html_format
  ERB.new(HTML_TPL).result(binding)
end

#outObject



86
87
88
89
90
91
92
# File 'lib/laborantin/runner/commands/describe.rb', line 86

def out
  @out ||= if stdout?
             self #self.puts forward to the runner 
           else
             File.open(opts[:output], 'w')
           end
end

#scenariiObject



102
103
104
# File 'lib/laborantin/runner/commands/describe.rb', line 102

def scenarii
  Scenario.all
end

#stdout?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/laborantin/runner/commands/describe.rb', line 82

def stdout?
  opts[:output].empty?
end

#txt_formatObject Also known as: default_format



191
192
193
# File 'lib/laborantin/runner/commands/describe.rb', line 191

def txt_format
  ERB.new(TXT_TPL).result(binding).lines.reject{|l| l =~/^\s*$/}.join
end