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, :gempath => nil }
Instance Attribute Summary collapse
-
#configs ⇒ Object
readonly
Returns the value of attribute configs.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#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.
-
#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.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/warning_shot/dep_checker.rb', line 57 def initialize(=DEFAULTS) @original_requires = $".clone #Add directory information to defaults DEFAULTS[:configs] = File.join([:dir],"config","warning_shot") @options = DEFAULTS.merge() #Map to correct running environment @options[:environment] = ENVIRONMENT_MAP[@options[:environment]] @logger = Logger.new( (@options[:log] || File.join(@options[:dir],"log","warning_shot_#{@options[:environment]}.log")), {:verbose => @options[:verbose], :flush => @options[:flush]} ) #No errors or warnings @errors = 0 @warnings = 0 #initalize config file hash @configs = {} #Check dependencies @which_installed = has_binary_prereqs? 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 |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
22 23 24 |
# File 'lib/warning_shot/dep_checker.rb', line 22 def logger @logger 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
121 122 123 |
# File 'lib/warning_shot/dep_checker.rb', line 121 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
98 99 100 |
# File 'lib/warning_shot/dep_checker.rb', line 98 def DepChecker.has_binary?(app) %x{which #{app}}.match(/\bno/).nil? end |
Instance Method Details
#run ⇒ Object
- Name
-
run
- Access
-
private
- Description
-
Run dependency checker
- Last_Edited
-
Wed Dec 12 16:04:15 PST 2007
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 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 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/warning_shot/dep_checker.rb', line 132 def run start_time = Time.now tmp_errors = 0 @logger.heading @logger.heading "WarningShot (v. #{VERSION::INTERNAL}) - started @ #{start_time}" check_framework @logger.info("Environment: #{@options[:environment]}") @logger.info("Framework: #{@framework}") @logger.heading("Loading YAML files:") ConfigParser.run(self) @logger.heading("Preloading classes") class_loader("preload") @logger.heading("Checking class dependencies") tmp_errors = class_loader("classes") if tmp_errors > 0 @errors += tmp_errors @logger.error("#{tmp_errors} classes not found!") else @logger.notice("All class dependencies found.") end @logger.heading("Checking binary dependencies") tmp_errors = check_binaries if tmp_errors > 0 @errors += tmp_errors @logger.error("#{tmp_errors} binaries not found!") else @logger.notice("All binaries found.") end @logger.heading("Checking filesystem dependencies") tmp_errors = check_filesystem if tmp_errors > 0 @errors += tmp_errors @logger.error("#{tmp_errors} files/directories not found!") else @logger.notice("All files/directories found.") end @logger.heading("Checking URL dependencies") tmp_errors = check_urls if tmp_errors > 0 @errors += tmp_errors @logger.error("#{tmp_errors} sites unavailable!") else @logger.notice("All sites found.") end @logger.heading("Checking gem dependencies") #Initialize Gem Handler gem_handler = GemHandler.new(self.configs["gems"],{ :install_all => @options[:gems], :gem_path => @options[:gempath] }) tmp_errors = 0 gem_handler.each do |c_gem| if c_gem.status != :installed tmp_errors += 1 @logger.notice("#{c_gem.name} v. #{c_gem.version}:: #{c_gem.details}") else @logger.info("#{c_gem.name} v. #{c_gem.version} requirement met.") end end if tmp_errors > 0 @errors += tmp_errors @logger.error("#{tmp_errors} gems are missing!") else @logger.notice("All gems found.") end #Load the ruby scripts (not run yet) @logger.heading("Loading Ruby test scripts") tmp_errors = load_ruby_scripts if tmp_errors > 0 @errors += tmp_errors @logger.error("#{tmp_errors} scripts failed to load!") else @logger.notice("All scripts loaded successfully.") end #Run the ruby scripts @logger.heading("Running ruby tests scripts") tmp_errors = test_ruby_scripts if tmp_errors > 0 @errors += tmp_errors @logger.error("#{tmp_errors} ruby tests failed!") else @logger.notice("All ruby tests ran successfully.") end #@logger.heading("Running shell tests scripts") #tmp_errors = check_shell_scripts #if tmp_errors > 0 # @errors += tmp_errors # @logger.error("#{tmp_errors} shell tests failed!") #else # @logger.info("All shell tests ran successfully.") #end @logger.heading @logger.heading("RESULTS") @logger.info("Total Warnings: #{@warnings}") @logger.info("Total Errors: #{@errors}") @logger.info("Checked in #{Time.now.to_f-start_time.to_f}s") @logger.heading #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 @logger.close end |
#unload ⇒ Object
102 103 104 105 106 |
# File 'lib/warning_shot/dep_checker.rb', line 102 def unload ($" - @original_requires).each do |req| $".delete(req) end end |