rare_map 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2a5bcbd97c37310f2e809a4328490c44076bd06
4
- data.tar.gz: f7fb2de31bbf07022673ad8a3e4655351f902e8a
3
+ metadata.gz: ce41eb2694e40a8af776fc9d0063284b6e8fed12
4
+ data.tar.gz: cd2b3b1c7c63e4100e4ed28f7d3f710631396cc6
5
5
  SHA512:
6
- metadata.gz: 839fb36c3ea95902213b7b2507ba2231b1238cee119fc9703a44af158b948d9add23725f2208f992623e7f472e7c1eefb94c23cce6e108435733f2da77044d1c
7
- data.tar.gz: 8c1f2ccfe9102b00e9b43f03004a16a5f8e2e141e79cd107f7b0d5e3bd16c7fda53122dc2e4abd92d37d920e5c0976817bfa3c8c8b888b24297188cc4ec44186
6
+ metadata.gz: b3d822835a7f7659db9e15aeb2657a592d7f646db4d529424efcb0ba3ca04742f0c66ca9b0f8cd7a2640f4c6c4e457f90a7e804bba384481285418da443293cc
7
+ data.tar.gz: d801ec96e6805e140d01ed8d9e01db4e9d4481c5999320a4e8c9a36267ff8d9fc6495ef7d58e4617a5e5f4d4328c61bb1febb0bd9dd20e788911606c29b060c5
@@ -1,4 +1,4 @@
1
- Copyright 2012 Wei-Ming Wu
1
+ Copyright 2013 Wei-Ming Wu
2
2
 
3
3
  Licensed under the Apache License, Version 2.0 (the "License"); you
4
4
  may not use this file except in compliance with the License. You may
@@ -0,0 +1,134 @@
1
+ [![Gem Version](https://badge.fury.io/rb/rare_map.png)](http://badge.fury.io/rb/rare_map)
2
+
3
+ rare_map
4
+ =============
5
+
6
+ Relational db to ActiveREcord models MAPper
7
+
8
+ RareMap can be used for BOTH standalone application & Rails
9
+
10
+ #### Installation:
11
+ ```ruby
12
+ gem install rare_map
13
+ ```
14
+
15
+ Basic RareMap Usage
16
+ -------------
17
+
18
+ #### Standalone:
19
+ Create a new rare_map.yml with following lines in the root of your application
20
+
21
+ #### Rails:
22
+ Create a new config/rare_map.yml with following lines in rails
23
+
24
+ rare_map.yml:
25
+ ```yaml
26
+ legacy:
27
+ adapter: sqlite3
28
+ database: db/db1.sqlite3
29
+
30
+ old_db:
31
+ adapter: mysql2
32
+ host: localhost
33
+ database: db_name
34
+ port: 3306
35
+ username: user
36
+ password: pw
37
+ ```
38
+
39
+ Run following command in the root of your application or rails
40
+ ```
41
+ $ raremap
42
+ ```
43
+
44
+ Standalone: A demo.rb example is generated for you in the root of your application
45
+
46
+ RareMap console which is like rails console for standalone app can be run by following command
47
+ ```
48
+ $ raremap console # or simply run `raremap c`
49
+ ```
50
+
51
+ Advanced RareMap Usage
52
+ -------------
53
+
54
+ #### Seperate databases into groups (highly recommended)
55
+ ```yaml
56
+ her_group:
57
+ -
58
+ db1:
59
+ adapter: sqlite3
60
+ database: db/db1.sqlite3
61
+ -
62
+ db2:
63
+ adapter: sqlite3
64
+ database: db/db1.sqlite3
65
+
66
+ his_group:
67
+ -
68
+ db1:
69
+ adapter: sqlite3
70
+ database: db/db3.sqlite3
71
+ -
72
+ db2:
73
+ adapter: sqlite3
74
+ database: db/db4.sqlite3
75
+ ````
76
+
77
+ There are benefits by separating databases into groups:
78
+
79
+ 1. Associations are built between databases within a group
80
+
81
+ 2. Group name is treated as a module namespace
82
+
83
+ 3. Models of a group are organized within a folder
84
+
85
+ If all your data reside in several legacy databases, it is important to build back those associations across databases
86
+
87
+ If there are 2 or more tables with the same name, giving them group names could avoid naming collision
88
+
89
+ If there are tons of tables, it is better to organize them well
90
+
91
+
92
+ #### Set up RareMap Options
93
+ ```yaml
94
+ rare_map_opts:
95
+ foreign_key:
96
+ suffix: fk
97
+ alias:
98
+ abnormal_fk1: table1
99
+ abnormal_fk2: table2
100
+ primary_key:
101
+ table1: abnormal_pk
102
+ ```
103
+
104
+ * rare_map_opts[foreign_key][suffix]: If your foreign keys are not ended with 'id', you can specify the suffix you want here
105
+ * rare_map_opts[foreign_key][alias]: If naming convention is not followed by some foreign keys, you can list them here
106
+ * rare_map_opts[primary_key]: Usually rare_map can identify the primary key of a table, if it fails, please list primary keys here
107
+
108
+ #### RareMap Options Precedence
109
+
110
+ You can place rare_map options in 3 ways
111
+ ```yaml
112
+ rare_map_opts: # Global options
113
+ ...
114
+ group1:
115
+ -
116
+ rare_map_opts: # Group options
117
+ ...
118
+ -
119
+ db1:
120
+ ...
121
+ legacy_db:
122
+ adapter: sqlite3
123
+ database: db/db.sqlite3
124
+ rare_map_opts: # DB options
125
+ ...
126
+ ```
127
+ Precedence: DB > Group > Global
128
+
129
+
130
+ ## Copyright
131
+
132
+ Copyright (c) 2013 Wei-Ming Wu. See LICENSE.txt for
133
+ further details.
134
+
@@ -43,9 +43,9 @@ module RareMap
43
43
 
44
44
  candidates = @columns.find_all { |col| col.unique }.map { |col| col.name }
45
45
  return 'id' if candidates.include? 'id'
46
- candidates.find { |c| c =~ eval("/^#{@name}.*id$/") } ||
47
- candidates.find { |c| c =~ eval("/^#{singularize}.*id$/") } ||
48
- candidates.find { |c| c =~ eval("/^#{pluralize}.*id$/") } ||
46
+ candidates.find { |c| c =~ eval("/^#{@name}.*id$/i") } ||
47
+ candidates.find { |c| c =~ eval("/^#{singularize}.*id$/i") } ||
48
+ candidates.find { |c| c =~ eval("/^#{pluralize}.*id$/i") } ||
49
49
  candidates.first
50
50
  end
51
51
 
@@ -67,7 +67,7 @@ module RareMap
67
67
  #
68
68
  # @return [String, nil] the name of this Table if given Column matched, nil otherwise
69
69
  def match_foreign_key(column)
70
- if column.ref_table == @name || foreign_keys.include?(column.name)
70
+ if column.ref_table == @name || foreign_keys.include?(column.name.downcase)
71
71
  @name if primary_key
72
72
  end
73
73
  end
@@ -76,14 +76,15 @@ module RareMap
76
76
  #
77
77
  # @return [String, nil] the name of this Table if given primary key matched, nil otherwise
78
78
  def match_foreign_key_by_primary_key(pk)
79
- @name if foreign_keys.include?(pk) && primary_key
79
+ @name if foreign_keys.include?(pk.to_s.downcase) && primary_key
80
80
  end
81
81
 
82
82
  private
83
83
 
84
84
  def foreign_keys
85
- ["#{@name}_#{fk_suffix}", "#{@name}#{fk_suffix}", "#{singularize}_#{fk_suffix}",
86
- "#{singularize}#{fk_suffix}", "#{pluralize}_#{fk_suffix}", "#{pluralize}#{fk_suffix}"]
85
+ ["#{@name}_#{fk_suffix}", "#{@name}#{fk_suffix}",
86
+ "#{singularize}_#{fk_suffix}", "#{singularize}#{fk_suffix}",
87
+ "#{pluralize}_#{fk_suffix}", "#{pluralize}#{fk_suffix}"].map(&:downcase)
87
88
  end
88
89
  end
89
90
  end
@@ -4,7 +4,7 @@ module RareMap
4
4
  # The minor version of RareMap
5
5
  MINOR = 2
6
6
  # The patch version of RareMap
7
- PATCH = 0
7
+ PATCH = 1
8
8
 
9
9
  # The version of RareMap
10
10
  VERSION = [MAJOR, MINOR, PATCH].compact.join('.')
@@ -44,8 +44,16 @@ class TableTest < Test::Unit::TestCase
44
44
  assert_equal nil, @Table.match_foreign_key(RareMap::Column.new('table2_id', 'integer'))
45
45
  end
46
46
 
47
+ def test_match_foreign_key_case_insensitively
48
+ assert_equal 'table1', @Table.match_foreign_key(RareMap::Column.new('Table1_ID', 'integer'))
49
+ end
50
+
47
51
  def test_match_foreign_key_by_primary_key
48
52
  assert_equal 'table1', @Table.match_foreign_key_by_primary_key('table1_id')
49
53
  assert_equal nil, @Table.match_foreign_key_by_primary_key('table2_id')
50
54
  end
55
+
56
+ def test_match_foreign_key_by_primary_key_case_insensitively
57
+ assert_equal 'table1', @Table.match_foreign_key_by_primary_key('Table1_ID')
58
+ end
51
59
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rare_map
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wei-Ming Wu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-11 00:00:00.000000000 Z
11
+ date: 2013-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -118,7 +118,7 @@ files:
118
118
  - lib/rare_map.rb
119
119
  - LICENSE.txt
120
120
  - Rakefile
121
- - README.rdoc
121
+ - README.md
122
122
  - test/column_test.rb
123
123
  - test/config_loader_test.rb
124
124
  - test/database_profile_test.rb
@@ -158,7 +158,7 @@ rubyforge_project:
158
158
  rubygems_version: 2.0.6
159
159
  signing_key:
160
160
  specification_version: 4
161
- summary: rare_map-2.2.0
161
+ summary: rare_map-2.2.1
162
162
  test_files:
163
163
  - test/column_test.rb
164
164
  - test/config_loader_test.rb
@@ -1,128 +0,0 @@
1
- = rare_map >= 2.0.0
2
-
3
- Relational db to ActiveREcord models MAPper
4
-
5
- RareMap can be used for BOTH standalone application & Rails
6
-
7
- * Installation:
8
-
9
- gem install rare_map
10
-
11
- == Basic RareMap use
12
-
13
- ==== Standalone:
14
- Create a new rare_map.yml with following lines in the root of your application
15
-
16
- ==== Rails:
17
- Create a new config/rare_map.yml with following lines in rails
18
-
19
- * rare_map.yml
20
-
21
- legacy:
22
- adapter: sqlite3
23
- database: db/db1.sqlite3
24
-
25
- old_db:
26
- adapter: mysql2
27
- host: localhost
28
- database: db_name
29
- port: 3306
30
- username: user
31
- password: pw
32
-
33
- * Run following command in the root of your application or rails
34
-
35
- $ raremap
36
-
37
- * Standalone: A demo.rb example is generated for you in the root of your application
38
- * RareMap console which is like rails console for standalone app can be run by following command
39
-
40
- $ raremap console # or simply run `raremap c`
41
-
42
- == Advanced RareMap use
43
-
44
- ==== Seperate databases into groups (highly recommended)
45
-
46
- her_group:
47
- -
48
- db1:
49
- adapter: sqlite3
50
- database: db/db1.sqlite3
51
- -
52
- db2:
53
- adapter: sqlite3
54
- database: db/db1.sqlite3
55
-
56
- his_group:
57
- -
58
- db1:
59
- adapter: sqlite3
60
- database: db/db3.sqlite3
61
- -
62
- db2:
63
- adapter: sqlite3
64
- database: db/db4.sqlite3
65
-
66
- There are benefits by separating databases into groups
67
- 1. Associations are built between databases within a group
68
- 2. Group name is treated as a module namespace
69
- 3. Models of a group are organized within a folder
70
-
71
- If all your data reside in several legacy databases, it is important to build back those associations across databases
72
-
73
- If there are 2 or more tables with the same name, giving them group names could avoid naming collision
74
-
75
- If there are tons of tables, it is better to organize them well
76
-
77
-
78
- ==== Set up RareMap Options
79
- rare_map_opts:
80
- foreign_key:
81
- suffix: fk
82
- alias:
83
- abnormal_fk1: table1
84
- abnormal_fk2: table2
85
- primary_key:
86
- table1: abnormal_pk
87
-
88
- * rare_map_opts[foreign_key][suffix]: If your foreign keys are not ended with 'id', you can specify the suffix you want here
89
- * rare_map_opts[foreign_key][alias]: If naming convention is not followed by some foreign keys, you can list them here
90
- * rare_map_opts[primary_key]: Usually rare_map can identify the primary key of a table, if it fails, please list primary keys here
91
-
92
- ==== RareMap Options Precedence
93
-
94
- You can place rare_map options in 3 ways
95
-
96
- rare_map_opts: # Global options
97
- ...
98
- group1:
99
- -
100
- rare_map_opts: # Group options
101
- ...
102
- -
103
- db1:
104
- ...
105
- legacy_db:
106
- adapter: sqlite3
107
- database: db/db.sqlite3
108
- rare_map_opts: # DB options
109
- ...
110
-
111
- * Precedence: DB > Group > Global
112
-
113
-
114
- == Contributing to rare_map
115
-
116
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
117
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
118
- * Fork the project.
119
- * Start a feature/bugfix branch.
120
- * Commit and push until you are happy with your contribution.
121
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
122
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
123
-
124
- == Copyright
125
-
126
- Copyright (c) 2012 Wei-Ming Wu. See LICENSE.txt for
127
- further details.
128
-