The project is in a healthy, maintained state
`expose :foo` defines an attr_reader and helper_method. `expose :foo, -> { ... }` (or with a block) defines a memoized reader. Replaces the boilerplate of attr_reader + helper_method + def.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 0
~> 3.0

Runtime

 Project Readme

action_controller-expose

Declarative helper-accessible readers (with optional lazy memoization) for ActionController.

Usage

class CommentsController < ApplicationController
  # Multiple attr_reader + helper_method declarations.
  # Controller actions assign @foo / @bar; views read `foo` / `bar`.
  expose :foo, :bar

  # Lazy memoized reader. First call runs the block, later calls return cached
  # result. Memoization via `instance_variable_defined?`, so nil/false cache.
  expose :comment,  -> { Comment.find(params[:id]) }
  expose :audition, -> { Audition.medium_ids_including(comment.medium_id).first }
  expose :shoot,    -> { audition.shoots.first }

  # Or with a block:
  expose(:current_thing) { Thing.find(params[:thing_id]) }
end

All forms call helper_method, so the views can call the names without @.

Installation

gem "action_controller-expose"

License

MIT