Sha256: d001ce4caf3047a7cbf5a6691c181d2347d5a2159326f3f43d1bfc64e2a6e7b7
Contents?: true
Size: 886 Bytes
Versions: 43
Compression:
Stored size: 886 Bytes
Contents
module WithRandomizations extend ActiveSupport::Concern included do serialize :randomizations, Hash validate :ensure_randomizations_format end def seed @seed || 0 end def seed_with!(seed) @seed = seed end def randomizer #TODO remove this hack after removing seed state from here @randomizer ||= (Mumukit::Randomizer.parse(randomizations) rescue Mumukit::Randomizer.new([])) end private def ensure_randomizations_format errors.add :randomizations, :invalid_format unless Mumukit::Randomizer.valid? randomizations.to_h end module ClassMethods def randomize(*selectors) selectors.each { |selector| randomize_field selector } end private def randomize_field(selector) define_method(selector) do |*args| super(*args).randomize_with randomizer, seed end end end end
Version data entries
43 entries across 43 versions & 1 rubygems