Expand constructor arguments to instance variables base on splat
.
This was inspired by Gourmet Service Objects, but to use without Virtus.
class AcceptInvite
include Splatter::Init
splat :invite, :user
def call
@invite.accept!(@user)
UserMailer.invite_accepted(invite).deliver
end
end
AcceptInvite.new(invite, user).call
class AcceptInvite
include Splatter::Init
include Splatter::Service
splat :invite, :user
def call
@invite.accept!(@user)
UserMailer.invite_accepted(invite).deliver
end
end
AcceptInvite.call(invite, user)
Use include Splatter
to include both, Splatter::Init
and Splatter::Service
Add this line to your application's Gemfile:
gem 'splatter'
And then execute:
$ bundle
Or install it yourself as:
$ gem install splatter
- Fork it ( https://github.com/vroy/splatter/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request