Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding rails support.

  • Loading branch information...
commit ad32076e33a6f6954456ddd4f98ae5527f3c799b 1 parent 7ab4969
@nate nate authored
View
6 generators/forgery/USAGE
@@ -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.
View
12 generators/forgery/forgery_generator.rb
@@ -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
27 lib/forgery.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.