legacy_migrations 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -0,0 +1,72 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{legacy_migrations}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Bernie Telles"]
12
+ s.date = %q{2010-03-15}
13
+ s.description = %q{Rails plugin for transferring or updating data between two db structures.}
14
+ s.email = %q{bernardo.telles@dms.myflorida.com}
15
+ s.extra_rdoc_files = [
16
+ "README"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "MIT-LICENSE",
21
+ "README",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "config/database.yml",
25
+ "install.rb",
26
+ "legacy_migrations.gemspec",
27
+ "lib/legacy_migrations.rb",
28
+ "lib/legacy_migrations/row_matchers.rb",
29
+ "lib/legacy_migrations/source_iterators.rb",
30
+ "lib/legacy_migrations/squirrel.rb",
31
+ "lib/legacy_migrations/squirrel/extensions.rb",
32
+ "lib/legacy_migrations/squirrel/paginator.rb",
33
+ "lib/legacy_migrations/squirrel/squirrel.rb",
34
+ "lib/legacy_migrations/transformations.rb",
35
+ "lib/legacy_migrations/validation_helper.rb",
36
+ "rails/init.rb",
37
+ "spec/db/schema.rb",
38
+ "spec/db/test.sqlite3",
39
+ "spec/legacy_migrations_spec.rb",
40
+ "spec/lib/transformations_spec.rb",
41
+ "spec/models.rb",
42
+ "spec/spec.opts",
43
+ "spec/spec_helper.rb",
44
+ "uninstall.rb"
45
+ ]
46
+ s.homepage = %q{http://github.com/btelles/legacy_migrations}
47
+ s.rdoc_options = ["--charset=UTF-8"]
48
+ s.require_paths = ["lib"]
49
+ s.rubygems_version = %q{1.3.5}
50
+ s.summary = %q{Rails plugin for transferring or updating data between two db structures.}
51
+ s.test_files = [
52
+ "spec/legacy_migrations_spec.rb",
53
+ "spec/lib/transformations_spec.rb",
54
+ "spec/models.rb",
55
+ "spec/spec_helper.rb",
56
+ "spec/db/schema.rb"
57
+ ]
58
+
59
+ if s.respond_to? :specification_version then
60
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
61
+ s.specification_version = 3
62
+
63
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
64
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
65
+ else
66
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
67
+ end
68
+ else
69
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
70
+ end
71
+ end
72
+
@@ -14,6 +14,9 @@ module LegacyMigrations
14
14
  # which is the value of the attribute in the _from_ parameter, then inserts the result of
15
15
  # the block into the destination attribute.
16
16
  # parameter and inserts the result of the block in the provided 'to' column.
17
+ # * <tt>:from_record</tt> - If you set the "from" column to "from_record",
18
+ # the variable passed into the block will be the entire from record,
19
+ # instead of just one of its columns
17
20
  def from(from_attribute, *args)
18
21
  options = args.extract_options!
19
22
 
@@ -25,7 +28,10 @@ module LegacyMigrations
25
28
  #anyone want to give this a try in another language? ;-)
26
29
  custom_method = Proc.new {|record|
27
30
  if if_method.call(record)
28
- if block_given?
31
+ case
32
+ when block_given? && from_attribute == :from_record
33
+ yield(record)
34
+ when block_given?
29
35
  yield(record.send(:[], from_attribute.to_s))
30
36
  else
31
37
  record.send(:[], from_attribute.to_s)
data/rails/init.rb ADDED
@@ -0,0 +1,4 @@
1
+ #We only want to load it when we really need it.
2
+ #This gem is intended to be used as part of a script,
3
+ #not part of an application
4
+ #require 'legacy_migrations'
@@ -41,6 +41,31 @@ describe LegacyMigrations do
41
41
  end
42
42
  Animal.all.count.should == 1
43
43
  end
44
+ it "rewinds an activerecord source" do
45
+ Person.create(:name => 'aoeu')
46
+ transfer_from Person, :to => Animal do
47
+ from :name, :to => :name
48
+ end
49
+ transfer_from Person, :to => Animal do
50
+ from :name, :to => :first_name
51
+ end
52
+ Animal.all.count.should == 2
53
+ Animal.find_by_name('aoeu').should be_instance_of(Animal)
54
+ Animal.find_by_first_name('aoeu').should be_instance_of(Animal)
55
+ end
56
+ it "rewinds a CSV source" do
57
+ person = "name,age\nalbert,123\nsmith,54"
58
+ person_csv = FasterCSV.parse(person, :headers => :first_row)
59
+ transfer_from person_csv, :to => Animal, :source_type => :csv do
60
+ from :name, :to => :name
61
+ end
62
+ transfer_from person_csv, :to => Animal, :source_type => :csv do
63
+ from :name, :to => :first_name
64
+ end
65
+ Animal.all.count.should == 4
66
+ Animal.find_by_name('albert').should be_instance_of(Animal)
67
+ Animal.find_by_first_name('albert').should be_instance_of(Animal)
68
+ end
44
69
  end
45
70
  describe 'update_from' do
46
71
  it "updates with simple column matching" do
@@ -28,6 +28,16 @@ describe "transformations" do
28
28
  Animal.first.first_name.should == nil
29
29
  Animal.first.name.should == 'my first name'
30
30
  end
31
+ it "allows user to use 'from_record' instead of column" do
32
+ Person.create(:name => 'my first name')
33
+ transfer_from Person, :to => Animal do
34
+ from :from_record, :to => :first_name do |from_record|
35
+ from_record.name.upcase
36
+ end
37
+ end
38
+ Animal.first.first_name.should == 'MY FIRST NAME'
39
+
40
+ end
31
41
  describe "match_same_name_attributes" do
32
42
  it "transfers same-name attributes" do
33
43
  Person.create(:name => 'same name')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legacy_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernie Telles
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-03-12 00:00:00 -05:00
12
+ date: 2010-03-15 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -33,10 +33,12 @@ extra_rdoc_files:
33
33
  files:
34
34
  - .gitignore
35
35
  - MIT-LICENSE
36
+ - README
36
37
  - Rakefile
37
38
  - VERSION
38
39
  - config/database.yml
39
40
  - install.rb
41
+ - legacy_migrations.gemspec
40
42
  - lib/legacy_migrations.rb
41
43
  - lib/legacy_migrations/row_matchers.rb
42
44
  - lib/legacy_migrations/source_iterators.rb
@@ -46,6 +48,7 @@ files:
46
48
  - lib/legacy_migrations/squirrel/squirrel.rb
47
49
  - lib/legacy_migrations/transformations.rb
48
50
  - lib/legacy_migrations/validation_helper.rb
51
+ - rails/init.rb
49
52
  - spec/db/schema.rb
50
53
  - spec/db/test.sqlite3
51
54
  - spec/legacy_migrations_spec.rb
@@ -54,7 +57,6 @@ files:
54
57
  - spec/spec.opts
55
58
  - spec/spec_helper.rb
56
59
  - uninstall.rb
57
- - README
58
60
  has_rdoc: true
59
61
  homepage: http://github.com/btelles/legacy_migrations
60
62
  licenses: []