Class: Cheri::Builder::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/cheri/builder/config.rb

Constant Summary collapse

None =

:nodoc:

{}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(*mods) ⇒ Config

Returns a new instance of Config.



30
31
32
33
34
35
36
37
# File 'lib/cheri/builder/config.rb', line 30

def initialize(*mods)
  @m = [] # included modules
  @f = {} # factories, indexed by module
  @c = {} # connecters, indexed by module
  @n = {} # consumers, indexed by module
  # @r = {} # resolvers, indexed by module
  mods.each do |mod| self << mod; end
end

Instance Method Details

#<<(mod) ⇒ Object Also known as: add

Raises:

  • (BuilderException)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/cheri/builder/config.rb', line 61

def <<(mod)
  return if @m.include?(mod)
  validate(mod) unless mod == Cheri::Builder
  extendee = mod.respond_to?(:extends) ? mod.extends : nil
  raise BuilderException,"extended builder module not included: #{extendee}" if extendee && !@m.include?(extendee)
  @m << mod

  if mod.respond_to?(:factory) && (obj = mod.factory)
    @f[mod] = obj
  end
  
  if mod.respond_to?(:connecter) && (obj = mod.connecter)
    @c[mod] = obj
  end

  if mod.respond_to?(:consumer) && (obj = mod.consumer)
    @n[mod] = obj
  end
  
  # FIXME: eliminate (isolate in Java class stuff)
  (@r ||= {})[mod] = mod.resolver if mod.respond_to?(:resolver) && mod.resolver


  extend_mod(extendee,mod) if extendee
  self
end

#connectersObject



47
48
49
# File 'lib/cheri/builder/config.rb', line 47

def connecters
  @c
end

#consumersObject



51
52
53
# File 'lib/cheri/builder/config.rb', line 51

def consumers
  @n
end

#copyObject



229
230
231
# File 'lib/cheri/builder/config.rb', line 229

def copy
  self.class.allocate.copy_from(@m,@f,@c,@n,@r)
end

#eachObject



225
226
227
# File 'lib/cheri/builder/config.rb', line 225

def each
  @m.each_key {|m| yield m } if block_given?
end

#factoriesObject



43
44
45
# File 'lib/cheri/builder/config.rb', line 43

def factories
  @f
end

#include?(mod) ⇒ Boolean

Returns:

  • (Boolean)


221
222
223
# File 'lib/cheri/builder/config.rb', line 221

def include?(mod)
  @m.include?(mod)
end

#inspectObject

Overrides the default Object#inspect to prevent mind-boggling circular displays in IRB.



234
235
236
# File 'lib/cheri/builder/config.rb', line 234

def inspect
  to_s
end

#modsObject



39
40
41
# File 'lib/cheri/builder/config.rb', line 39

def mods
  @m
end

#resolversObject

FIXME: eliminate!



57
58
59
# File 'lib/cheri/builder/config.rb', line 57

def resolvers
  @r || None
end