acts_as_parameter_object
testing ruby: 1.9.3, 2.0.0
About acts_as_parameter_object
ActsAsParameterObject creates a model which acts as a Parameter Object. cf. Refactoring: Ruby Edition.
Example
class ParameterObjectExample
include ActsAsParameterObject
attr_accessor :title
validates_presence_of :title
def initialize(params = {})
@title = params[:title]
end
end
ParameterObjectExample.new(:foo => 'bar').valid? #=> false
You can use all of ActiveModel::Validations methods.
I use a parameter object as a validator model for params coming from rails controller. In contrast to ActiveRecord, this model does not access to the database.
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
Copyright
Copyright (c) 2013 Naotoshi SEO. See LICENSE for details.