No commit activity in last 3 years
No release in over 3 years
DRY-up Rails controllers by leveraging interchangeable conductors to export data
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Development

~> 1.7
~> 10.0
>= 3.0.0, ~> 3.0

Runtime

>= 4.0.0, ~> 4.0
 Project Readme

Action Conductor

Build StatusCode Climate

DRY-up Rails Controllers with conductors

Installation

Add this line to your application's Gemfile:

gem 'action_conductor'

And then execute:

$ bundle

Usage

Define a Conductor in app/conductors

class PagesConductor < ActionConductor::Base

  # pass it a value directly
  export :page, "Hello World"

  # delegate to a block for compilation
  export :meta do
    "some computed value"
  end

  # optionally pass arguments from the computed action to the computed value
  export :foo do |args|
    "some computed value with arguments"
  end

  # blocks are executed in the context of the conductor instance, so...
  export :bar do
    bar_conductor
  end

  # ... delegates to ...
  def bar_conductor
  end
end

Bind it to a Rails Controller

class PagesController < ApplicationController
  conductor :pages
  # ...
end

Export computed values via exports

class PagesController < ApplicationController
  # ...
  def show
    @page = exports
  end
end

or export multiple computed values

class PagesController < ApplicationController
  # ...
  def show
    @page, @meta = exports # => exports in the established order
  end
end

explicitly declare which exports to export, and in which order

class PagesController < ApplicationController
  # ...
  def show
    @meta, @page = exports(:meta, :page)
  end
end

Pass arguments to the export block

class PagesController < ApplicationController
  # ...
  def show
    @address = exports(:address, "111 Main St.")
  end
end

class PagesConductor < ActionConductor::Base
  export :address do |street|
    "#{street} Medford, OR 97501"
  end
end

In case there is a competing exports method on the controller, you can access it through the conductor instance

class PagesController < ApplicationController
  # ...
  def show
    @foo = conductor.exports(:foo)
  end
end

Contributing

  1. Fork it ( https://github.com/[my-github-username]/conductor/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request