Method: Maintain::Backend.add

Defined in:
lib/maintain/backend.rb

.add(name, owner) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/maintain/backend.rb', line 6

def add(name, owner)
  classes[name.to_sym] = owner
  # Dig through the constant name to find if it exists
  modules = owner.split('::')
  if Object.const_defined?(modules.first) && owner = Object.const_get(modules.shift)
    while modules.length > 0
      owner = owner.const_get(modules.shift)
    end
    # If it exists, extend it with Maintain methods automatically
    owner.extend Maintain
  end
end