Sha256: 94306c8b3ae5a632da5c45fb4e4188b1c713f1001c7e122ab579c6c7c4585ef6

Contents?: true

Size: 594 Bytes

Versions: 8

Compression:

Stored size: 594 Bytes

Contents

# frozen_string_literal: true

class ActWithFlags::Admin
  attr_reader :clears

  def clear_at_save(*flags)
    flags.each { |name| add_to_clear_mask(name) }
    clears.each { |orig, mask|
      before_save(orig, mask)
    }
    @clears = {}
  end

  private

  def add_to_clear_mask(name)
    _model, orig, _pos = location(name).values
    mask = @clears[orig] || 0
    mask |= 1 << position(name)
    @clears[orig] = mask
  end

  def before_save(orig, mask)
    model.class_eval %(
      before_save do |row|
        row.#{orig} &= ~#{mask}
      end
    ), __FILE__, __LINE__ - 4
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
act_with_flags-3.1.9 lib/act_with_flags/clear.rb
act_with_flags-3.1.6 lib/act_with_flags/clear.rb
act_with_flags-3.1.5 lib/act_with_flags/clear.rb
act_with_flags-3.1.3 lib/act_with_flags/clear.rb
act_with_flags-3.1.2 lib/act_with_flags/clear.rb
act_with_flags-3.1.1 lib/act_with_flags/clear.rb
act_with_flags-3.1.0 lib/act_with_flags/clear.rb
act_with_flags-3.0.1 lib/act_with_flags/clear.rb