Module: Registerable::ClassMethods

Defined in:
lib/exegesis/registerable.rb

Instance Method Summary collapse

Instance Method Details

#build(*args) ⇒ Object



19
20
21
22
23
# File 'lib/exegesis/registerable.rb', line 19

def build(*args)
  new(*args).tap do |instance|
    registry.register! instance
  end
end

#build_path(*args) ⇒ Object



39
40
41
42
43
# File 'lib/exegesis/registerable.rb', line 39

def build_path(*args)
  parent, name = *args
  return parent if name.nil?
  File.join(parent.path, name)
end

#clear_registry!Object



35
36
37
# File 'lib/exegesis/registerable.rb', line 35

def clear_registry!
  registry.clear!
end

#create(*args) ⇒ Object



10
11
12
# File 'lib/exegesis/registerable.rb', line 10

def create(*args)
  retrieve(*args) || build(*args)
end

#registryObject



25
26
27
28
29
30
31
32
33
# File 'lib/exegesis/registerable.rb', line 25

def registry
  @flyweight ||= Flyweight.new do |dir|
    if dir.respond_to? :path
      dir.path
    else
      dir
    end
  end
end

#retrieve(*args) ⇒ Object



14
15
16
17
# File 'lib/exegesis/registerable.rb', line 14

def retrieve(*args)
  path = build_path(*args.take(2))
  registry[path] if registry.has_key?(path)
end