Module: Exegesis::Registerable::ClassMethods
- Defined in:
- lib/exegesis/registerable.rb
Instance Method Summary collapse
- #build(*args) ⇒ Object
- #build_path(*args) ⇒ Object
- #clear_registry! ⇒ Object
- #create(*args) ⇒ Object
- #registry ⇒ Object
- #retrieve(*args) ⇒ Object
Instance Method Details
#build(*args) ⇒ Object
20 21 22 23 24 |
# File 'lib/exegesis/registerable.rb', line 20 def build(*args) new(*args).tap do |instance| registry.register! instance end end |
#build_path(*args) ⇒ Object
40 41 42 43 44 |
# File 'lib/exegesis/registerable.rb', line 40 def build_path(*args) parent, name = *args return parent if name.nil? File.join(parent.path, name) end |
#clear_registry! ⇒ Object
36 37 38 |
# File 'lib/exegesis/registerable.rb', line 36 def clear_registry! registry.clear! end |
#create(*args) ⇒ Object
11 12 13 |
# File 'lib/exegesis/registerable.rb', line 11 def create(*args) retrieve(*args) || build(*args) end |
#registry ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/exegesis/registerable.rb', line 26 def registry @flyweight ||= Flyweight.new do |dir| if dir.respond_to? :path dir.path else dir end end end |
#retrieve(*args) ⇒ Object
15 16 17 18 |
# File 'lib/exegesis/registerable.rb', line 15 def retrieve(*args) path = build_path(*args.take(2)) registry[path] if registry.has_key?(path) end |