forgery 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +1 -0
- data/lib/forgery/file_reader.rb +8 -41
- data/lib/forgery/forgery.rb +9 -0
- data/lib/forgery/version.rb +1 -1
- data/lib/forgery.rb +1 -5
- metadata +2 -2
data/README.markdown
CHANGED
data/lib/forgery/file_reader.rb
CHANGED
@@ -4,12 +4,12 @@ class Forgery
|
|
4
4
|
|
5
5
|
# Returns an array of strings containing each line in the dictionary
|
6
6
|
def self.read_dictionary(dictionary)
|
7
|
-
read_file(
|
7
|
+
read_file(find_file(dictionary, :dictionaries))
|
8
8
|
end
|
9
9
|
|
10
10
|
# Returns an array of strings containing each line in the format
|
11
11
|
def self.read_format(format)
|
12
|
-
read_file(
|
12
|
+
read_file(find_file(format, :formats))
|
13
13
|
end
|
14
14
|
|
15
15
|
protected
|
@@ -24,46 +24,13 @@ class Forgery
|
|
24
24
|
lines
|
25
25
|
end
|
26
26
|
|
27
|
-
#
|
28
|
-
#
|
29
|
-
def self.
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
internal_path_to_format(format)
|
27
|
+
# Search a file in all load_paths, starting from last to first, so
|
28
|
+
# last takes precedence over first.
|
29
|
+
def self.find_file(name, folder)
|
30
|
+
Forgery.load_paths.reverse.each do |path|
|
31
|
+
file = "#{path}/#{folder}/#{name}"
|
32
|
+
return file if File.exists?(file)
|
34
33
|
end
|
35
34
|
end
|
36
|
-
|
37
|
-
# Returns the path to a format outside of forgery
|
38
|
-
def self.external_path_to_format(format)
|
39
|
-
Forgery.rails_root + '/lib/forgery/formats/' + format.to_s if Forgery.rails?
|
40
|
-
end
|
41
|
-
|
42
|
-
# Returns the path to a format inside of forgery
|
43
|
-
def self.internal_path_to_format(format)
|
44
|
-
File.dirname(__FILE__) + '/formats/' + format.to_s
|
45
|
-
end
|
46
|
-
|
47
|
-
# Returns the path to a dictionary. It will return the external path if
|
48
|
-
# the file exists, otherwise it will return the internal path.
|
49
|
-
def self.path_to_dictionary(dictionary)
|
50
|
-
if external_path_to_dictionary(dictionary) && File.exists?(external_path_to_dictionary(dictionary))
|
51
|
-
external_path_to_dictionary(dictionary)
|
52
|
-
else
|
53
|
-
internal_path_to_dictionary(dictionary)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# Returns the path to a dictionary outside of forgery
|
58
|
-
def self.external_path_to_dictionary(dictionary)
|
59
|
-
Forgery.rails_root + '/lib/forgery/dictionaries/' + dictionary.to_s if Forgery.rails?
|
60
|
-
end
|
61
|
-
|
62
|
-
# Returns the path to a dictionary within forgery
|
63
|
-
def self.internal_path_to_dictionary(dictionary)
|
64
|
-
File.dirname(__FILE__) + '/dictionaries/' + dictionary.to_s
|
65
|
-
end
|
66
|
-
|
67
35
|
end
|
68
|
-
|
69
36
|
end
|
data/lib/forgery/forgery.rb
CHANGED
@@ -8,6 +8,15 @@ class Forgery
|
|
8
8
|
@@formats ||= Formats.new
|
9
9
|
end
|
10
10
|
|
11
|
+
def self.load_paths
|
12
|
+
@@load_paths ||= [File.dirname(__FILE__)]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.load_from!(path)
|
16
|
+
self.load_paths << File.expand_path(path)
|
17
|
+
Dir["#{self.load_paths.last}/**/*.rb"].uniq.each { |file| require file }
|
18
|
+
end
|
19
|
+
|
11
20
|
def self.rails_root
|
12
21
|
if defined?(Rails)
|
13
22
|
Rails.root.to_s
|
data/lib/forgery/version.rb
CHANGED
data/lib/forgery.rb
CHANGED
@@ -29,8 +29,4 @@ end
|
|
29
29
|
|
30
30
|
# Loading rails forgeries to override current forgery methods and add new
|
31
31
|
# forgeries
|
32
|
-
if Forgery.rails?
|
33
|
-
Dir[File.expand_path(Forgery.rails_root + '/lib/forgery/**/*.rb')].uniq.each do |file|
|
34
|
-
require file
|
35
|
-
end
|
36
|
-
end
|
32
|
+
Forgery.load_from! "#{Forgery.rails_root}/lib/forgery" if Forgery.rails?
|