Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flash #56

Merged
merged 3 commits into from
Dec 4, 2014
Merged

Flash #56

merged 3 commits into from
Dec 4, 2014

Conversation

jodosha
Copy link
Member

@jodosha jodosha commented Dec 3, 2014

Private mechanism to send data across requests.

Use case

require 'lotus/controller'

module Comments
  class Index
    include Lotus::Action
    include Lotus::Action::Session

    expose :comments

    def call(params)
      @comments = CommentRepository.all
    end
  end

  class Create
    include Lotus::Action
    include Lotus::Action::Session

    params do
      param :text, type: String, presence: true
    end

    def call(params)
      comment = Comment.new(params)
      CommentRepository.create(comment) if params.valid?

      redirect_to '/comments'
    end
  end
end

The validation errors caused by Comments::Create are available after the redirect in the context of Comments::Index.

Technical details

  • It uses unique request ID to store the data that we set
  • It's aware of the current request ID
  • When finalized (at the end of the request), it removes all the data that doesn't belong to the current request
  • If after the finalization, there is no data left, it removes the flash entirely from the session.
  • It introduces Lotus::Action::Glue which was written initially for testing purposes, but then I decided to introduce it in favor of the monkey patching that we do in Lotus.
  • This isn't a complete solution that we want to expose to developers, but at least it helps with the use case described.

Again, this is marked as private API.

Closes #10

@jodosha jodosha self-assigned this Dec 3, 2014
@jodosha jodosha added this to the v0.3.0 milestone Dec 3, 2014
@coveralls
Copy link

Coverage Status

Coverage increased (+0.13%) when pulling 5322d63 on flash into 257459e on master.

jodosha added a commit that referenced this pull request Dec 4, 2014
@jodosha jodosha merged commit 8cc53a6 into master Dec 4, 2014
@jodosha jodosha deleted the flash branch December 4, 2014 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants