Class: Reviser::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/reviser/component.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(data = nil) ⇒ Component

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



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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

Instance Method Details

#resource(path) ⇒ Object

Be kind to our childs and let them access ressources files easily

Note: you must store your component's files int res/your_component/

Returns:

  • The specified resource path



83
84
85
# File 'lib/reviser/component.rb', line 83

def resource path
	Cfg::resource File.join(self.class.name.split('::').last.underscore, path)
end

#runObject

Place-holder Just like an abstract method

Raises:

  • (NotImplementedError)


58
59
60
# File 'lib/reviser/component.rb', line 58

def run
	raise NotImplementedError, 'All components must implement a run method'
end

#workObject

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



67
68
69
70
71
72
# File 'lib/reviser/component.rb', line 67

def work
	data = run
	@logger.close

	data
end