depot 0.1.0 → 0.2.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/README.rdoc +66 -1
- data/depot.gemspec +1 -1
- data/lib/depot.rb +4 -0
- data/lib/depot/base.rb +0 -3
- data/lib/depot/context.rb +7 -2
- data/lib/depot/template.rb +6 -0
- data/lib/depot/version.rb +1 -1
- data/spec/depot/context_spec.rb +5 -2
- data/spec/fixtures/example.html.erb +1 -0
- data/spec/spec_helper.rb +4 -0
- metadata +20 -22
data/README.rdoc
CHANGED
@@ -1,3 +1,68 @@
|
|
1
1
|
= Depot
|
2
2
|
|
3
|
-
|
3
|
+
Depot is a simple and more *maintainable* way to define seed data in Rails.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem "depot", "~> 0.1.1", require: false
|
10
|
+
|
11
|
+
== Usage
|
12
|
+
|
13
|
+
You've probably did that in the old days of your +db/seeds.rb+ life.
|
14
|
+
|
15
|
+
# This file should contain all the record creation needed to seed the database with its default values.
|
16
|
+
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
17
|
+
#
|
18
|
+
# Examples:
|
19
|
+
#
|
20
|
+
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
|
21
|
+
# Mayor.create(name: 'Emanuel', city: cities.first)
|
22
|
+
|
23
|
+
If there were a better way to populate your database it would be like this:
|
24
|
+
|
25
|
+
require "depot"
|
26
|
+
|
27
|
+
Depot.construct do
|
28
|
+
cities do
|
29
|
+
create name: 'Chicago', as: :chicago
|
30
|
+
create name: 'Copenhagen'
|
31
|
+
end
|
32
|
+
|
33
|
+
# If you prefer you can use the block syntax too.
|
34
|
+
mayors do
|
35
|
+
create do |m|
|
36
|
+
m.name = 'Emanuel'
|
37
|
+
m.city = chicago
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Yes, you can!
|
43
|
+
|
44
|
+
== License
|
45
|
+
|
46
|
+
(The MIT License)
|
47
|
+
|
48
|
+
Copyright (c) 2012 Rainer Borene
|
49
|
+
|
50
|
+
Permission is hereby granted, free of charge, to any person
|
51
|
+
obtaining a copy of this software and associated documentation files
|
52
|
+
(the 'Software'), to deal in the Software without restriction,
|
53
|
+
including without limitation the rights to use, copy, modify, merge,
|
54
|
+
publish, distribute, sublicense, an d/or sell copies of the
|
55
|
+
Software, and to permit persons to whom the Software is furnished to
|
56
|
+
do so, subject to the following conditions:
|
57
|
+
|
58
|
+
The above copyright notice and this permission notice shall be
|
59
|
+
included in all copies or substantial portions of the Software.
|
60
|
+
|
61
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
62
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
63
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
64
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
65
|
+
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
66
|
+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
67
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
68
|
+
THE SOFTWARE.
|
data/depot.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
s.add_runtime_dependency "
|
21
|
+
s.add_runtime_dependency "rails" , ">= 3.0"
|
22
22
|
|
23
23
|
s.add_development_dependency "rake" , "~> 0.9"
|
24
24
|
s.add_development_dependency "rspec" , "~> 2.8"
|
data/lib/depot.rb
CHANGED
data/lib/depot/base.rb
CHANGED
data/lib/depot/context.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require "active_support/core_ext/hash"
|
2
|
-
|
3
1
|
module Depot
|
4
2
|
class Context
|
5
3
|
attr_reader :klass, :base
|
@@ -13,6 +11,13 @@ module Depot
|
|
13
11
|
@finder = criteria
|
14
12
|
end
|
15
13
|
|
14
|
+
def render_template(template, assigns = {}, view_path = nil)
|
15
|
+
view_path ||= Rails.root.join("db", "seeds")
|
16
|
+
view = Depot::Template.new(view_path)
|
17
|
+
view.assign(assigns)
|
18
|
+
view.render :template => template.to_s
|
19
|
+
end
|
20
|
+
|
16
21
|
def create(attributes = {})
|
17
22
|
# remove method reference symbol
|
18
23
|
key = attributes[:as]
|
data/lib/depot/version.rb
CHANGED
data/spec/depot/context_spec.rb
CHANGED
@@ -23,10 +23,14 @@ describe Depot::Context do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
describe "#render_template" do
|
27
|
+
output = subject.call.render_template(:example, { title: "Hello World" }, "spec/fixtures")
|
28
|
+
output.should == "<h1>Hello World</h1>\n"
|
29
|
+
end
|
30
|
+
|
26
31
|
describe "#create" do
|
27
32
|
it "should create a new entry given a hash" do
|
28
33
|
subject.create({ name: "Jonh Doe", email: "jonh@doe.com", :as => :jonh_doe })
|
29
|
-
@base.entries.should_not be_empty
|
30
34
|
@base.entries.should have_key :jonh_doe
|
31
35
|
end
|
32
36
|
|
@@ -36,7 +40,6 @@ describe Depot::Context do
|
|
36
40
|
p.email = "jonh@doe.com"
|
37
41
|
end
|
38
42
|
|
39
|
-
@base.entries.should_not be_empty
|
40
43
|
@base.entries.should have_key :jonh_doe
|
41
44
|
end
|
42
45
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1><%= @title %></h1>
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: depot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement: &
|
15
|
+
name: rails
|
16
|
+
requirement: &74892910 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 3.0
|
21
|
+
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *74892910
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &74892210 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0.9'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *74892210
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &74891170 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '2.8'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *74891170
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: pry
|
49
|
-
requirement: &
|
49
|
+
requirement: &74890490 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0.9'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *74890490
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: guard-rspec
|
60
|
-
requirement: &
|
60
|
+
requirement: &74889680 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0.6'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *74889680
|
69
69
|
description: A simple DSL for defining database seeds in Rails.
|
70
70
|
email:
|
71
71
|
- me@rainerborene.com
|
@@ -82,10 +82,12 @@ files:
|
|
82
82
|
- lib/depot.rb
|
83
83
|
- lib/depot/base.rb
|
84
84
|
- lib/depot/context.rb
|
85
|
+
- lib/depot/template.rb
|
85
86
|
- lib/depot/version.rb
|
86
87
|
- spec/depot/base_spec.rb
|
87
88
|
- spec/depot/context_spec.rb
|
88
89
|
- spec/depot/version_spec.rb
|
90
|
+
- spec/fixtures/example.html.erb
|
89
91
|
- spec/spec_helper.rb
|
90
92
|
homepage: https://github.com/rainerborene/depot
|
91
93
|
licenses: []
|
@@ -101,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
103
|
version: '0'
|
102
104
|
segments:
|
103
105
|
- 0
|
104
|
-
hash:
|
106
|
+
hash: -627366001
|
105
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
108
|
none: false
|
107
109
|
requirements:
|
@@ -110,15 +112,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
112
|
version: '0'
|
111
113
|
segments:
|
112
114
|
- 0
|
113
|
-
hash:
|
115
|
+
hash: -627366001
|
114
116
|
requirements: []
|
115
117
|
rubyforge_project: depot
|
116
|
-
rubygems_version: 1.8.
|
118
|
+
rubygems_version: 1.8.11
|
117
119
|
signing_key:
|
118
120
|
specification_version: 3
|
119
121
|
summary: Populate your database in an elegant way
|
120
|
-
test_files:
|
121
|
-
- spec/depot/base_spec.rb
|
122
|
-
- spec/depot/context_spec.rb
|
123
|
-
- spec/depot/version_spec.rb
|
124
|
-
- spec/spec_helper.rb
|
122
|
+
test_files: []
|