Module: Cieloz::Helpers::InstanceMethods
- Defined in:
- lib/cieloz/helpers.rb
Instance Method Summary collapse
Instance Method Details
#add_error(attr, message) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cieloz/helpers.rb', line 32 def add_error(attr, ) = errors.add(attr, ).first if @source source_attr = @opts[attr] if source_attr.is_a?(Symbol) and @source.respond_to?(source_attr) @source.errors.add source_attr, else @source.errors.add :base, "#{attr}: #{error_message}" end end end |
#valid? ⇒ Boolean
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/cieloz/helpers.rb', line 44 def valid? valid = _valid? unless @source.nil? unless valid errors..each { |attr,attr_errors| source_attr = @opts[attr] if source_attr.is_a?(Symbol) and @source.respond_to?(source_attr) attr_errors.each {|e| @source.errors.add source_attr, e } else attr_errors.each {|e| @source.errors.add :base, "#{attr}: #{e}" if e.is_a? String } end @source.errors..each {|attr,attr_errors| attr_errors.uniq! } } end end valid end |