Class: Config::ItemFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/module_config/itemfactory.rb

Constant Summary collapse

@@factories =
[]

Class Method Summary collapse

Class Method Details

.createObject

Raises:

  • (NotImplementedError)


45
46
47
# File 'lib/module_config/itemfactory.rb', line 45

def ItemFactory.create()
    raise NotImplementedError, "You have to implement create() in sublcasses inherited from Config::ItemFactory!"
end

.factoriesObject



14
15
16
# File 'lib/module_config/itemfactory.rb', line 14

def ItemFactory.factories()
    @@factories
end

.getItemFor(_str) ⇒ Object

Raises:



19
20
21
22
23
24
25
26
27
28
# File 'lib/module_config/itemfactory.rb', line 19

def ItemFactory.getItemFor(_str)
    @@factories.each do |subclass|
        match = subclass.match(_str)    # the matched string will be removed from _str by subclass.match()
        if !match.nil?
            return subclass.create(match)
        end
    end

    raise ConfigException.new(self.class), "There were some wrong entries in your configfile:\n -----\n #{_str.strip}\n -----" 
end

.inherited(_if) ⇒ Object



9
10
11
# File 'lib/module_config/itemfactory.rb', line 9

def ItemFactory.inherited(_if)
    @@factories.push(_if)
end

.load(_dir) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/module_config/itemfactory.rb', line 31

def ItemFactory.load(_dir)
    Dir.open(_dir).each do |file|
        if file =~ /[.]rb$/
            require _dir+"/"+file
        end
    end
    @@factories.sort! { |x,y| x.priority <=> y.priority }
end

.match(_str) ⇒ Object

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/module_config/itemfactory.rb', line 40

def ItemFactory.match(_str)
    raise NotImplementedError, "You have to implement match() in sublcasses inherited from Config::ItemFactory!"
end

.priorityObject



49
50
51
# File 'lib/module_config/itemfactory.rb', line 49

def ItemFactory.priority()
    0
end