forgery 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -92,6 +92,7 @@ Thanks to the authors and contributors:
92
92
  * Josh Nichols (technicalpickles)
93
93
  * Jeremy Stephens (viking aka crookshanks)
94
94
  * Darcy Laycock (Sutto)
95
+ * Lukas Westermann (lwe)
95
96
 
96
97
  ## Notes
97
98
 
@@ -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(path_to_dictionary(dictionary))
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(path_to_format(format))
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
- # Returns the path to a format. It will return the external path if the
28
- # file exists, otherwise it will return the internal path.
29
- def self.path_to_format(format)
30
- if external_path_to_format(format) && File.exists?(external_path_to_format(format))
31
- external_path_to_format(format)
32
- else
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  class Forgery
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
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?
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 1
9
- version: 0.3.1
8
+ - 2
9
+ version: 0.3.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nathan Sutton