Sha256: 1b40fa3a710a3ed09d5e78c0dd5ee72ca754d6bb9d8e650c64ba02133074d6b3

Contents?: true

Size: 605 Bytes

Versions: 20

Compression:

Stored size: 605 Bytes

Contents

module WithRandomizations
  extend ActiveSupport::Concern

  included do
    serialize :randomizations, Hash
  end

  def seed
    @seed || 0
  end

  def seed_with!(seed)
    @seed = seed
  end

  def randomizer
    @randomizer ||= Mumukit::Randomizer.parse(randomizations)
  end

  module ClassMethods
    def randomize(*selectors)
      selectors.each { |selector| randomize_field selector }
    end

    private

    def randomize_field(selector)
      define_method(selector) do |*args|
        return unless super(*args)
        randomizer.randomize!(super(*args), seed)
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
mumuki-laboratory-5.13.0 app/models/concerns/with_randomizations.rb
mumuki-laboratory-5.12.1 app/models/concerns/with_randomizations.rb
mumuki-laboratory-5.12.0 app/models/concerns/with_randomizations.rb
mumuki-laboratory-5.11.0 app/models/concerns/with_randomizations.rb
mumuki-laboratory-5.10.4 app/models/concerns/with_randomizations.rb
mumuki-laboratory-5.10.3 app/models/concerns/with_randomizations.rb
mumuki-laboratory-5.10.2 app/models/concerns/with_randomizations.rb
mumuki-laboratory-5.10.1 app/models/concerns/with_randomizations.rb
mumuki-laboratory-5.10.0 app/models/concerns/with_randomizations.rb
mumuki-laboratory-5.9.1 app/models/concerns/with_randomizations.rb
mumuki-laboratory-5.9.0 app/models/concerns/with_randomizations.rb
mumuki-laboratory-5.8.3 app/models/concerns/with_randomizations.rb
mumuki-laboratory-5.8.1 app/models/concerns/with_randomizations.rb
mumuki-laboratory-5.8.0 app/models/concerns/with_randomizations.rb
mumuki-laboratory-5.7.0 app/models/concerns/with_randomizations.rb
mumuki-laboratory-5.6.3 app/models/concerns/with_randomizations.rb
mumuki-laboratory-5.6.2 app/models/concerns/with_randomizations.rb
mumuki-laboratory-5.6.1 app/models/concerns/with_randomizations.rb
mumuki-laboratory-5.6.0 app/models/concerns/with_randomizations.rb
mumukit-randomizer-0.1.0 lib/mumukit/randomizer/with_randomizations.rb