Module: AdequateExposure::Controller::ClassMethods

Defined in:
lib/adequate_exposure/controller.rb

Instance Method Summary collapse

Instance Method Details

#expose(*args, **options, &block) ⇒ Object

Public: Exposes an attribute to a controller Class.

*args - An Array of attributes for the new exposure. See

Exposure#initialize for attribute details.

block - If supplied, the exposed attribute method executes

the Proc when accessed.

Returns the helper methods that are now defined on the class where this method is included.



20
21
22
# File 'lib/adequate_exposure/controller.rb', line 20

def expose(*args, **options, &block)
  Exposure.expose! self, *args, **options, &block
end

#expose!(name, *args, &block) ⇒ Object

Public: Exposes an attribute to a controller Class. The exposed methods are then set to a before_action callback.

name - The String name of the Exposure instance. *args - An Array of attributes for the new exposure. See

Exposure#initialize for attribute details.

block - If supplied, the exposed attribute method executes

the Proc when accessed.

Sets the exposed attribute to a before_action callback in the controller.



36
37
38
39
# File 'lib/adequate_exposure/controller.rb', line 36

def expose!(name, *args, &block)
  expose name, *args, &block
  before_action name
end

#exposure_config(name, options) ⇒ Object

Public: Configures an Exposure instance for a controller Class.

name - The String name of the Exposure instance. options - The Hash of options to configure the Exposure instance.

Returns the exposure configuration Hash.



47
48
49
50
# File 'lib/adequate_exposure/controller.rb', line 47

def exposure_config(name, options)
  store = self.exposure_configuration ||= {}
  self.exposure_configuration = store.merge(name => options)
end