OptionsHash::MethodObject
A MethodObject with an OptionsHash built in
Installation
Add this line to your application's Gemfile:
gem 'options_hash-method_object'
And then execute:
$ bundle
Or install it yourself as:
$ gem install options_hash-method_object
Usage
class CreatePerson < OptionsHash::MethodObject
required :name
optional :favorite_color, default: ->{ 'blue' }
def call
build_person!
validate_person!
create_person!
@person
end
def build_person!
@person = Person.new(.to_hash)
end
def validate_person!
@person.valid? or raise 'invalid person'
end
def create_person!
@person.save!
end
end
For details about the require
and optional
methods see OptionsHash
Contributing
- Fork it
- 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 new Pull Request