Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

[ruby] plugin structure

plugin structure sorta thing. Use inherited to concatenate all plugins to a library in a Plugins constant in said library.

class Library
  Plugins = []
  
  def initialize#(...)
    Plugins.each do |plugin|
      # Here you can run a certain class method or grab some data from each class
    end
  end
  
  # ...
end


class LibraryPlugin
  # ...
  
  def self.inherited(sub); Library::Plugins << sub; end
end


class LibraryFooer < LibraryPlugin
  
end
class LibraryBarer < LibraryPlugin
  
end


Library::Plugins.inspect #=> [LibraryFooer, LibraryBarer]

Speeding up your acts_as_tokenized inserts

You might want to apply this diff to your token_generator plugin. Otherwise for saving identical models the minimum time taken is one per second. Not fun!


Index: vendor/plugins/token_generator/lib/token_generator.rb
===================================================================
--- vendor/plugins/token_generator/lib/token_generator.rb       (revision 1233)
+++ vendor/plugins/token_generator/lib/token_generator.rb       (working copy)
@@ -1,7 +1,7 @@
 module TokenGenerator
   def generate_token(size = 12, &validity)
     begin
-      token = Digest::MD5.hexdigest("#{inspect}#{Time.now}").first(size)
+      token = Digest::MD5.hexdigest("#{inspect}#{Time.now}#{rand}").first(size)
     end while !validity.call(token) if block_given?
     

Install DateBocks

Install engines plugin

./script/plugin source http://svn.rails-engines.org/plugins/
./script/plugin install engines


Install datebocks

./script/plugin source http://svn.toolbocks.com/plugins
./script/plugin install datebocks_engine
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS