Class: Rollbacker::ChangeValidator
- Inherits:
-
Object
- Object
- Rollbacker::ChangeValidator
- Defined in:
- lib/rollbacker/change_validator.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #changes(other_changes = {}) ⇒ Object
-
#initialize(action, options, model) ⇒ ChangeValidator
constructor
A new instance of ChangeValidator.
- #valid? ⇒ Boolean
Constructor Details
#initialize(action, options, model) ⇒ ChangeValidator
Returns a new instance of ChangeValidator.
6 7 8 9 10 |
# File 'lib/rollbacker/change_validator.rb', line 6 def initialize(action, , model) @action = action @options = @model = model end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
3 4 5 |
# File 'lib/rollbacker/change_validator.rb', line 3 def action @action end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/rollbacker/change_validator.rb', line 4 def @options end |
Instance Method Details
#changes(other_changes = {}) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/rollbacker/change_validator.rb', line 21 def changes(other_changes={}) chg = @model.changes.dup chg.reverse_merge!( (other_changes || {}).with_indifferent_access ) chg.reject!{|key, value| @options[:except].include?(key) } unless @options[:except].blank? chg.reject!{|key, value| !@options[:only].include?(key) } unless @options[:only].blank? chg end |
#valid? ⇒ Boolean
12 13 14 15 16 17 18 19 |
# File 'lib/rollbacker/change_validator.rb', line 12 def valid? case @action when :destroy @model.persisted? when :update, :create self.changes.any? end end |