0.0
No commit activity in last 3 years
No release in over 3 years
Sequent is an event sourcing framework for Ruby. This gem allows Sequent to work with Sinatra-backed applications.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 5.0, < 6.1
~> 2.5
~> 3.1
~> 2.0
 Project Readme

Sequent-Sinatra

Build Status Code Climate Test Coverage

Use the sequent gem with the Sinatra web framework.

Provides functionality to initialize sequent and form helpers to bind forms to Sequent::Core::Commands.

Getting started

gem install sequent-sinatra
class MyApp < Sinatra::Base
  register Sequent::Web::Sinatra::App
end

See the sample application for sequent-sinatra in action.

Documentation

Configuration

sequent_config_dir contains the location of initializers/sequent.rb file that is uses to initialize sequent. By default it will use the value root configured in your sinatra app.

Example

class MyApp < Sinatra::Base
  set :sequent_config_dir, "#{root}/config"
  register Sequent::Web::Sinatra::App
end

A minimal example of your initializers/sequent.rb

Sequent.configure do |config|
 config.event_handlers = [MyEventHandler.new]
 config.command_handlers = [MyCommandHandler.new]
end

Formhelpers

Sequent sinatra provides basic form helpers to bind forms to Commands.

Example:

Given this application

class MyApp < Sinatra::Base
  set :sequent_config_dir, "#{root}/config"
  register Sequent::Web::Sinatra::App
  get '/' do
    @command = SignupCommand.new
    erb :index
  end
  post '/' do
    @command = CreateInvoiceCommand.from_params(params[:signup_command])
    execute_command @command do |errors|
          if errors
            erb :index
          else
            redirect '/some-other-page'
          end
    end
  end
end
class SignupCommand < Sequent::Core::Command
  attrs username: String
  validates_presence_of :username
end

You can use the form helpers as follows

<% html_form_for(@command, "/", :post) do |form| %>
  <% form.fieldset(@command.class.to_s.underscore.to_sym) do |f| %>
    <%= f.raw_input :username, class: "form-input" %>
  <% end %>
  <input type="submit" value="Save">
<% end %>

This outputs to the following HTML

<form action="/" method="POST" role="form">
  <input type="hidden" name="_csrf" value="MAF4FQZPM4lssJnB7nyn4UlEssTAQnbVVsMRdfmLcmY=" />
  <input class="form-input" id="signup_command_username" name="signup_command[username]" type="text" />
  <input type="submit" value="Save">
</form>

Various for helpers exist

  • raw_input
  • raw_checkbox
  • raw_password
  • raw_textarea
  • raw_hidden
  • raw_select
  • raw_radio

You can provide the following parameters to these helper methods

  • class the css class
  • value default value of the field. This is used when the actual value is nil

Contributing

Fork and send pull requests

Running the specs

rspec

License

Sequent Sinatra is released under the MIT License