seedy 0.6.3
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/.document +5 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/lib/seedy.rb +12 -0
- data/lib/seedy/buffer.rb +2 -0
- data/lib/seedy/buffer/abstract_buffer.rb +27 -0
- data/lib/seedy/buffer/database_buffer.rb +38 -0
- data/lib/seedy/connection.rb +15 -0
- data/lib/seedy/exceptions.rb +2 -0
- data/lib/seedy/generators.rb +22 -0
- data/lib/seedy/generators/address.rb +19 -0
- data/lib/seedy/generators/company.rb +10 -0
- data/lib/seedy/generators/customer.rb +7 -0
- data/lib/seedy/generators/date_time.rb +7 -0
- data/lib/seedy/generators/department.rb +329 -0
- data/lib/seedy/generators/description.rb +7 -0
- data/lib/seedy/generators/direction.rb +8 -0
- data/lib/seedy/generators/duration.rb +7 -0
- data/lib/seedy/generators/email_address.rb +7 -0
- data/lib/seedy/generators/guid.rb +7 -0
- data/lib/seedy/generators/industry.rb +40 -0
- data/lib/seedy/generators/money.rb +7 -0
- data/lib/seedy/generators/name.rb +13 -0
- data/lib/seedy/generators/ownership.rb +8 -0
- data/lib/seedy/generators/password.rb +10 -0
- data/lib/seedy/generators/phone.rb +7 -0
- data/lib/seedy/generators/priority.rb +8 -0
- data/lib/seedy/generators/status.rb +7 -0
- data/lib/seedy/generators/subject.rb +7 -0
- data/lib/seedy/generators/title.rb +484 -0
- data/lib/seedy/generators/user.rb +7 -0
- data/lib/seedy/generators/website.rb +7 -0
- data/lib/seedy/graph.rb +3 -0
- data/lib/seedy/graphs/abstract_graph.rb +143 -0
- data/lib/seedy/graphs/instance_methods.rb +0 -0
- data/lib/seedy/graphs/simple_graph.rb +36 -0
- data/lib/seedy/graphs/user_graph.rb +35 -0
- data/lib/seedy/random.rb +7 -0
- data/lib/seedy/record.rb +13 -0
- data/lib/seedy/records/accounts.rb +49 -0
- data/lib/seedy/records/attribute_methods.rb +121 -0
- data/lib/seedy/records/bugs.rb +38 -0
- data/lib/seedy/records/calls.rb +41 -0
- data/lib/seedy/records/cases.rb +38 -0
- data/lib/seedy/records/contacts.rb +46 -0
- data/lib/seedy/records/email_addresses.rb +20 -0
- data/lib/seedy/records/emails.rb +32 -0
- data/lib/seedy/records/leads.rb +48 -0
- data/lib/seedy/records/opportunities.rb +42 -0
- data/lib/seedy/records/record.rb +45 -0
- data/lib/seedy/records/teams.rb +32 -0
- data/lib/seedy/records/users.rb +45 -0
- data/seedy.gemspec +140 -0
- data/test/helper.rb +18 -0
- data/test/test_generators.rb +10 -0
- data/test/test_seedy.rb +18 -0
- metadata +315 -0
data/lib/seedy/graph.rb
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
module Seedy
|
2
|
+
class AbstractGraph
|
3
|
+
@@related_records = {
|
4
|
+
:teams => 0,
|
5
|
+
:accounts => 0,
|
6
|
+
:bugs => 0,
|
7
|
+
:calls => 0,
|
8
|
+
:cases => 0,
|
9
|
+
:contacts => 0,
|
10
|
+
:documents=> 0,
|
11
|
+
:emails => 0,
|
12
|
+
:email_addresses => 0,
|
13
|
+
:leads => 0,
|
14
|
+
:meetings => 0,
|
15
|
+
:notes => 0,
|
16
|
+
:opportunities => 0,
|
17
|
+
:products => 0,
|
18
|
+
:product_bundles => 0,
|
19
|
+
:quotes => 0,
|
20
|
+
:tasks => 0,
|
21
|
+
}
|
22
|
+
|
23
|
+
@@records = {}
|
24
|
+
@@buffer = Seedy::AbstractBuffer
|
25
|
+
|
26
|
+
# Adds an ID to the id array
|
27
|
+
def add(mod,id)
|
28
|
+
@@records[mod] = [] unless @@records[mod].class == Array
|
29
|
+
@@records[mod] << id
|
30
|
+
end
|
31
|
+
|
32
|
+
# Selects a random ID from the id array for a given module
|
33
|
+
def select(mod)
|
34
|
+
@@records[mod][rand(@@records[mod].length - 1)]
|
35
|
+
end
|
36
|
+
|
37
|
+
def records
|
38
|
+
@@related_records
|
39
|
+
end
|
40
|
+
|
41
|
+
# Our buffer
|
42
|
+
def buffer
|
43
|
+
@@buffer
|
44
|
+
end
|
45
|
+
|
46
|
+
def create_user
|
47
|
+
user = Users.build
|
48
|
+
buffer << user
|
49
|
+
add(:users, user)
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_teams
|
53
|
+
mod = :teams
|
54
|
+
records[mod].times {
|
55
|
+
team = Teams.build(select(:users))
|
56
|
+
buffer << team
|
57
|
+
add(mod, team.id)
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
def create_accounts
|
62
|
+
mod = :accounts
|
63
|
+
records[mod].times {
|
64
|
+
account = Accounts.build(select(:users),select(:teams))
|
65
|
+
buffer << account
|
66
|
+
add(mod, account.id)
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
def create_bugs
|
71
|
+
mod = :bugs
|
72
|
+
records[mod].times {
|
73
|
+
bug = Bugs.build(select(:users),select(:teams), select(:accounts))
|
74
|
+
buffer << bug
|
75
|
+
add(mod, bug.id)
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
def create_contacts
|
80
|
+
mod = :contacts
|
81
|
+
records[mod].times {
|
82
|
+
contact = Contacts.build(select(:users),select(:teams), select(:accounts))
|
83
|
+
buffer << contact
|
84
|
+
add(mod, contact.id)
|
85
|
+
}
|
86
|
+
end
|
87
|
+
|
88
|
+
def create_cases
|
89
|
+
mod = :cases
|
90
|
+
records[mod].times {
|
91
|
+
cases = Cases.build(select(:users),select(:teams), select(:accounts))
|
92
|
+
buffer << cases
|
93
|
+
add(mod, cases.id)
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
def create_opportunities
|
98
|
+
mod = :opportunities
|
99
|
+
records[mod].times {
|
100
|
+
opp = Opportunities.build(select(:users),select(:teams), select(:accounts))
|
101
|
+
buffer << opp
|
102
|
+
add(mod, opp.id)
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
106
|
+
def create_leads
|
107
|
+
mod = :leads
|
108
|
+
records[mod].times {
|
109
|
+
lead = Leads.build(select(:users),select(:teams), select(:contacts), select(:opportunities), select(:accounts))
|
110
|
+
buffer << lead
|
111
|
+
add(mod, lead.id)
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
115
|
+
def create_calls
|
116
|
+
mod = :calls
|
117
|
+
records[mod].times {
|
118
|
+
call = Calls.build(select(:users),select(:teams), select(:contacts))
|
119
|
+
buffer << call
|
120
|
+
add(mod, call.id)
|
121
|
+
}
|
122
|
+
end
|
123
|
+
|
124
|
+
def create_emails
|
125
|
+
mod = :emails
|
126
|
+
records[mod].times {
|
127
|
+
email = Emails.build(select(:users),select(:teams))
|
128
|
+
buffer << email
|
129
|
+
add(mod, email.id)
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
133
|
+
def create_email_addresses
|
134
|
+
mod = :email_addresses
|
135
|
+
records[mod].times {
|
136
|
+
email = EmailAddresses.build()
|
137
|
+
buffer << email
|
138
|
+
add(mod, email.id)
|
139
|
+
}
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
end
|
File without changes
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Seedy
|
2
|
+
class SimpleGraph < AbstractGraph
|
3
|
+
@@related_records = {
|
4
|
+
:teams => 1,
|
5
|
+
:accounts => 20,
|
6
|
+
:bugs => 60,
|
7
|
+
:cases => 80,
|
8
|
+
:contacts => 80,
|
9
|
+
:opportunities => 40,
|
10
|
+
:calls => 480,
|
11
|
+
:leads => 80,
|
12
|
+
:emails => 320,
|
13
|
+
:email_addresses => 80
|
14
|
+
}
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
@@buffer = Seedy::AbstractBuffer
|
19
|
+
|
20
|
+
# Creates a new user record, and all the dependent records listed above
|
21
|
+
def initialize()
|
22
|
+
create_user
|
23
|
+
create_teams
|
24
|
+
create_accounts
|
25
|
+
create_bugs
|
26
|
+
create_contacts
|
27
|
+
create_cases
|
28
|
+
create_opportunities
|
29
|
+
create_calls
|
30
|
+
create_leads
|
31
|
+
Seedy::DatabaseBuffer.flush
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Seedy
|
2
|
+
class UserGraph < AbstractGraph
|
3
|
+
@@related_records = {
|
4
|
+
'Teams' => 1,
|
5
|
+
'Accounts' => 20,
|
6
|
+
'Bugs' => 60,
|
7
|
+
'Calls' => 480,
|
8
|
+
'Cases' => 80,
|
9
|
+
'Contacts' => 80,
|
10
|
+
'Documents'=> 80,
|
11
|
+
'Emails' => 320,
|
12
|
+
'EmailAddresses'=> 80,
|
13
|
+
'Leads' => 80,
|
14
|
+
'Meetings' => 160,
|
15
|
+
'Notes' => 80,
|
16
|
+
'Opportunities' => 40,
|
17
|
+
'Products' => 80,
|
18
|
+
'ProductBundles' => 40,
|
19
|
+
'Quotes' => 20,
|
20
|
+
'Tasks' => 80,
|
21
|
+
}
|
22
|
+
|
23
|
+
# Creates a new user record, and all the dependent records listed above
|
24
|
+
def initialize
|
25
|
+
user = Users.build
|
26
|
+
@@related_records.each_pair do |module_name,count|
|
27
|
+
count.times {
|
28
|
+
record = module_name.build(self)
|
29
|
+
DatabaseBuffer.insert(record)
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
data/lib/seedy/random.rb
ADDED
data/lib/seedy/record.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'seedy/records/attribute_methods'
|
2
|
+
require 'seedy/records/record'
|
3
|
+
require 'seedy/records/accounts'
|
4
|
+
require 'seedy/records/bugs'
|
5
|
+
require 'seedy/records/calls'
|
6
|
+
require 'seedy/records/cases'
|
7
|
+
require 'seedy/records/contacts'
|
8
|
+
require 'seedy/records/email_addresses'
|
9
|
+
require 'seedy/records/emails'
|
10
|
+
require 'seedy/records/leads'
|
11
|
+
require 'seedy/records/opportunities'
|
12
|
+
require 'seedy/records/teams'
|
13
|
+
require 'seedy/records/users'
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Seedy
|
2
|
+
class Accounts < Record
|
3
|
+
self.columns = {
|
4
|
+
:id => :guid,
|
5
|
+
:name => :company,
|
6
|
+
:date_entered => :date_time,
|
7
|
+
:date_modified => :date_time,
|
8
|
+
:modified_user_id => :association,
|
9
|
+
:created_by => :association,
|
10
|
+
:description => :description,
|
11
|
+
:deleted => 0,
|
12
|
+
:assigned_user_id => :association,
|
13
|
+
:team_id => :association,
|
14
|
+
:account_type => :customer_type,
|
15
|
+
:industry => :industry,
|
16
|
+
:annual_revenue => :monetary_sum,
|
17
|
+
:phone_fax => :phone,
|
18
|
+
:billing_address_street => :address_street,
|
19
|
+
:billing_address_city => :city,
|
20
|
+
:billing_address_state => :state,
|
21
|
+
:billing_address_postalcode => :zip,
|
22
|
+
:billing_address_country => :country,
|
23
|
+
:phone_office => :phone,
|
24
|
+
:website => :website,
|
25
|
+
:ownership => :ownership,
|
26
|
+
:employees => :employees,
|
27
|
+
:shipping_address_street => :address_street,
|
28
|
+
:shipping_address_city => :city,
|
29
|
+
:shipping_address_state => :state,
|
30
|
+
:shipping_address_postalcode => :zip,
|
31
|
+
:shipping_address_country => :country,
|
32
|
+
}
|
33
|
+
|
34
|
+
class << self
|
35
|
+
def build(user, team)
|
36
|
+
account = Accounts.new
|
37
|
+
account.associate(user,team)
|
38
|
+
account
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def associate(user, team)
|
43
|
+
write_attribute(:modified_user_id, user.id)
|
44
|
+
write_attribute(:assigned_user_id, user.id)
|
45
|
+
write_attribute(:team_id, team)
|
46
|
+
write_attribute(:created_by, user.id)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
module Seedy
|
2
|
+
module AttributeMethods
|
3
|
+
# Wrapper around attributes hash
|
4
|
+
def read_attribute(key)
|
5
|
+
@attributes[key]
|
6
|
+
end
|
7
|
+
|
8
|
+
# Wrapper around attributes hash
|
9
|
+
def write_attribute(key, value)
|
10
|
+
@attributes[key] = value
|
11
|
+
end
|
12
|
+
|
13
|
+
def table_name
|
14
|
+
self.class.to_s.tableize.split(/\//)[-1]
|
15
|
+
end
|
16
|
+
|
17
|
+
def table_columns#:nodoc:
|
18
|
+
sql = "SHOW FIELDS FROM #{table_name}"
|
19
|
+
columns = []
|
20
|
+
result = execute(sql)
|
21
|
+
result.each { |field| columns << field[0]}
|
22
|
+
result.free
|
23
|
+
columns
|
24
|
+
end
|
25
|
+
|
26
|
+
# Adds a row to a join table
|
27
|
+
def join(table, hash)
|
28
|
+
sql = <<-EOF
|
29
|
+
INSERT INTO #{table}
|
30
|
+
(#{hash.keys.join(",")})
|
31
|
+
VALUES
|
32
|
+
(#{quote(hash.values).join(",")});
|
33
|
+
EOF
|
34
|
+
sql.gsub!(/^\s{6}/, '')
|
35
|
+
execute(sql)
|
36
|
+
end
|
37
|
+
|
38
|
+
def quote(object)
|
39
|
+
case object
|
40
|
+
when String:
|
41
|
+
return "'#{object}'"
|
42
|
+
when Fixnum:
|
43
|
+
return object
|
44
|
+
when Array:
|
45
|
+
objs = []
|
46
|
+
object.each do |o|
|
47
|
+
objs << quote(o)
|
48
|
+
end
|
49
|
+
return objs
|
50
|
+
else
|
51
|
+
return "'#{object}'"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def execute(sql)
|
56
|
+
puts sql
|
57
|
+
Seedy.connection.query(sql)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Checks to see if we have all the neccessary attributes
|
61
|
+
def valid?
|
62
|
+
clear_errors
|
63
|
+
valid = true
|
64
|
+
self.class.columns.keys.each do |attribute|
|
65
|
+
if @attributes[attribute].blank?
|
66
|
+
@errors.add "#{attribute} cannot be blank"
|
67
|
+
valid = false
|
68
|
+
end
|
69
|
+
end
|
70
|
+
valid
|
71
|
+
end
|
72
|
+
|
73
|
+
def errors
|
74
|
+
@errors.to_a.join(", ")
|
75
|
+
end
|
76
|
+
|
77
|
+
def clear_errors
|
78
|
+
@errors = Set.new
|
79
|
+
end
|
80
|
+
|
81
|
+
# Generates get/set methods for keys in the attributes hash
|
82
|
+
def define_attribute_methods
|
83
|
+
return if self.class.attribute_methods_generated
|
84
|
+
table_columns.each do |k|
|
85
|
+
self.class.module_eval %Q?
|
86
|
+
def #{k}
|
87
|
+
read_attribute :#{k}
|
88
|
+
end
|
89
|
+
def #{k}=(value)
|
90
|
+
write_attribute :#{k},value
|
91
|
+
end
|
92
|
+
?
|
93
|
+
end
|
94
|
+
self.class.attribute_methods_generated = true
|
95
|
+
end
|
96
|
+
|
97
|
+
def generate_attributes_for(columns)
|
98
|
+
columns.each_pair do |column, generator|
|
99
|
+
case generator
|
100
|
+
when Symbol:
|
101
|
+
next if generator == :association
|
102
|
+
write_attribute(column, Seedy::Random.send(generator))
|
103
|
+
else
|
104
|
+
write_attribute(column, generator)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def attribute_for_inspect(attr_name)
|
110
|
+
value = read_attribute(attr_name)
|
111
|
+
if value.is_a?(String) && value.length > 50
|
112
|
+
"#{value[0..50]}...".inspect
|
113
|
+
elsif value.is_a?(Date) || value.is_a?(Time)
|
114
|
+
%("#{value.to_s}")
|
115
|
+
else
|
116
|
+
value.inspect
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Seedy
|
2
|
+
class Bugs < Record
|
3
|
+
self.columns = {
|
4
|
+
:id => :guid,
|
5
|
+
:name => :subject,
|
6
|
+
:date_entered => :date_time,
|
7
|
+
:date_modified => :date_time,
|
8
|
+
:modified_user_id => :association,
|
9
|
+
:created_by => :association,
|
10
|
+
:description => :description,
|
11
|
+
:deleted => 0,
|
12
|
+
:assigned_user_id => :association,
|
13
|
+
:team_id => :association,
|
14
|
+
:status => :status,
|
15
|
+
:priority => :priority,
|
16
|
+
}
|
17
|
+
|
18
|
+
class << self
|
19
|
+
def build(user, team, account)
|
20
|
+
bug = Bugs.new
|
21
|
+
bug.associate(user,team,account)
|
22
|
+
bug
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def associate(user, team, account)
|
27
|
+
write_attribute(:modified_user_id, user.id)
|
28
|
+
write_attribute(:assigned_user_id, user.id)
|
29
|
+
write_attribute(:team_id, team)
|
30
|
+
write_attribute(:created_by, user.id)
|
31
|
+
join("accounts_bugs", {
|
32
|
+
:id => Random.guid,
|
33
|
+
:account_id => account,
|
34
|
+
:bug_id => read_attribute(:id),
|
35
|
+
:date_modified => read_attribute(:date_modified)})
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|