README.md in attribeauty-0.3.4 vs README.md in attribeauty-0.4.0

- old
+ new

@@ -101,21 +101,22 @@ Attribeauty::Params.with(request.params) end def update_params params_filter.accept do - attribute :title, :string, allow_nil: false, required: true + attribute :title, :string, required: true attribute :email do - attribute :address, :string, allow_empty: false - attribute :valid, :boolean, allow_nil: false - attribute :ip_address, :string, allow_blank: true + attribute :address, :string + attribute :valid, :boolean + attribute :ip_address, :string, exclude_if: :empty? end end end ``` -If you have a "head" param, like in rails, you can exclude it like this: +If you have a "head" param, like in rails, you can exclude it, also note the `exclude_if` option, this will exclude the value completely, if it evaluates to true. +`exclude_if` will accept a single method call (`:nil?`) or an array (`[:nil?, :empty?]`) ``` class MyController def update MyRecord.update(update_params) @@ -124,11 +125,11 @@ end private # your params look like this: - # { user: { title: "woo", email: { address: "hmm@yep.com" } } } + # { user: { title: "woo", email: { address: "hmm@yep.com", ip_address: "" } } } # def params_filter Attribeauty::Params.with(request.params) end @@ -136,15 +137,15 @@ # { title: "woo", email: { address: "hmm@yep.com" } } # def update_params params_filter.accept do container :user do - attribute :title, :string, allow_nil: false, required: true + attribute :title, :string, required: true attribute :email do - attribute :address, :string, allow_empty: false - attribute :valid, :boolean, allow_nil: false - attribute :ip_address, :string, allow_blank: true + attribute :address, :string, exclude_if: [:empty?, :nil?] + attribute :valid, :boolean + attribute :ip_address, :string, exclude_if: :empty? end end end end end @@ -175,14 +176,14 @@ # will raise: Attribeauty::MissingAttributeError, "title required, email required" # def update_params params_filter.accept! do container :user do - attribute :title, :string, allow_nil: false, required: true + attribute :title, :string, exclude_if: :nil?, required: true attribute :email do - attribute :address, :string, allow_empty: false - attribute :valid, :boolean, allow_nil: false - attribute :ip_address, :string, allow_blank: true + attribute :address, :string + attribute :valid, :boolean + attribute :ip_address, :string end end end end end