Permalink
Browse files

Adding rails support.

  • Loading branch information...
1 parent 7ab4969 commit ad32076e33a6f6954456ddd4f98ae5527f3c799b @nate nate committed Apr 4, 2008
Showing with 52 additions and 5 deletions.
  1. +6 −0 generators/forgery/USAGE
  2. +12 −0 generators/forgery/forgery_generator.rb
  3. +11 −1 init.rb
  4. +23 −4 lib/forgery.rb
View
@@ -0,0 +1,6 @@
+
+./script/generate forgery
+
+Creates the Forgery directories in RAILS_ROOT/lib. The contents of these
+directories can be used to extend Forgery, adding new forgeries and overriding
+dictionaries and formats.
@@ -0,0 +1,12 @@
+class ForgeryGenerator < Rails::Generator::Base
+ def manifest
+ record do |m|
+ m.directory 'lib'
+ m.directory 'lib/forgery'
+ m.directory 'lib/forgery/dictionaries'
+ m.directory 'lib/forgery/extensions'
+ m.directory 'lib/forgery/forgeries'
+ m.directory 'lib/forgery/formats'
+ end
+ end
+end
View
12 init.rb
@@ -1 +1,11 @@
-require File.dirname(__FILE__) + '/lib/forgery'
+require File.dirname(__FILE__) + '/lib/forgery'
+
+Dir[File.expand_path(File.dirname(__FILE__) + '/lib/**/*.rb')].uniq.each do |file|
+ require file
+end
+
+if defined?(RAILS_ROOT)
+ Dir[File.expand_path(RAILS_ROOT + '/lib/forgery/**/*.rb')].uniq.each do |file|
+ require file
+ end
+end
View
@@ -30,15 +30,34 @@ def self.read_format(format)
end
def self.path_to_format(format)
+ if external_path_to_format(format) && File.exists?(external_path_to_format(format))
+ external_path_to_format(format)
+ else
+ internal_path_to_format(format)
+ end
+ end
+
+ def self.external_path_to_format(format)
+ RAILS_ROOT + '/lib/forgery/formats/' + format.to_s if defined?(RAILS_ROOT)
+ end
+
+ def self.internal_path_to_format(format)
File.dirname(__FILE__) + '/formats/' + format.to_s
end
def self.path_to_dictionary(dictionary)
- File.dirname(__FILE__) + '/dictionaries/' + dictionary.to_s
+ if external_path_to_dictionary(dictionary) && File.exists?(external_path_to_dictionary(dictionary))
+ external_path_to_dictionary(dictionary)
+ else
+ internal_path_to_dictionary(dictionary)
+ end
end
-end
+ def self.external_path_to_dictionary(dictionary)
+ RAILS_ROOT + '/lib/forgery/dictionaries/' + dictionary.to_s if defined?(RAILS_ROOT)
+ end
-Dir[File.expand_path(File.dirname(__FILE__) + '/**/*.rb')].uniq.each do |file|
- require file
+ def self.internal_path_to_dictionary(dictionary)
+ File.dirname(__FILE__) + '/dictionaries/' + dictionary.to_s
+ end
end

0 comments on commit ad32076

Please sign in to comment.