Class: MVCLI::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/mvcli/loader.rb

Defined Under Namespace

Classes: RubyClassLoader

Instance Method Summary collapse

Constructor Details

#initialize(extensions = {}) ⇒ Loader



6
7
8
9
# File 'lib/mvcli/loader.rb', line 6

def initialize(extensions = {})
  @extensions = Map extensions
  @default_handler = RubyClassLoader.new
end

Instance Method Details

#exists?(path, extension_type, name) ⇒ Boolean



15
16
17
18
# File 'lib/mvcli/loader.rb', line 15

def exists?(path, extension_type, name)
  pathname = handler(extension_type).to_path name, extension_type
  path.exists? pathname
end

#load(type, name, *args, &block) ⇒ Object



11
12
13
# File 'lib/mvcli/loader.rb', line 11

def load(type, name, *args, &block)
  constantize(camelize("#{name}_#{type}")).new(*args, &block)
end

#read(path, extension_type, name, namespace = Object) ⇒ Object



20
21
22
23
24
# File 'lib/mvcli/loader.rb', line 20

def read(path, extension_type, name, namespace = Object)
  pathname = handler(extension_type).to_path name, extension_type
  bytes = path.read pathname
  handler(extension_type).define name, bytes, extension_type, namespace
end