Class: AdequateExposure::Exposure
- Inherits:
-
Object
- Object
- AdequateExposure::Exposure
- Defined in:
- lib/adequate_exposure/exposure.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.expose!(*args, **options, &block) ⇒ Object
Public: Initializes an Exposure and makes it accessible to a controller.
Instance Method Summary collapse
-
#expose! ⇒ Object
Public: Creates a getter and setter methods for the attribute.
-
#initialize(controller, name, fetch_block = nil, **options, &block) ⇒ Exposure
constructor
Public: Initalize an Exposure with a hash of options.
Constructor Details
#initialize(controller, name, fetch_block = nil, **options, &block) ⇒ Exposure
Public: Initalize an Exposure with a hash of options.
If a block is given, the Proc is assigned to value of options.
The ‘asserts_*` section raise errors if the controller was initialized with an unacceptable options Hash.
controller - The Controller class where methods will be exposed. name - The String name of the Exposure instance. fetch_block - Proc that will be executed if the exposed
attribute has no value (default: nil).
options - Hash of options for the Behavior of the exposed methods. block - If supplied, the exposed attribute method executes
the Proc.
Returns a normalized options Hash.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/adequate_exposure/exposure.rb', line 38 def initialize(controller, name, fetch_block=nil, **, &block) @controller = controller @options = .with_indifferent_access.merge(name: name) merge_lambda_option :fetch, fetch_block if fetch_block merge_lambda_option :fetch, block if block_given? assert_singleton_option :fetch assert_singleton_option :from :parent, :model :parent, :scope :find_by, :find end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
3 4 5 |
# File 'lib/adequate_exposure/exposure.rb', line 3 def controller @controller end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/adequate_exposure/exposure.rb', line 3 def @options end |
Class Method Details
.expose!(*args, **options, &block) ⇒ Object
Public: Initializes an Exposure and makes it accessible to a controller. For each Exposure, a getter and setter is defined. Those getters and setters are made available to the controller as helper methods.
*args - An Array of all parameters for the new Exposure. See
#initialize.
**args - A Hash of options. See #initialize. block - If supplied, the exposed attribute method executes
the Proc when called.
Returns a collection of exposed helper methods.
17 18 19 |
# File 'lib/adequate_exposure/exposure.rb', line 17 def self.expose!(*args, **, &block) new(*args, **, &block).expose! end |
Instance Method Details
#expose! ⇒ Object
Public: Creates a getter and setter methods for the attribute. Those methods are made avaiable to the controller as helper methods.
Returns a collection of exposed helper methods.
59 60 61 62 |
# File 'lib/adequate_exposure/exposure.rb', line 59 def expose! expose_attribute! expose_helper_methods! end |