jim-summon 0.0.0

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 ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jim Benton
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,20 @@
1
+ = summon
2
+
3
+ Provides a nice DSL for creating dummy data using Factory Girl factory definitions.
4
+
5
+ Docs and examples coming soon.
6
+
7
+ == Note on Patches/Pull Requests
8
+
9
+ * Fork the project.
10
+ * Make your feature addition or bug fix.
11
+ * Add tests for it. This is important so I don't break it in a
12
+ future version unintentionally.
13
+ * Commit, do not mess with rakefile, version, or history.
14
+ (if you want to have your own version, that is fine but
15
+ bump version in a commit by itself I can ignore when I pull)
16
+ * Send me a pull request. Bonus points for topic branches.
17
+
18
+ == Copyright
19
+
20
+ Copyright (c) 2009 Jim Benton. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "summon"
8
+ gem.summary = %Q{Provided a nice DSL for creating dummy data using Factory Girl factory definitions}
9
+ gem.description = %Q{Allows for easily setting up deeply nested associations}
10
+ gem.email = "jim@autonomousmachine.com"
11
+ gem.homepage = "http://github.com/jim/summon"
12
+ gem.authors = ["Jim Benton"]
13
+ gem.add_dependency 'thoughtbot-factory_girl', '>= 1.2.0'
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ if File.exist?('VERSION')
47
+ version = File.read('VERSION')
48
+ else
49
+ version = ""
50
+ end
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "summon #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
data/lib/summon.rb ADDED
@@ -0,0 +1,61 @@
1
+ require 'factory_girl'
2
+
3
+ module Summon
4
+
5
+ class Conjure
6
+
7
+ attr :parent
8
+
9
+ def initialize(parent)
10
+ @parent = parent
11
+ end
12
+
13
+ def log(string)
14
+ if parent.nil?
15
+ printf string; $stdout.flush
16
+ end
17
+ end
18
+
19
+ def method_missing(name, *args, &block)
20
+
21
+ process_options = lambda do |o|
22
+ o.inject({}) do |hash, pair| key, value = pair
23
+ value = case value
24
+ when Range: value.to_a[rand(value.to_a.size)]
25
+ when Array: value[rand(value.size)]
26
+ when Proc: value.call
27
+ else value
28
+ end
29
+ hash[key] = value
30
+ hash
31
+ end
32
+ end
33
+
34
+ quantity = args.first
35
+ quantity = quantity.to_a[rand(quantity.to_a.size)] if quantity.is_a?(Range)
36
+ options = args.extract_options!
37
+
38
+ log "** Summoning #{quantity} #{name.to_s.pluralize} "
39
+
40
+ quantity.times do
41
+
42
+ log '.'
43
+
44
+ attributes = process_options.call(options)
45
+
46
+ if parent.nil?
47
+ child = Factory(name, attributes)
48
+ else
49
+ child = parent.send(name).create(Factory.attributes_for(name.to_s.singularize, attributes))
50
+ end
51
+ yield Conjure.new(child) if block_given?
52
+ end
53
+ log "\n"
54
+ end
55
+ end
56
+
57
+ end
58
+
59
+ def Summon(factory, quantity, options = {}, &block)
60
+ Summon::Conjure.new(nil).send(factory, quantity, options, &block)
61
+ end
data/summon.gemspec ADDED
@@ -0,0 +1,53 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{summon}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jim Benton"]
12
+ s.date = %q{2009-08-25}
13
+ s.description = %q{Allows for easily setting up deeply nested associations}
14
+ s.email = %q{jim@autonomousmachine.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/summon.rb",
27
+ "summon.gemspec",
28
+ "test/summon_test.rb",
29
+ "test/test_helper.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/jim/summon}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.3}
35
+ s.summary = %q{Provided a nice DSL for creating dummy data using Factory Girl factory definitions}
36
+ s.test_files = [
37
+ "test/summon_test.rb",
38
+ "test/test_helper.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<thoughtbot-factory_girl>, [">= 1.2.0"])
47
+ else
48
+ s.add_dependency(%q<thoughtbot-factory_girl>, [">= 1.2.0"])
49
+ end
50
+ else
51
+ s.add_dependency(%q<thoughtbot-factory_girl>, [">= 1.2.0"])
52
+ end
53
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class SummonTest < Test::Unit::TestCase
4
+ def test_pass
5
+ assert true, 'had better pass'
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ require 'summon'
7
+
8
+ class Test::Unit::TestCase
9
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jim-summon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jim Benton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-25 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-factory_girl
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.0
24
+ version:
25
+ description: Allows for easily setting up deeply nested associations
26
+ email: jim@autonomousmachine.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - lib/summon.rb
42
+ - summon.gemspec
43
+ - test/summon_test.rb
44
+ - test/test_helper.rb
45
+ has_rdoc: false
46
+ homepage: http://github.com/jim/summon
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.2.0
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Provided a nice DSL for creating dummy data using Factory Girl factory definitions
71
+ test_files:
72
+ - test/summon_test.rb
73
+ - test/test_helper.rb