Class: Reviser::Component

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

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
# File 'lib/reviser/component.rb', line 40

def initialize(data = nil)
  @data = 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(options[:verbose] && log_file || STDERR)
end

Instance Method Details

#resource(path) ⇒ Object

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

TODO : put resources in dedicated folders for each component or extension, so that the user can omit // when calling this method

Returns:

  • The specified resource path



80
81
82
# File 'lib/reviser/component.rb', line 80

def resource path
  Cfg::resource path
end

#runObject

Place-holder Just like an abstract method

Raises:

  • (NotImplementedError)


54
55
56
# File 'lib/reviser/component.rb', line 54

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



63
64
65
66
67
68
# File 'lib/reviser/component.rb', line 63

def work
  data = run
  @logger.close

  data
end