Module: SimpleExposure::Core::ClassMethods

Defined in:
lib/simple_exposure/core.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(extension, *attributes, &block) ⇒ Object (private)



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/simple_exposure/core.rb', line 97

def method_missing(extension, *attributes, &block)
  extension_class = _exposure_extension_class(extension.to_s)
  if extension_class
    options = attributes.extract_options!

    extensions = options.fetch(:extend, nil)
    extensions = Array(extensions)
    extensions = extensions.prepend(extension)

    options = options.merge(extend: extensions)

    expose(*attributes, options, &block)
  end
rescue UnknownExtension
  super
end

Instance Method Details

#_exposure_extension_class(extension) ⇒ Object



49
50
51
52
53
# File 'lib/simple_exposure/core.rb', line 49

def _exposure_extension_class(extension)
  Extensions.const_get(extension.camelize)
rescue NameError
  raise UnknownExtension, "Unknown extension: #{extension}"
end

#_exposure_extensionsObject



45
46
47
# File 'lib/simple_exposure/core.rb', line 45

def _exposure_extensions
  @_exposure_extensions ||= HashWithIndifferentAccess.new([])
end

#expose(*attributes, &block) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/simple_exposure/core.rb', line 35

def expose(*attributes, &block)
  options = attributes.extract_options!

  extensions = options.fetch(:extend, nil)
  extensions = Array(extensions)

  _define_exposure_accessors(attributes, &block)
  _define_exposure_extensions(attributes, extensions)
end