Module: Congo::Scoper::InstanceMethods

Defined in:
lib/congo/scoper.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object (private)



68
69
70
71
72
73
74
75
76
# File 'lib/congo/scoper.rb', line 68

def method_missing(method, *args)
  if ctype = content_type_as_const(method.to_s.classify, method.to_s)
    meta = proxy_scoper? ? scoper_instance.metaclass : metaclass
    meta.many method, :class => ctype
    (proxy_scoper? ? scoper_instance : self).send(method, *args)
  else
    super
  end        
end

Instance Method Details

#constsObject



47
48
49
# File 'lib/congo/scoper.rb', line 47

def consts
  @consts ||= {}
end

#content_type_as_const(name, method_name = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/congo/scoper.rb', line 51

def content_type_as_const(name, method_name = nil)
  return nil if (Congo::Types.const_defined?(name) rescue nil).nil?
  return Congo::Types.const_get(name) if Congo::Types.const_defined?(name)
  return name.constantize if Object.const_defined?(name)
  
  unless consts[name]
    if (type = content_types.find_by_name(name)).nil?
      type = content_types.find_by_slug(method_name) if method_name
    end
    consts[name] = type.to_const rescue nil # This doesn't work because of different instances being used
  end
  
  consts[name]
end

#proxy_scoper?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/congo/scoper.rb', line 43

def proxy_scoper?
  !scoper_instance.nil?
end