class Reviser::Component
The abstract class Component Even though Ruby doesn't have abstract classes, we force inheriting classes to implement the run method that will be called during reviser's execution
@author Renan Strauss
Public Class Methods
new(data = nil)
click to toggle source
Don’t forget to call super in your component’s initializer ! This method is all about : it stores the data from another component accordingly to what you told to Reviser
, and creates a hash for child to easily access config file values
# File lib/reviser/component.rb, line 40 def initialize(data = nil) # # Deep copy to ensure everything goes well # (we DO NOT want to copy references) # @data = Marshal.load(Marshal.dump(data)) ext = options[:log_mode] log_file = File.join(options[:log_dir], "#{self.class.name.split('::').last}.#{ext}") # For now, we output to stderr if verbose option is not set # In the future, it would be a good idea to always have logs, # but to let the user change the level @logger = Loggers::Logger.new log_file end
Public Instance Methods
resource(path)
click to toggle source
Be kind to our childs and let them access ressources files easily
Note: you must store your component’s files int res/your_component/
@return The specified resource path
# File lib/reviser/component.rb, line 83 def resource path Cfg::resource File.join(self.class.name.split('::').last.underscore, path) end
run()
click to toggle source
Place-holder Just like an abstract method
# File lib/reviser/component.rb, line 58 def run raise NotImplementedError, 'All components must implement a run method' end
work()
click to toggle source
Method template So that when somebody implements a custom Component
, he doesn’t have to carry about logger being closed or not. Might be even more useful at some point
# File lib/reviser/component.rb, line 67 def work data = run @logger.close data end
Protected Instance Methods
options()
click to toggle source
@return all options for all components if they exist in config file.
# File lib/reviser/component.rb, line 91 def options Cfg[:options] end