ae_users_migrator 1.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/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg/*
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Nat Budin
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,17 @@
1
+ = ae_users_migrator
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Nat Budin. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "ae_users_migrator"
8
+ gem.summary = %Q{Migrate ae_users installations using dumpfiles}
9
+ gem.description = %Q{Importer and exporter for ae_users databases using JSON-based dumpfiles}
10
+ gem.email = "natbudin@gmail.com"
11
+ gem.homepage = "http://github.com/nbudin/ae_users_migrator"
12
+ gem.authors = ["Nat Budin"]
13
+ gem.bindir = "bin"
14
+ gem.add_dependency("activerecord", ">= 2.3")
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "ae_users_migrator #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,52 @@
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{ae_users_migrator}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Nat Budin"]
12
+ s.date = %q{2010-06-29}
13
+ s.default_executable = %q{export_ae_users}
14
+ s.description = %q{Importer and exporter for ae_users databases using JSON-based dumpfiles}
15
+ s.email = %q{natbudin@gmail.com}
16
+ s.executables = ["export_ae_users"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "ae_users_migrator.gemspec",
28
+ "bin/export_ae_users",
29
+ "lib/ae_users_migrator.rb",
30
+ "lib/ae_users_migrator/export.rb",
31
+ "lib/ae_users_migrator/import.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/nbudin/ae_users_migrator}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.7}
37
+ s.summary = %q{Migrate ae_users installations using dumpfiles}
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<activerecord>, [">= 2.3"])
45
+ else
46
+ s.add_dependency(%q<activerecord>, [">= 2.3"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<activerecord>, [">= 2.3"])
50
+ end
51
+ end
52
+
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+
5
+ options = {
6
+ :adapter => "mysql",
7
+ :host => "localhost",
8
+ :username => "root",
9
+ :database => "ae_users"
10
+ }
11
+
12
+ OptionParser.new do |opts|
13
+ opts.banner = "Usage: export_ae_users [options]"
14
+
15
+ opts.on("-a", "--adapter ADAPTER", "ActiveRecord database adapter") do |a|
16
+ options[:adapter] = a
17
+ end
18
+
19
+ opts.on("-u", "--username USERNAME", "Database username") do |u|
20
+ options[:username] = u
21
+ end
22
+
23
+ opts.on("-p", "--password PASSWORD", "Database password") do |p|
24
+ options[:password] = p
25
+ end
26
+
27
+ opts.on("-d", "--database DATABASE", "Database to connect to") do |d|
28
+ options[:database] = d
29
+ end
30
+ end.parse!
31
+
32
+ require 'rubygems'
33
+ require 'active_record'
34
+
35
+ ActiveRecord::Base.establish_connection(options)
36
+
37
+ require 'ae_users_migrator/export'
38
+
39
+ puts AeUsersMigrator::Export::Person.includes(:email_addresses, :account, :open_id_identities, :roles).all.to_json
@@ -0,0 +1,38 @@
1
+ require 'active_record'
2
+
3
+ module AeUsersMigrator
4
+ module Export
5
+ class Account < ActiveRecord::Base
6
+ belongs_to :person
7
+ end
8
+
9
+ class EmailAddress < ActiveRecord::Base
10
+ belongs_to :person
11
+ end
12
+
13
+ class OpenIdIdentity < ActiveRecord::Base
14
+ belongs_to :person
15
+ end
16
+
17
+ class Person < ActiveRecord::Base
18
+ has_many :email_addresses
19
+ has_one :account
20
+ has_many :open_id_identities
21
+ has_and_belongs_to_many :roles
22
+
23
+ def as_json(options = {})
24
+ json = super(options)
25
+
26
+ %w{email_addresses account open_id_identities roles}.each do |assn|
27
+ json[assn] = self.send(assn).as_json
28
+ end
29
+
30
+ json
31
+ end
32
+ end
33
+
34
+ class Role < ActiveRecord::Base
35
+ has_and_belongs_to_many :people
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,96 @@
1
+ require 'json'
2
+
3
+ module AeUsersMigrator
4
+ module Import
5
+ class EmailAddress
6
+ attr_accessor :address, :created_at, :updated_at, :primary, :id
7
+
8
+ def initialize(json)
9
+ %w{address created_at updated_at primary id}.each do |f|
10
+ self.send("#{f}=", json[f])
11
+ end
12
+ end
13
+ end
14
+
15
+ class OpenIdIdentity
16
+ attr_accessor :id, :identity_url
17
+
18
+ def initialize(json)
19
+ %w{id identity_url}.each do |f|
20
+ self.send("#{f}=", json[f])
21
+ end
22
+ end
23
+ end
24
+
25
+ class Account
26
+ attr_accessor :activation_key, :created_at, :updated_at, :id, :password, :active
27
+
28
+ def initialize(json)
29
+ %w{activation_key created_at updated_at id password active}.each do |f|
30
+ self.send("#{f}=", json[f])
31
+ end
32
+ end
33
+ end
34
+
35
+ class Role
36
+ attr_accessor :name
37
+
38
+ def initialize(json)
39
+ self.name = json["name"]
40
+ end
41
+ end
42
+
43
+ class Person
44
+ attr_reader :email_addresses, :open_id_identities, :account, :roles
45
+ attr_accessor :nickname, :birthdate, :gender, :id, :firstname, :lastname, :phone, :best_call_time
46
+
47
+ def initialize(json)
48
+ @email_addresses = json["email_addresses"].collect do |ea_record|
49
+ EmailAddress.new(ea_record["email_address"])
50
+ end
51
+
52
+ @open_id_identities = json["open_id_identities"].collect do |oid_record|
53
+ OpenIdIdentity.new(oid_record["open_id_identity"])
54
+ end
55
+
56
+ @roles = json["roles"].collect do |role_record|
57
+ Role.new(role_record["role"])
58
+ end
59
+
60
+ if json["account"]
61
+ @account = Account.new(json["account"]["account"])
62
+ end
63
+
64
+ %w{nickname birthdate gender id firstname lastname phone best_call_time}.each do |f|
65
+ self.send("#{f}=", json[f])
66
+ end
67
+ end
68
+
69
+ def primary_email_address
70
+ @email_addresses.select { |ea| ea.primary }.first || @email_addresses.first
71
+ end
72
+ end
73
+
74
+ class Dumpfile
75
+ attr_reader :people
76
+
77
+ def initialize
78
+ @people = {}
79
+ end
80
+
81
+ def self.load(file)
82
+ json = JSON.load(file)
83
+ df = Dumpfile.new
84
+
85
+ json.each do |item|
86
+ if item["person"]
87
+ p = Person.new(item["person"])
88
+ df.people[p.id] = p
89
+ end
90
+ end
91
+
92
+ return df
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1 @@
1
+
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ae_users_migrator
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Nat Budin
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-29 00:00:00 -04:00
19
+ default_executable: export_ae_users
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activerecord
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 2
32
+ - 3
33
+ version: "2.3"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: Importer and exporter for ae_users databases using JSON-based dumpfiles
37
+ email: natbudin@gmail.com
38
+ executables:
39
+ - export_ae_users
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - LICENSE
44
+ - README.rdoc
45
+ files:
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - ae_users_migrator.gemspec
52
+ - bin/export_ae_users
53
+ - lib/ae_users_migrator.rb
54
+ - lib/ae_users_migrator/export.rb
55
+ - lib/ae_users_migrator/import.rb
56
+ has_rdoc: true
57
+ homepage: http://github.com/nbudin/ae_users_migrator
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options:
62
+ - --charset=UTF-8
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ hash: 3
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ requirements: []
84
+
85
+ rubyforge_project:
86
+ rubygems_version: 1.3.7
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Migrate ae_users installations using dumpfiles
90
+ test_files: []
91
+