fixturease 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +27 -0
- data/bin/fixturease.rb +49 -0
- metadata +47 -0
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rake/gempackagetask'
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
PKG_VERSION="0.2"
|
5
|
+
PKG_FILES=["bin/fixturease.rb","Rakefile"]
|
6
|
+
|
7
|
+
spec = Gem::Specification.new do |s|
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.summary = "Easy fixture creation tool"
|
10
|
+
s.name = 'fixturease'
|
11
|
+
s.version = PKG_VERSION
|
12
|
+
s.requirements << 'none'
|
13
|
+
s.require_path = 'lib'
|
14
|
+
s.autorequire = 'rake'
|
15
|
+
s.files = PKG_FILES
|
16
|
+
s.bindir = "bin"
|
17
|
+
s.executables = ["fixturease.rb"]
|
18
|
+
s.default_executable = "fixturease.rb"
|
19
|
+
s.author = "Yurii Rashkovskii"
|
20
|
+
s.email = "yrashk@verbdev.com"
|
21
|
+
s.description = "Easy fixture creation too"
|
22
|
+
end
|
23
|
+
|
24
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
25
|
+
pkg.need_zip = true
|
26
|
+
pkg.need_tar = true
|
27
|
+
end
|
data/bin/fixturease.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
unless $0.match /^irb$/
|
3
|
+
exec "irb -I #{File.dirname(__FILE__)} -r fixturease --simple-prompt"
|
4
|
+
else
|
5
|
+
ENV['RAILS_ENV'] ||= 'test'
|
6
|
+
ENV['RAILS_ROOT'] ||= "."
|
7
|
+
ENV['FIXTURES_ROOT'] ||= "spec/fixtures"
|
8
|
+
puts "Loading Fixturease console for #{ENV['RAILS_ENV']} mode."
|
9
|
+
require ENV['RAILS_ROOT'] + '/config/boot'
|
10
|
+
require ENV['RAILS_ROOT'] + '/config/environment'
|
11
|
+
class ActiveRecord::Base
|
12
|
+
alias_method :save_orig, :save
|
13
|
+
@@fixtures = {}
|
14
|
+
def save
|
15
|
+
save_orig
|
16
|
+
@@fixtures[self.class] ||= {}
|
17
|
+
@@fixtures[self.class][self.id] = self
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.fixturease_fixtures
|
21
|
+
@@fixtures
|
22
|
+
end
|
23
|
+
end
|
24
|
+
ActiveRecord::Base.send :increment_open_transactions
|
25
|
+
ActiveRecord::Base.connection.begin_db_transaction
|
26
|
+
at_exit do
|
27
|
+
vars = {}
|
28
|
+
instance_variables.each {|varname| vars[instance_variable_get(varname)]=varname.gsub(/^@/,"") if instance_variable_get(varname).is_a? ActiveRecord::Base}
|
29
|
+
unless ActiveRecord::Base.fixturease_fixtures.keys.empty?
|
30
|
+
puts
|
31
|
+
puts "Saving fixtures:"
|
32
|
+
ActiveRecord::Base.fixturease_fixtures.each_pair do |k,v|
|
33
|
+
filename = "#{ENV['RAILS_ROOT']}/#{ENV['FIXTURES_ROOT']}/#{k.table_name}.yml"
|
34
|
+
print "#{k} [#{filename}]: "
|
35
|
+
puts v.keys.collect{|rec_id| vars[k.find(rec_id)] ? vars[k.find(rec_id)] : rec_id }.to_sentence
|
36
|
+
f = File.new("#{filename}","a")
|
37
|
+
f.write "\n\n# Fixturease (#{Time.now}):\n\n"
|
38
|
+
f.write v.values.inject({}) { |hsh, record| hsh.merge(vars[record] || "#{k.table_name}_#{record.id}" => record.attributes) }.to_yaml(:SortKeys => true).gsub(/^---.*\n/,"")
|
39
|
+
f.write "\n# End Fixturease (#{Time.now})\n\n"
|
40
|
+
f.close
|
41
|
+
end
|
42
|
+
else
|
43
|
+
puts
|
44
|
+
puts "No new objects were created."
|
45
|
+
end
|
46
|
+
ActiveRecord::Base.connection.rollback_db_transaction
|
47
|
+
ActiveRecord::Base.send :decrement_open_transactions
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: fixturease
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: "0.2"
|
7
|
+
date: 2007-01-18 00:00:00 +02:00
|
8
|
+
summary: Easy fixture creation tool
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: yrashk@verbdev.com
|
12
|
+
homepage:
|
13
|
+
rubyforge_project:
|
14
|
+
description: Easy fixture creation too
|
15
|
+
autorequire: rake
|
16
|
+
default_executable: fixturease.rb
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Yurii Rashkovskii
|
31
|
+
files:
|
32
|
+
- bin/fixturease.rb
|
33
|
+
- Rakefile
|
34
|
+
test_files: []
|
35
|
+
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
extra_rdoc_files: []
|
39
|
+
|
40
|
+
executables:
|
41
|
+
- fixturease.rb
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
requirements:
|
45
|
+
- none
|
46
|
+
dependencies: []
|
47
|
+
|