Sha256: 899eed98ac912c016b299fe4c2ed4fa8bf121c84e1837fc58c56e2c246476358

Contents?: true

Size: 974 Bytes

Versions: 5

Compression:

Stored size: 974 Bytes

Contents

module Generator
  
  def self.included base
    base.extend ClassMethods
  end
  
  module ClassMethods
    
    def generates klass, options = {}
      self.send :include, InstanceMethods
      
      rate   = options[:every]
      til    = options[:until] || 100
      offset = options[:starting_at] || 1
      
      InitializerHooks.register self do
        start_generating klass, rate, til, offset
      end
      
    end
    
  end
  
  module InstanceMethods
    
    def start_generating klass, every_rate, til, offset
      return if til <= 0
      threaded offset, &generation(klass, every_rate, til)
    end
    
    def generation klass, every_rate, til
      lambda do
        self.generate klass
        self.start_generating klass, every_rate, til - every_rate, every_rate
      end
    end
    
    def generate klass
      generated = klass.new self.window
      generated.warp self.position
      self.window.register generated
    end
    
  end
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gosu_extensions-0.1.4 lib/traits/generator.rb
gosu_extensions-0.1.3 lib/traits/generator.rb
gosu_extensions-0.1.2 lib/traits/generator.rb
gosu_extensions-0.1.1 lib/traits/generator.rb
gosu_extensions-0.1.0 lib/traits/generator.rb