forgery 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +15 -10
- data/lib/forgery.rb +3 -0
- data/lib/forgery/forgery/date.rb +71 -0
- data/lib/forgery/forgery/name.rb +4 -3
- data/lib/forgery/forgery_railtie.rb +8 -0
- data/lib/forgery/version.rb +1 -1
- data/lib/generators/forgery/forgery_generator.rb +15 -15
- metadata +5 -4
- data/lib/forgery/railtie.rb +0 -10
data/README.markdown
CHANGED
@@ -33,7 +33,7 @@ plugin includes a generator providing directories to make your own forgeries.
|
|
33
33
|
|
34
34
|
## Rails 3 Generator
|
35
35
|
|
36
|
-
|
36
|
+
rails generate forgery
|
37
37
|
|
38
38
|
In a rails project this generator creates:
|
39
39
|
|
@@ -77,24 +77,29 @@ for individual examples.
|
|
77
77
|
Forgery(:monetary).formatted_money # => "$3.48"
|
78
78
|
Forgery(:monetary).money :min => 100, :max => 1000 # => "923.36"
|
79
79
|
|
80
|
-
##Customization
|
80
|
+
## Customization
|
81
|
+
|
81
82
|
You can utilize the directories generated in /lib to customize the behavior of forgery.
|
83
|
+
|
82
84
|
Examples of each of these components are available in the source.
|
83
85
|
|
84
|
-
###Dictionaries
|
86
|
+
### Dictionaries
|
87
|
+
|
85
88
|
Dictionaries are files with no extensions. Entries are separated by new lines.
|
86
89
|
|
87
|
-
###Forgeries
|
90
|
+
### Forgeries
|
91
|
+
|
88
92
|
Forgeries are classes that inherit from the Forgery class. A basic forgery definition is as follows
|
89
93
|
|
90
|
-
|
91
|
-
|
94
|
+
class NewForgery < Forgery
|
95
|
+
end
|
96
|
+
|
97
|
+
### Extensions
|
98
|
+
|
99
|
+
Extensions are additional methods/functionality that are added to classes (Ruby core or otherwise) that are loaded by Forgery. Follow standard Ruby practices.
|
92
100
|
|
93
|
-
###
|
94
|
-
Extensions are additional methods/functionality that are added to classes (Ruby core or otherwise)
|
95
|
-
that are loaded by Forgery. Follow standard Ruby practices.
|
101
|
+
### Formats
|
96
102
|
|
97
|
-
###Formats
|
98
103
|
Formatting for numerical fields. Each numerical entry corresponds to a # mark.
|
99
104
|
|
100
105
|
## DOCUMENTATION
|
data/lib/forgery.rb
CHANGED
@@ -30,3 +30,6 @@ end
|
|
30
30
|
# Loading rails forgeries to override current forgery methods and add new forgeries
|
31
31
|
# Only run this for Rails < 3.0 since we need to use a Railtie to initialize >= 3.0
|
32
32
|
Forgery.load_from! "#{Forgery.rails_root}/lib/forgery" if Forgery.rails? && Rails::VERSION::STRING < "3.0.0"
|
33
|
+
|
34
|
+
# Include our Railtie if Rails >= 3.0.0
|
35
|
+
require 'forgery/forgery_railtie' if Forgery.rails? && Rails::VERSION::STRING >= "3.0.0"
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
class Forgery::Date < Forgery
|
4
|
+
DAYS = %w{Sunday Monday Tuesday Wednesday Thursday Friday Saturday}
|
5
|
+
DAYS_ABBR = %w{Sun Mon Tue Wed Thu Fri Sat}
|
6
|
+
MONTHS = %w{January February March April May June July August September October November December}
|
7
|
+
MONTHS_ABBR = %w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
|
8
|
+
|
9
|
+
def self.day_of_week(options={})
|
10
|
+
options.reverse_merge!(:abbr => false)
|
11
|
+
|
12
|
+
if (options[:abbr])
|
13
|
+
DAYS_ABBR.random
|
14
|
+
else
|
15
|
+
DAYS.random
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.month(options={})
|
20
|
+
options.reverse_merge!(:abbr => false, :numerical => false)
|
21
|
+
|
22
|
+
if (options[:numerical])
|
23
|
+
1 + rand(12)
|
24
|
+
else
|
25
|
+
if (options[:abbr])
|
26
|
+
MONTHS_ABBR.random
|
27
|
+
else
|
28
|
+
MONTHS.random
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.year(options={})
|
35
|
+
options.reverse_merge!(:future => false, :min_delta => 0, :max_delta => 20)
|
36
|
+
|
37
|
+
#Calculate our delta
|
38
|
+
delta = options[:min_delta] + rand(options[:max_delta] + 1 - options[:min_delta]).to_i
|
39
|
+
|
40
|
+
#Potentially negate our delta if future is false
|
41
|
+
unless (options[:future])
|
42
|
+
if rand(2).zero?
|
43
|
+
delta *= -1
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
#Apply our delta to this year
|
48
|
+
DateTime.now.year + delta
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.day
|
52
|
+
1 + rand(31)
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.date(options={})
|
56
|
+
options.reverse_merge!(:future => false, :min_delta => 0, :max_delta => 7300)
|
57
|
+
|
58
|
+
#Calculate our delta
|
59
|
+
delta = options[:min_delta] + rand(options[:max_delta] + 1 - options[:min_delta]).to_i
|
60
|
+
|
61
|
+
#Potentially negate our delta if future is false
|
62
|
+
unless (options[:future])
|
63
|
+
if rand(2).zero?
|
64
|
+
delta *= -1
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
#Apply our delta to today
|
69
|
+
DateTime.now.to_date + delta
|
70
|
+
end
|
71
|
+
end
|
data/lib/forgery/forgery/name.rb
CHANGED
data/lib/forgery/version.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'rails/generators/base'
|
2
2
|
|
3
3
|
class ForgeryGenerator < Rails::Generators::Base
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
4
|
+
desc "Create the necessary directories in /lib to customize forgery's behavior"
|
5
|
+
|
6
|
+
def self.source_root
|
7
|
+
@_forgery_source_root ||= File.expand_path(File.dirname(__FILE__))
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_directories
|
11
|
+
puts "Creating directories in /lib/forgery..."
|
12
|
+
|
13
|
+
FileUtils.mkdir_p 'lib/forgery/dictionaries'
|
14
|
+
FileUtils.mkdir_p 'lib/forgery/extensions'
|
15
|
+
FileUtils.mkdir_p 'lib/forgery/forgeries'
|
16
|
+
FileUtils.mkdir_p 'lib/forgery/formats'
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 6
|
9
|
+
version: 0.3.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Nathan Sutton
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-10-
|
17
|
+
date: 2010-10-22 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- lib/forgery/file_reader.rb
|
77
77
|
- lib/forgery/forgery/address.rb
|
78
78
|
- lib/forgery/forgery/basic.rb
|
79
|
+
- lib/forgery/forgery/date.rb
|
79
80
|
- lib/forgery/forgery/internet.rb
|
80
81
|
- lib/forgery/forgery/lorem_ipsum.rb
|
81
82
|
- lib/forgery/forgery/monetary.rb
|
@@ -84,11 +85,11 @@ files:
|
|
84
85
|
- lib/forgery/forgery/time.rb
|
85
86
|
- lib/forgery/forgery.rb
|
86
87
|
- lib/forgery/forgery_api.rb
|
88
|
+
- lib/forgery/forgery_railtie.rb
|
87
89
|
- lib/forgery/formats/phone
|
88
90
|
- lib/forgery/formats/street_number
|
89
91
|
- lib/forgery/formats/zip
|
90
92
|
- lib/forgery/formats.rb
|
91
|
-
- lib/forgery/railtie.rb
|
92
93
|
- lib/forgery/version.rb
|
93
94
|
- lib/forgery.rb
|
94
95
|
- lib/generators/forgery/forgery_generator.rb
|