Module: Cline::Serializable::Dir::ClassMethods
- Defined in:
- lib/cline/serializable/dir.rb
Overview
Class methods that should be made accessible to any class including our mixin
Public API collapse
-
#open(dir, *args, create: false, **kwargs) ⇒ Object?
Instantiate an instance of the including class from a given directory.
Internal collapse
-
#new_instance(_dir, *args, **kwargs) ⇒ Object
Default factory for instances.
Instance Method Details
#new_instance(_dir, *args, **kwargs) ⇒ Object
Default factory for instances. This could be overriden by some classes that need to instantiate differently.
43 44 45 |
# File 'lib/cline/serializable/dir.rb', line 43 def new_instance(_dir, *args, **kwargs) new(*args, **kwargs) end |
#open(dir, *args, create: false, **kwargs) ⇒ Object?
Instantiate an instance of the including class from a given directory.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cline/serializable/dir.rb', line 23 def open(dir, *args, create: false, **kwargs) unless ::File.exist?(dir) && ::File.directory?(dir) return unless create FileUtils.mkdir_p dir end instance = new_instance(dir, *args, **kwargs) instance.initialize_from_dir(dir, create:) instance end |