Class: RippleNetworks::WarningShot::DepChecker
- Inherits:
-
Object
- Object
- RippleNetworks::WarningShot::DepChecker
- Includes:
- RippleNetworks::WarningShot
- Defined in:
- lib/warning_shot/dep_checker.rb
Overview
- Name
-
WarningShot
- Type
-
Class
- Namespace
-
RippleNetworks::WarningShot
- Description
-
Application dependency checker
- Inherits
-
None
- Mixins
-
None
- Extends
-
None
- RequiredGems
-
activerecord
- RequiredRubyLibraries
-
rubygems, fileutils, net/http, net/https, uri, yaml
- RequiredBinaries
-
which, growlnotify (if –growl option used)
- Authors
-
Cory O’Daniel
-
codaniel @nospam@ rippletv.com
- Last_Edited
-
Wed Dec 12 15:01:00 PST 2007
Constant Summary collapse
- LIB_DIRECTORY =
$:[0]
- DEP_FILES =
Config files to load
%w(urls preload classes binaries filesystem gems).freeze
- SCRIPTS =
Script folders to load
%w(ruby shell).freeze
- MANDATORY_OPTIONS =
Any mandatory options
%w().freeze
- ENVIRONMENT_MAP =
Ability to map additional corporate environments to applicable rails environment
{ "test" => "test", "development" => "development", "qa" => "development", "stage" => "production", "production" => "production" }.freeze
- DEFAULTS =
{ :dir => '.', :environment => 'development', :strict => false, :flush => false, :gems => false, :verbose => false, :growl => false, :templates => false }
- CLEAR =
`clear`
Instance Attribute Summary collapse
-
#configs ⇒ Object
readonly
Returns the value of attribute configs.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Class Method Summary collapse
-
.generate_templates(path = ".") ⇒ Object
- Name
- generate_templates Access
- public Description
- Generates all template files Last_Edited
- Fri Dec 14 17:53:32 PST 2007 Todo
-
Encapsulate as seperate private functions ===Parameters * Name: path * Description: path of creation * Datatype: string * Default: .
-
.has_binary?(app) ⇒ Boolean
- Name
- DepChecker.has_binary? Access
- public Description
- Determine if an command line application is installed Last_Edited
- Wed Dec 12 22:05:55 PST 2007 ===Parameters * Name: app * Description: name of cl tool * Datatype: string * Default: None * Required: True ===Returns Description
- whether it is installed or not Datatype
-
Boolean.
Instance Method Summary collapse
-
#initialize(options = DEFAULTS) ⇒ DepChecker
constructor
A new instance of DepChecker.
-
#record(msg, level = :none) ⇒ Object
- Name
- record Access
- public Description
- Record message to log Last_Edited
-
Wed Dec 12 15:37:21 PST 2007 ===Parameters * Name: level * Description: Message level :error, :warning, :info, :none * Datatype: Symbol * Default: :info * Required: false.
-
#run ⇒ Object
- Name
- run Access
- private Description
- Run dependency checker Last_Edited
-
Wed Dec 12 16:04:15 PST 2007.
- #unload ⇒ Object
Constructor Details
#initialize(options = DEFAULTS) ⇒ DepChecker
Returns a new instance of DepChecker.
68 69 70 71 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 |
# File 'lib/warning_shot/dep_checker.rb', line 68 def initialize(=DEFAULTS) @original_requires = $".clone ObjectSpace.define_finalizer(self, lambda{ @log_file.close unless @log_file.closed? }) #Add directory information to defaults DEFAULTS[:log] = File.join([:dir],"log","warning_shot_#{[:environment]}.log") DEFAULTS[:configs] = File.join([:dir],"config","warning_shot") @options = DEFAULTS.merge() #Map to correct running environment @options[:environment] = ENVIRONMENT_MAP[@options[:environment]] #No errors or warnings @errors = 0 @warnings = 0 #initalize config file hash @configs = {} #Flush log flush_log! if @options[:flush] #Open log @log_file = File.open(@options[:log],"a+") #Check dependencies @which_installed = has_binary_prereqs? puts CLEAR if @options[:verbose] end |
Instance Attribute Details
#configs ⇒ Object (readonly)
Returns the value of attribute configs.
22 23 24 |
# File 'lib/warning_shot/dep_checker.rb', line 22 def configs @configs end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
22 23 24 |
# File 'lib/warning_shot/dep_checker.rb', line 22 def errors @errors end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
22 23 24 |
# File 'lib/warning_shot/dep_checker.rb', line 22 def @options end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
22 23 24 |
# File 'lib/warning_shot/dep_checker.rb', line 22 def warnings @warnings end |
Class Method Details
.generate_templates(path = ".") ⇒ Object
- Name
-
generate_templates
- Access
-
public
- Description
-
Generates all template files
- Last_Edited
-
Fri Dec 14 17:53:32 PST 2007
- Todo
-
Encapsulate as seperate private functions
===Parameters
* Name: path
* Description: path of creation
* Datatype: string
* Default: .
* Required: false
138 139 140 |
# File 'lib/warning_shot/dep_checker.rb', line 138 def DepChecker.generate_templates(path=".") TemplateGenerator.new(path) end |
.has_binary?(app) ⇒ Boolean
- Name
-
DepChecker.has_binary?
- Access
-
public
- Description
-
Determine if an command line application is installed
- Last_Edited
-
Wed Dec 12 22:05:55 PST 2007
===Parameters
* Name: app
* Description: name of cl tool
* Datatype: string
* Default: None
* Required: True
===Returns
*Description*:: whether it is installed or not
*Datatype*:: Boolean
115 116 117 |
# File 'lib/warning_shot/dep_checker.rb', line 115 def DepChecker.has_binary?(app) %x{which #{app}}.match(/\bno/).nil? end |
Instance Method Details
#record(msg, level = :none) ⇒ Object
- Name
-
record
- Access
-
public
- Description
-
Record message to log
- Last_Edited
-
Wed Dec 12 15:37:21 PST 2007
===Parameters
* Name: level
* Description: Message level :error, :warning, :info, :none
* Datatype: Symbol
* Default: :info
* Required: false
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/warning_shot/dep_checker.rb', line 253 def record(msg,level=:none) if [:error,:warning,:info,:fatal].include? level msg = %{#{level.to_s.upcase}: #{msg}} end case level when :error @errors += 1 when :warning @warnings += 1 end @log_file.puts msg if @options[:verbose] case level when :info msg = "\e[37m#{msg}\e[0m" when :error msg = "\e[31m#{msg}\e[0m" when :warning msg = "\e[33m#{msg}\e[0m" when :fatal msg = "\e[1m\e[5m#{msg}\e[0m" end puts msg Kernel.exit if level == :fatal end end |
#run ⇒ Object
- Name
-
run
- Access
-
private
- Description
-
Run dependency checker
- Last_Edited
-
Wed Dec 12 16:04:15 PST 2007
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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/warning_shot/dep_checker.rb', line 149 def run start_time = Time.now section record("WarningShot (v. #{VERSION::INTERNAL}) - started @ #{start_time}") check_framework record("Environment: #{@options[:environment]}") record("Framework: #{@framework}") section("Loading YAML files:") ConfigParser.run(self) section("Preloading classes") class_loader("preload") section("Checking class dependencies") count = class_loader("classes") record "#{count} classes not found",:error if count > 0 section("Checking binary dependencies") count = check_binaries record "#{count} binaries not found", :error if count > 0 section("Checking filesystem dependencies") count = check_filesystem record "#{count} files/directories not found", :error if count > 0 section("Checking URL dependencies") count = check_urls record "#{count} sites unavailable", :error if count > 0 section("Checking gem dependencies") #Initialize gem handler @gh = GemHandler.new(self.configs["gems"],self.[:gems]) gem_errors = @gh.missing_gems.size if @gh.missing_gems.size > 0 record "#{gem_errors} gems not found: " @gh.missing_gems.each do |gem,version| record "\t#{gem} : #{version}" end end if self.[:gems] && @gh.failed_installs.size > 0 gem_errors = @gh.failed_installs.size record "#{gem_errors} gems failed to install:" @gh.failed_installs.each do |gem,| record "\t#{gem}: #{}" end end @gh.installed_gems.each do |gem| record("#{gem.name} v. #{gem.version} was installed!",:info) end record("#{gem_errors} gems had errors", :error) if gem_errors > 0 @errors += gem_errors section("Loading Ruby test scripts") count = load_ruby_scripts record("#{count} scripts failed to load",:error) if count > 0 section("Running Ruby test scripts") count = test_ruby_scripts record("#{count} scripts failed",:error) if count > 0 #section("Shell script dependencies") #count = check_shell_scripts #record("#{count} scripts failed",:error) if count > 0 section section("RESULTS") record("Total Warnings #{@warnings}",(@warnings > 0) ? :warning : :info) record("Total Errors: #{@errors}",(@errors > 0) ? :error : :info) record("Checked in #{Time.now.to_f-start_time.to_f}s",:info) section #Status via growlnotify if @options[:growl] #TODO Update to Red/Green ruby, instead of Rails Logo if @errors == 0 growl("All Dependencies tests passed!","ruby_ok.png") else growl("#{@errors} failed dependencies!","ruby_fail.png") end end unload @log_file.close unless @log_file.closed? end |
#unload ⇒ Object
119 120 121 122 123 |
# File 'lib/warning_shot/dep_checker.rb', line 119 def unload ($" - @original_requires).each do |req| $".delete(req) end end |