soveran-spawner 0.0.2 → 0.0.4
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.rdoc +21 -2
- data/lib/spawner.rb +11 -14
- data/rails/init.rb +3 -0
- data/spawner.gemspec +5 -6
- metadata +7 -15
- data/init.rb +0 -1
data/README.rdoc
CHANGED
@@ -5,6 +5,8 @@ I use Faker to generate random data, but you can use any method.
|
|
5
5
|
|
6
6
|
== Usage
|
7
7
|
|
8
|
+
With ActiveRecord:
|
9
|
+
|
8
10
|
class User < ActiveRecord::Base
|
9
11
|
spawner do |user|
|
10
12
|
user.name = Faker::Name.name
|
@@ -12,6 +14,25 @@ I use Faker to generate random data, but you can use any method.
|
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
17
|
+
With Sequel:
|
18
|
+
|
19
|
+
class User < Sequel::Model
|
20
|
+
extend Spawner
|
21
|
+
|
22
|
+
spawner do |user|
|
23
|
+
user.name = Faker::Name.name
|
24
|
+
user.email = Faker::Internet.email
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
If you don't want to pollute your class definition, you
|
29
|
+
can of course use it from outside:
|
30
|
+
|
31
|
+
User.spawner do |user|
|
32
|
+
user.name = Faker::Name.name
|
33
|
+
user.email = Faker::Internet.email
|
34
|
+
end
|
35
|
+
|
15
36
|
Then, in your test or in any other place:
|
16
37
|
|
17
38
|
@user = User.spawn
|
@@ -28,8 +49,6 @@ Or even this:
|
|
28
49
|
|
29
50
|
== Installation
|
30
51
|
|
31
|
-
You can install it as a Rails plugin or as a gem:
|
32
|
-
|
33
52
|
$ gem sources -a http://gems.github.com (you only have to do this once)
|
34
53
|
$ sudo gem install soveran-spawner
|
35
54
|
|
data/lib/spawner.rb
CHANGED
@@ -1,19 +1,16 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
@@spawn
|
1
|
+
module Spawner
|
2
|
+
def spawner &default
|
3
|
+
@@spawn ||= Hash.new do |hash, key|
|
4
4
|
hash[key] = lambda { |model| model }
|
5
5
|
end
|
6
|
+
@@spawn[self.name] = default
|
7
|
+
end
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
model.attributes = attrs unless attrs.empty?
|
14
|
-
yield model if block_given?
|
15
|
-
model.save!
|
16
|
-
model
|
17
|
-
end
|
9
|
+
def spawn attrs = Hash.new
|
10
|
+
model = new &@@spawn[self.name]
|
11
|
+
model.attributes = attrs unless attrs.empty?
|
12
|
+
yield model if block_given?
|
13
|
+
model.save!
|
14
|
+
model
|
18
15
|
end
|
19
16
|
end
|
data/rails/init.rb
ADDED
data/spawner.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "spawner"
|
3
|
-
s.version = "0.0.
|
4
|
-
s.date = "2008-
|
5
|
-
s.summary = "Simple fixtures replacement for ActiveRecord"
|
3
|
+
s.version = "0.0.4"
|
4
|
+
s.date = "2008-12-18"
|
5
|
+
s.summary = "Simple fixtures replacement for Sequel, ActiveRecord and probably many other ORMs"
|
6
6
|
s.email = "michel@soveran.com"
|
7
7
|
s.homepage = "http://github.com/soveran/spawner"
|
8
|
-
s.description = "
|
8
|
+
s.description = "Simple fixtures replacement that allows to populate the database with custom data."
|
9
9
|
s.has_rdoc = true
|
10
10
|
s.authors = ["Michel Martens"]
|
11
11
|
s.files = [
|
@@ -13,9 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
"MIT-LICENSE",
|
14
14
|
"spawner.gemspec",
|
15
15
|
"lib/spawner.rb",
|
16
|
-
"init.rb",
|
16
|
+
"rails/init.rb",
|
17
17
|
"extras/samples.rake"]
|
18
18
|
s.rdoc_options = ["--main", "README.rdoc"]
|
19
19
|
s.extra_rdoc_files = ['README.rdoc']
|
20
|
-
s.add_dependency("activerecord", ["> 0.0.0"])
|
21
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soveran-spawner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Martens
|
@@ -9,19 +9,11 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-12-18 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
17
|
-
version_requirement:
|
18
|
-
version_requirements: !ruby/object:Gem::Requirement
|
19
|
-
requirements:
|
20
|
-
- - ">"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 0.0.0
|
23
|
-
version:
|
24
|
-
description: Populates the database with custom data.
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Simple fixtures replacement that allows to populate the database with custom data.
|
25
17
|
email: michel@soveran.com
|
26
18
|
executables: []
|
27
19
|
|
@@ -34,7 +26,7 @@ files:
|
|
34
26
|
- MIT-LICENSE
|
35
27
|
- spawner.gemspec
|
36
28
|
- lib/spawner.rb
|
37
|
-
- init.rb
|
29
|
+
- rails/init.rb
|
38
30
|
- extras/samples.rake
|
39
31
|
has_rdoc: true
|
40
32
|
homepage: http://github.com/soveran/spawner
|
@@ -62,6 +54,6 @@ rubyforge_project:
|
|
62
54
|
rubygems_version: 1.2.0
|
63
55
|
signing_key:
|
64
56
|
specification_version: 2
|
65
|
-
summary: Simple fixtures replacement for ActiveRecord
|
57
|
+
summary: Simple fixtures replacement for Sequel, ActiveRecord and probably many other ORMs
|
66
58
|
test_files: []
|
67
59
|
|
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/lib/spawner'
|