Module: SweetLoader::ClassMethods

Included in:
SweetLoader
Defined in:
lib/sweetloader/class_methods.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_modeObject



49
50
51
# File 'lib/sweetloader/class_methods.rb', line 49

def default_mode
  valid_modes.first
end

Instance Method Details

#modeObject



33
34
35
# File 'lib/sweetloader/class_methods.rb', line 33

def mode
  @mode || default_mode
end

#mode=(mode) ⇒ Object



37
38
39
# File 'lib/sweetloader/class_methods.rb', line 37

def mode= mode 
  @mode = mode if valid_mode? mode
end

#namespacesObject



24
25
26
# File 'lib/sweetloader/class_methods.rb', line 24

def namespaces
  @namespaces ||= {}
end

#namespaces=(namespaces) ⇒ Object

Raises:

  • (ArgumentError)


28
29
30
31
# File 'lib/sweetloader/class_methods.rb', line 28

def namespaces= namespaces
  raise ArgumentError, "Must be a Hash, was: #{namespaces}" if !namespaces.kind_of?(Hash)
  @namespaces = namespaces
end

#rootObject



15
16
17
# File 'lib/sweetloader/class_methods.rb', line 15

def root
  @root ||= ''
end

#root=(root) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
# File 'lib/sweetloader/class_methods.rb', line 19

def root= root
  raise ArgumentError, "Must be a String, was: #{root}" if !root.kind_of?(String)
  @root = root
end

#translate(name, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/sweetloader/class_methods.rb', line 5

def translate name, options = {}    
  names = name.split('/')
  ns = namespaces.merge(options[:namespaces] || options[:ns] || {})
  names.map do |name|
    clazz_name = name.to_s.camelize
    folder = ns[clazz_name.to_sym] ? ns[clazz_name.to_sym] : name
    folder.sub /\/$/, ''
  end.join('/')
end

#valid_mode?(mode) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/sweetloader/class_methods.rb', line 41

def valid_mode? mode
  valid_modes.include? mode
end

#valid_modesObject



45
46
47
# File 'lib/sweetloader/class_methods.rb', line 45

def valid_modes
  [:autoload, :require]
end