timecapsule 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,7 +1,8 @@
1
1
  source "http://rubygems.org"
2
2
  # Add dependencies required to use your gem here.
3
3
  # Example:
4
- gem "activerecord", ">= 2.3.5"
4
+ # gem "activerecord", ">= 2.3.5"
5
+ # gem "rails", ">=2.3.5"
5
6
 
6
7
  # Add dependencies to develop your gem here.
7
8
  # Include everything needed to run rake, tests, features, etc.
data/Gemfile.lock CHANGED
@@ -1,39 +1,22 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activemodel (3.1.2)
5
- activesupport (= 3.1.2)
6
- builder (~> 3.0.0)
7
- i18n (~> 0.6)
8
- activerecord (3.1.2)
9
- activemodel (= 3.1.2)
10
- activesupport (= 3.1.2)
11
- arel (~> 2.2.1)
12
- tzinfo (~> 0.3.29)
13
- activesupport (3.1.2)
14
- multi_json (~> 1.0)
15
- arel (2.2.1)
16
- builder (3.0.0)
17
4
  git (1.2.5)
18
- i18n (0.6.0)
19
5
  jeweler (1.6.4)
20
6
  bundler (~> 1.0)
21
7
  git (>= 1.2.5)
22
8
  rake
23
9
  json (1.6.1)
24
- multi_json (1.0.3)
25
10
  rake (0.9.2.2)
26
11
  rcov (0.9.11)
27
12
  rdoc (3.11)
28
13
  json (~> 1.4)
29
14
  shoulda (2.11.3)
30
- tzinfo (0.3.31)
31
15
 
32
16
  PLATFORMS
33
17
  ruby
34
18
 
35
19
  DEPENDENCIES
36
- activerecord (>= 2.3.5)
37
20
  bundler (~> 1.0.0)
38
21
  jeweler (~> 1.6.4)
39
22
  rcov
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/lib/timecapsule.rb CHANGED
@@ -0,0 +1,49 @@
1
+ class Timecapsule
2
+
3
+ config = YAML.load_file(Rails.root.join("config/timecapsule.yml")
4
+ IMPORT_DIR = config[:import_directory] || 'db/seed_data/'
5
+ EXPORT_DIR = config[:export_directory] || 'db/seed_data/'
6
+
7
+ require 'csv'
8
+
9
+ def self.import_model(model_import)
10
+ puts "Importing: #{model_import} from #{IMPORT_DIR}#{model_import.to_s.pluralize.underscore}.csv"
11
+ csv = CSV.read(Rails.root.join("#{IMPORT_DIR}#{model_import.to_s.pluralize.underscore}.csv"))
12
+ attributes = csv.shift
13
+ csv.each do |row|
14
+ hash = {}
15
+ attributes.collect{|k| k.to_sym}.each_with_index do |key,i|
16
+ hash[key] = row[i]
17
+ end
18
+ object = model_import.new(hash)
19
+ object.save(false)
20
+ end
21
+ end
22
+
23
+ def self.import
24
+ @csv_files = Dir.glob("#{IMPORT_DIR}*.csv")
25
+ @csv_files.each do |file|
26
+ model_name = file.split('/').last.split('.').first.classify.constantize
27
+ if model_name.count == 0
28
+ Timecapsule.import_model(model_name)
29
+ end
30
+ end
31
+ end
32
+
33
+ def self.export_model(model_export)
34
+ puts "Exporting: #{model_export} to #{EXPORT_DIR}#{model_export.to_s.pluralize.underscore}.csv"
35
+ @file = File.open("#{EXPORT_DIR}#{model_export.to_s.pluralize.underscore}.csv", "w")
36
+ @file.puts model_export.first.attributes.collect{|k,v| k}.join(",")
37
+ model_export.all.each do |item|
38
+ @file.puts item.attributes.collect{|k,v| "#{Timecapsule.output(v)}"}.join(",")
39
+ end
40
+ end
41
+
42
+ def self.output(value)
43
+ if value.is_a?(String)
44
+ return value.gsub(",",'')
45
+ end
46
+ value
47
+ end
48
+
49
+ end
@@ -1,7 +1,16 @@
1
1
  require 'helper'
2
+ require 'rails'
3
+
4
+ class User < ActiveRecord::Base
5
+ attr_accessor :first_name, :last_name, :username, :password
6
+ end
2
7
 
3
8
  class TestTimecapsule < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
9
+ should "export a model" do
10
+ flunk('FIGURE OUT HOW TO TEST THIS!!')
11
+ # u = User.new
12
+ # u.first_name = 'test'
13
+ # Timecapsule.export_model(User)
14
+ # assert_equal File.exists?("#{Timecapsule::EXPORT_DIR}#{User.to_s.pluralize.underscore}.csv"), true
6
15
  end
7
16
  end
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
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 = "timecapsule"
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ren\303\251e De Voursney"]
12
+ s.date = "2011-11-23"
13
+ s.description = "Great for creating seed data from data entered through your app's ui or the console"
14
+ s.email = "renee.devoursney@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rvmrc",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/timecapsule.rb",
29
+ "test/helper.rb",
30
+ "test/test_timecapsule.rb",
31
+ "timecapsule.gemspec"
32
+ ]
33
+ s.homepage = "http://github.com/reneedv/timecapsule"
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = "1.8.10"
37
+ s.summary = "gem for importing and exporting ActiveRecord data."
38
+
39
+ if s.respond_to? :specification_version then
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
44
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
45
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
46
+ s.add_development_dependency(%q<rcov>, [">= 0"])
47
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
48
+ else
49
+ s.add_dependency(%q<shoulda>, [">= 0"])
50
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
51
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
52
+ s.add_dependency(%q<rcov>, [">= 0"])
53
+ s.add_dependency(%q<rdoc>, [">= 0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<shoulda>, [">= 0"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
59
+ s.add_dependency(%q<rcov>, [">= 0"])
60
+ s.add_dependency(%q<rdoc>, [">= 0"])
61
+ end
62
+ end
63
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timecapsule
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Ren\xC3\xA9e De Voursney"
@@ -15,26 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-19 00:00:00 Z
18
+ date: 2011-11-23 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
22
- none: false
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- hash: 9
27
- segments:
28
- - 2
29
- - 3
30
- - 5
31
- version: 2.3.5
32
- name: activerecord
33
- prerelease: false
34
- type: :runtime
35
- requirement: *id001
36
- - !ruby/object:Gem::Dependency
37
- version_requirements: &id002 !ruby/object:Gem::Requirement
38
22
  none: false
39
23
  requirements:
40
24
  - - ">="
@@ -46,9 +30,9 @@ dependencies:
46
30
  name: shoulda
47
31
  prerelease: false
48
32
  type: :development
49
- requirement: *id002
33
+ requirement: *id001
50
34
  - !ruby/object:Gem::Dependency
51
- version_requirements: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
52
36
  none: false
53
37
  requirements:
54
38
  - - ~>
@@ -62,9 +46,9 @@ dependencies:
62
46
  name: bundler
63
47
  prerelease: false
64
48
  type: :development
65
- requirement: *id003
49
+ requirement: *id002
66
50
  - !ruby/object:Gem::Dependency
67
- version_requirements: &id004 !ruby/object:Gem::Requirement
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
68
52
  none: false
69
53
  requirements:
70
54
  - - ~>
@@ -78,9 +62,9 @@ dependencies:
78
62
  name: jeweler
79
63
  prerelease: false
80
64
  type: :development
81
- requirement: *id004
65
+ requirement: *id003
82
66
  - !ruby/object:Gem::Dependency
83
- version_requirements: &id005 !ruby/object:Gem::Requirement
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
84
68
  none: false
85
69
  requirements:
86
70
  - - ">="
@@ -92,9 +76,9 @@ dependencies:
92
76
  name: rcov
93
77
  prerelease: false
94
78
  type: :development
95
- requirement: *id005
79
+ requirement: *id004
96
80
  - !ruby/object:Gem::Dependency
97
- version_requirements: &id006 !ruby/object:Gem::Requirement
81
+ version_requirements: &id005 !ruby/object:Gem::Requirement
98
82
  none: false
99
83
  requirements:
100
84
  - - ">="
@@ -106,7 +90,7 @@ dependencies:
106
90
  name: rdoc
107
91
  prerelease: false
108
92
  type: :development
109
- requirement: *id006
93
+ requirement: *id005
110
94
  description: Great for creating seed data from data entered through your app's ui or the console
111
95
  email: renee.devoursney@gmail.com
112
96
  executables: []
@@ -128,6 +112,7 @@ files:
128
112
  - lib/timecapsule.rb
129
113
  - test/helper.rb
130
114
  - test/test_timecapsule.rb
115
+ - timecapsule.gemspec
131
116
  homepage: http://github.com/reneedv/timecapsule
132
117
  licenses:
133
118
  - MIT