Module: DryEraser::ModelExtensions

Extended by:
ActiveSupport::Concern
Defined in:
lib/dry_eraser.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#check_dry_erasersObject



48
49
50
# File 'lib/dry_eraser.rb', line 48

def check_dry_erasers
  throw(:abort) unless dry_erasable?
end

#dry_erasable?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dry_eraser.rb', line 27

def dry_erasable?
  errors.clear

  self.class.dry_erasers.each do |dry_eraser|
    case dry_eraser
    in Class
      dry_eraser.new.dry_erase(self)
    in ->(it) { it.respond_to?(:dry_erase) }
      dry_eraser.dry_erase(self)
    in ->(it) { it.respond_to?(:call) }
      dry_eraser.call(self)
    in Symbol | String
      send(dry_eraser)
    else
      raise ArgumentError, "Invalid dry eraser: #{dry_eraser.inspect}"
    end
  end

  errors.empty?
end