peterpunk-spawner 0.0.1
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/MIT-LICENSE +20 -0
- data/README.rdoc +42 -0
- data/extras/samples.rake +31 -0
- data/init.rb +1 -0
- data/lib/spawner.rb +21 -0
- data/spawner.gemspec +21 -0
- metadata +67 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Michel Martens for CitrusByte (http://www.citrusbyte.com)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
= Spawner
|
2
|
+
|
3
|
+
Spawner is a simple fixtures replacement. In the examples
|
4
|
+
I use Faker to generate random data, but you can use any method.
|
5
|
+
|
6
|
+
== Usage
|
7
|
+
|
8
|
+
class User < ActiveRecord::Base
|
9
|
+
spawner do |user|
|
10
|
+
user.name = Faker::Name.name
|
11
|
+
user.email = Faker::Internet.email
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Then, in your test or in any other place:
|
16
|
+
|
17
|
+
@user = User.spawn
|
18
|
+
|
19
|
+
Or, if you need something special:
|
20
|
+
|
21
|
+
@user = User.spawn do |user|
|
22
|
+
user.name = "Michel Martens"
|
23
|
+
end
|
24
|
+
|
25
|
+
Or even this:
|
26
|
+
|
27
|
+
@user = User.spawn :name => "Michel Martens"
|
28
|
+
|
29
|
+
== Installation
|
30
|
+
|
31
|
+
You can install it as a Rails plugin or as a gem:
|
32
|
+
|
33
|
+
$ gem sources -a http://gems.github.com (you only have to do this once)
|
34
|
+
$ sudo gem install soveran-spawner
|
35
|
+
|
36
|
+
|
37
|
+
== Thanks
|
38
|
+
|
39
|
+
Thanks to Foca (http://github.com/foca/) for his suggestions and Pedro (http://github.com/peterpunk/) for the gemspec.
|
40
|
+
|
41
|
+
Copyright (c) 2008 Michel Martens for CitrusByte (http://www.citrusbyte.com).
|
42
|
+
Released under the MIT license.
|
data/extras/samples.rake
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Use this task to generate sample records
|
2
|
+
# for your database. This code has to be
|
3
|
+
# customized for each application.
|
4
|
+
#
|
5
|
+
# This task is not installed by default. It's
|
6
|
+
# provided here so you can use it if you find
|
7
|
+
# it convenient. To use it, move it to the
|
8
|
+
# lib/tasks directory in your rails install.
|
9
|
+
namespace(:db) do
|
10
|
+
namespace(:samples) do
|
11
|
+
desc "Populate the database with sample records."
|
12
|
+
task :load => :environment do
|
13
|
+
|
14
|
+
# Default user
|
15
|
+
user = User.spawn :login => 'admin'
|
16
|
+
|
17
|
+
# Default blog
|
18
|
+
blog = Blog.spawn :title => 'Foo Blog'
|
19
|
+
|
20
|
+
# Blog posts
|
21
|
+
20.times do
|
22
|
+
post = Post.spawn :user => user
|
23
|
+
|
24
|
+
# Post comments
|
25
|
+
5.times do
|
26
|
+
Comment.spawn :post => post
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/lib/spawner'
|
data/lib/spawner.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
class Base
|
3
|
+
class << self
|
4
|
+
@spawn = Hash.new do |hash, key|
|
5
|
+
hash[key] = lambda { |model| model }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.spawner &default
|
10
|
+
@spawn[self.name] = default
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.spawn attrs = Hash.new
|
14
|
+
model = new &@spawn[self.name]
|
15
|
+
model.attributes = attrs unless attrs.empty?
|
16
|
+
yield model if block_given?
|
17
|
+
model.save!
|
18
|
+
model
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spawner.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "spawner"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.date = "2008-08-24"
|
5
|
+
s.summary = "Simple fixtures replacement for ActiveRecord"
|
6
|
+
s.email = "michel@soveran.com"
|
7
|
+
s.homepage = "http://github.com/soveran/spawner"
|
8
|
+
s.description = "Generates Random data for test, demo, etc."
|
9
|
+
s.has_rdoc = true
|
10
|
+
s.authors = ["Michel Martens"]
|
11
|
+
s.files = [
|
12
|
+
"README.rdoc",
|
13
|
+
"MIT-LICENSE",
|
14
|
+
"spawner.gemspec",
|
15
|
+
"lib/spawner.rb",
|
16
|
+
"init.rb",
|
17
|
+
"extras/samples.rake"]
|
18
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
19
|
+
s.extra_rdoc_files = ['README.rdoc']
|
20
|
+
s.add_dependency("activerecord", ["> 0.0.0"])
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: peterpunk-spawner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michel Martens
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-08-24 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activerecord
|
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: Generates Random data for test, demo, etc.
|
25
|
+
email: michel@soveran.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- README.rdoc
|
32
|
+
files:
|
33
|
+
- README.rdoc
|
34
|
+
- MIT-LICENSE
|
35
|
+
- spawner.gemspec
|
36
|
+
- lib/spawner.rb
|
37
|
+
- init.rb
|
38
|
+
- extras/samples.rake
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/soveran/spawner
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options:
|
43
|
+
- --main
|
44
|
+
- README.rdoc
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.2.0
|
63
|
+
signing_key:
|
64
|
+
specification_version: 2
|
65
|
+
summary: Simple fixtures replacement for ActiveRecord
|
66
|
+
test_files: []
|
67
|
+
|