Class: Changeset

Inherits:
Object
  • Object
show all
Includes:
Validators
Defined in:
lib/changeset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validators

#cast, #validate_acceptance, #validate_change, #validate_confirmation, #validate_exclusion, #validate_format, #validate_inclusion, #validate_length, #validate_number, #validate_required, #validate_subset

Constructor Details

#initialize(params) ⇒ Changeset

Returns a new instance of Changeset.



9
10
11
12
13
14
15
# File 'lib/changeset.rb', line 9

def initialize(params) 
  @changes = symbolized_keys(params)
  @errors = {}
  @changes.keys.each do |k|
    @errors[k] = {} 
  end
end

Instance Attribute Details

#changesObject (readonly)

Returns the value of attribute changes.



8
9
10
# File 'lib/changeset.rb', line 8

def changes
  @changes
end

#errorsObject (readonly)

Returns the value of attribute errors.



8
9
10
# File 'lib/changeset.rb', line 8

def errors
  @errors
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/changeset.rb', line 17

def valid? 
  @errors.values.all?(&:empty?)
end