Class: Doem::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/doem/registry.rb

Overview

common registry

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



11
12
13
# File 'lib/doem/registry.rb', line 11

def initialize
  @items = []
end

Instance Method Details

#<<(val) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/doem/registry.rb', line 19

def <<(val)
  klass = val[:klass]
  block = val[:block]
  if klass
    fail "#{klass.name} needs to implement methods: "\
      "#{mandatory_methods}" unless valid? klass
    @items << val[:klass].new(*val[:args])
  elsif block
    @items << CompatiableProc.new(&block)
  else
    fail 'registry error'
  end
end

#eachObject



39
40
41
42
43
# File 'lib/doem/registry.rb', line 39

def each
  @items.each do |item|
    yield item
  end
end

#mandatory_methodsObject



15
16
17
# File 'lib/doem/registry.rb', line 15

def mandatory_methods
  []
end

#valid?(klass) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/doem/registry.rb', line 33

def valid?(klass)
  mandatory_methods.all? do |m|
    klass.method_defined? m
  end
end