Module: WarningShot::Resolver::ClassMethods Private
- Defined in:
- lib/warningshot/resolver.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
-
#add_dependency(type, req_name, dep_opts = {}) ⇒ Object
private
creates a list of gems that the resolver is dependent on for different features The goal of this is that WarningShot will not need a bunch of libraries installed unless the end users needs that specific functionality.
-
#after(type, &block) ⇒ Object
add after filters to test/resolution blocks.
-
#after_filters(type) ⇒ Array[Proc]
private
gets after filters for type.
-
#before(type, &block) ⇒ Object
add before filters to test/resolution blocks.
-
#before_filters(type) ⇒ Array[Proc]
private
gets before filters for type.
-
#branch(b = nil) ⇒ String
Setter/Getter for resolver branch, used in outputting info and for determine which yaml to apply.
-
#cli(*opts, &block) ⇒ Object
provides shortcut to WarningShot::Config.cli.
-
#depends_on ⇒ Hash
private
list the gems the resolver relies on.
-
#description(d = nil) ⇒ String
Setter/Getter for resolver description, .
-
#details ⇒ Array(Object)
private
Outputs class static details.
-
#disable! ⇒ Object
Sets a resolver to disabled mode, won’t be processed.
-
#disabled? ⇒ Boolean
Determines if resolver is disabled.
-
#enable! ⇒ Object
enables a resolver (enabled by default).
-
#flush! ⇒ Object
removes all test/resolutions from a resolver.
-
#flush_resolutions! ⇒ Object
Removes all resolutions from a resolver.
-
#flush_tests! ⇒ Object
Removes all tests from a resolver.
-
#logger ⇒ ~Logger
Provides resolver access to logger.
-
#logger=(log) ⇒ Object
private
Sets.
-
#options ⇒ Hash
private
provides shortcut to WarningShot::Config.cli_options.
-
#order(p = nil) ⇒ Fixnum
Setter/Getter for resolver order, determines order in which resolver is checked.
-
#register(type, meta = {}, &block) ⇒ Object
register :resolution do |dependency| #Access to current dependency via dependency my_method_that_would_resolve dependency end.
-
#resolutions(resolution_name = nil) ⇒ Object
private
Lists current resolver resolutions.
-
#tests(test_name = nil) ⇒ Hash|Array
private
Lists current resolver tests.
-
#typecast(klass = nil, &block) ⇒ Object
Defines how to cast YAML parsed data to an object the resolver can work with.
-
#yaml_to_object(data) ⇒ Object
private
calls the block defined by Resolver#typecast to convert the yaml data to an object.
Instance Method Details
#add_dependency(type, req_name, dep_opts = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
creates a list of gems that the resolver is dependent on for different features
The goal of this is that WarningShot will not need a bunch of libraries installed unless
the end users needs that specific functionality. If a corelib/gem is missing the logger will
receive warnings if a particular functionality that needs that library is enabled and its missing
The missing GEMS can be installed with: warningshot --build-deps
All resolvers' dependencies can be viewed with: warningshot --list-deps
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/warningshot/resolver.rb', line 42 def add_dependency(type,req_name,dep_opts={}) require req_name dep_opts[:installed] = true rescue LoadError => ex self.disable! unless dep_opts[:disable] === false dep_opts[:installed] = false ensure @dependent_libs ||= {:core => [], :gem => []} #if an alternate name isn't specified refer to it by the req_name dep_opts[:name] ||= req_name @dependent_libs[type].push dep_opts end |
#after(type, &block) ⇒ Object
add after filters to test/resolution blocks
420 421 422 423 |
# File 'lib/warningshot/resolver.rb', line 420 def after(type,&block) @after_filters ||= {:test=>[],:resolution=>[]} @after_filters[type] << block end |
#after_filters(type) ⇒ Array[Proc]
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
gets after filters for type
408 409 410 |
# File 'lib/warningshot/resolver.rb', line 408 def after_filters(type) @after_filters ? @after_filters[type] : [] end |
#before(type, &block) ⇒ Object
add before filters to test/resolution blocks
385 386 387 388 |
# File 'lib/warningshot/resolver.rb', line 385 def before(type,&block) @before_filters ||= {:test=>[],:resolution=>[]} @before_filters[type] << block end |
#before_filters(type) ⇒ Array[Proc]
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
gets before filters for type
397 398 399 |
# File 'lib/warningshot/resolver.rb', line 397 def before_filters(type) @before_filters ? @before_filters[type] : [] end |
#branch(b = nil) ⇒ String
Setter/Getter for resolver branch, used in outputting info and for determine which yaml to apply
105 106 107 108 |
# File 'lib/warningshot/resolver.rb', line 105 def branch(b=nil) @branch = b unless b.nil? @branch end |
#cli(*opts, &block) ⇒ Object
provides shortcut to WarningShot::Config.cli
83 84 85 86 87 |
# File 'lib/warningshot/resolver.rb', line 83 def cli(*opts,&block) return if self.disabled? WarningShot::Config.cli(*opts, &block) end |
#depends_on ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
list the gems the resolver relies on
59 60 61 |
# File 'lib/warningshot/resolver.rb', line 59 def depends_on @dependent_libs ||= {:core => [], :gem => []} end |
#description(d = nil) ⇒ String
Setter/Getter for resolver description,
Resolver’s description
125 126 127 128 |
# File 'lib/warningshot/resolver.rb', line 125 def description(d=nil) @description = d unless d.nil? @description end |
#details ⇒ Array(Object)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Outputs class static details
429 430 431 |
# File 'lib/warningshot/resolver.rb', line 429 def details [self.name,self.description,self.order,self.disabled?] end |
#disable! ⇒ Object
Sets a resolver to disabled mode, won’t be processed
161 162 163 |
# File 'lib/warningshot/resolver.rb', line 161 def disable! @disabled = true end |
#disabled? ⇒ Boolean
Determines if resolver is disabled
188 189 190 |
# File 'lib/warningshot/resolver.rb', line 188 def disabled? @disabled ||=false end |
#enable! ⇒ Object
enables a resolver (enabled by default)
178 179 180 |
# File 'lib/warningshot/resolver.rb', line 178 def enable! @disabled = false end |
#flush! ⇒ Object
removes all test/resolutions from a resolver
358 359 360 361 |
# File 'lib/warningshot/resolver.rb', line 358 def flush! flush_tests! flush_resolutions! end |
#flush_resolutions! ⇒ Object
Removes all resolutions from a resolver
373 374 375 |
# File 'lib/warningshot/resolver.rb', line 373 def flush_resolutions! @registered_blocks[:resolution] = [] end |
#flush_tests! ⇒ Object
Removes all tests from a resolver
366 367 368 |
# File 'lib/warningshot/resolver.rb', line 366 def flush_tests! @registered_blocks[:test] = [] end |
#logger ⇒ ~Logger
Provides resolver access to logger
198 199 200 |
# File 'lib/warningshot/resolver.rb', line 198 def logger @logger || Logger.new(STDOUT) end |
#logger=(log) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sets
203 204 205 |
# File 'lib/warningshot/resolver.rb', line 203 def logger=(log) @logger = log end |
#options ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
provides shortcut to WarningShot::Config.cli_options
69 70 71 |
# File 'lib/warningshot/resolver.rb', line 69 def WarningShot::Config. end |
#order(p = nil) ⇒ Fixnum
Setter/Getter for resolver order, determines order in which resolver is checked
147 148 149 150 |
# File 'lib/warningshot/resolver.rb', line 147 def order(p=nil) @order = p unless p.nil? @order || 100 end |
#register(type, meta = {}, &block) ⇒ Object
register :resolution do |dependency|
#Access to current dependency via dependency
my_method_that_would_resolve dependency
end
register :resolution, :if => lambda{|dependency|
#This will determin if resolution should be attempted
my_special_instance == true
} do |dependency|
my_method_that_would_resolve dependency
end
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/warningshot/resolver.rb', line 300 def register(type, ={}, &block) if [:if] && [:unless] raise Exception, ":if and :unless cannot be specified on the same resolution" end @registered_blocks ||= {:test => [], :resolution => []} [type] = block # If a condition is given add to begining of array, if no condition # add it to end. This makes it so we dont have to sort later on :if|:unless # to get non-condition resolutions to run last if [:if] || [:unless] @registered_blocks[type].unshift else @registered_blocks[type] << end end |
#resolutions(resolution_name = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Lists current resolver resolutions
345 346 347 348 349 350 351 352 353 |
# File 'lib/warningshot/resolver.rb', line 345 def resolutions(resolution_name=nil) unless resolution_name @registered_blocks[:resolution] ||= [] else return @registered_blocks[:resolution].find do |registered_resolution| registered_resolution[:name] == resolution_name end end end |
#tests(test_name = nil) ⇒ Hash|Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Lists current resolver tests
329 330 331 332 333 334 335 336 337 |
# File 'lib/warningshot/resolver.rb', line 329 def tests(test_name=nil) unless test_name @registered_blocks[:test] ||= [] else return @registered_blocks[:test].find do |registered_test| registered_test[:name] == test_name end end end |
#typecast(klass = nil, &block) ⇒ Object
Defines how to cast YAML parsed data to an object
the resolver can work with
218 219 220 221 222 223 224 225 |
# File 'lib/warningshot/resolver.rb', line 218 def typecast(klass=nil,&block) if klass.nil? klass = :default else klass = klass.name.to_sym end (@yaml_to_object_methods||={})[klass] = block end |
#yaml_to_object(data) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
calls the block defined by Resolver#typecast to convert
the yaml data to an object
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/warningshot/resolver.rb', line 241 def yaml_to_object(data) @yaml_to_object_methods||={} klass = data.class.name.to_sym # if klass has a registered casting method, do it if @yaml_to_object_methods.key? klass return @yaml_to_object_methods[klass].call(data) # elsif there is a regsitered default method, do it. elsif @yaml_to_object_methods.key? :default return @yaml_to_object_methods[:default].call(data) else # else return original data return data end end |