rmap 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/rmap/table.rb +16 -5
  2. data/lib/rmap/version.rb +1 -1
  3. metadata +10 -10
@@ -89,7 +89,7 @@ module Rmap
89
89
  elsif column?(name.to_s.sub(/=\Z/, "")) && name.match(/\A(.*)=\Z/)
90
90
  all.each{|row| row.update($1 => args[0])}
91
91
  elsif name.match /\A(.*?)_(#{BINARY_FILTER_METHODS.keys.join('|')})\Z/
92
- @binary_filter_methods_args[$2].push([$1,args[0]])
92
+ @binary_filter_methods_args[$2].push([$1.split(/_or_/),args[0]])
93
93
  self
94
94
  else
95
95
  super
@@ -171,10 +171,10 @@ module Rmap
171
171
  "#{table1.name}.#{foreign_key} = #{table2.name}.id"
172
172
  end
173
173
  else
174
- if table2.column? "#{table1.name.to_s.gsub(/ies\Z/, "y").gsub(/s\Z/, "")}_id"
175
- "#{table1.name}.id = #{table2.name.to_s.gsub(/ies\Z/, "y").gsub(/s\Z/, "")}.#{table1.name}_id"
174
+ if table2.column? "#{to_singular(table1.name)}_id"
175
+ "#{table1.name}.id = #{to_singular(table2.name)}.#{table1.name}_id"
176
176
  else
177
- "#{table1.name}.#{table2.name.to_s.gsub(/ies\Z/, "y").gsub(/s\Z/, "")}_id = #{table2.name}.id"
177
+ "#{table1.name}.#{to_singular(table2.name)}_id = #{table2.name}.id"
178
178
  end
179
179
  end
180
180
  end
@@ -318,7 +318,6 @@ module Rmap
318
318
  @database.client.query("alter table `#{@name}` drop `#{name}`")
319
319
  end
320
320
 
321
-
322
321
  def column_names
323
322
  @database.client.query("describe `#{@name}`", :as => :hash).map {|row| row['Field']}
324
323
  end
@@ -327,5 +326,17 @@ module Rmap
327
326
  all.to_s
328
327
  end
329
328
 
329
+ private
330
+
331
+ def to_singular(value)
332
+ if value.to_s.match /\A(.*)ies\Z/
333
+ "#{$1}y"
334
+ elsif value.to_s.match /\A(.*ss)es\Z/
335
+ $1
336
+ else
337
+ value.to_s.gsub(/s\Z/, "")
338
+ end
339
+ end
340
+
330
341
  end
331
342
  end
@@ -1,3 +1,3 @@
1
1
  module Rmap
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-10 00:00:00.000000000Z
12
+ date: 2012-05-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mysql2
16
- requirement: &74039820 !ruby/object:Gem::Requirement
16
+ requirement: &78471470 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *74039820
24
+ version_requirements: *78471470
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &74039570 !ruby/object:Gem::Requirement
27
+ requirement: &78471220 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *74039570
35
+ version_requirements: *78471220
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ripl
38
- requirement: &74039340 !ruby/object:Gem::Requirement
38
+ requirement: &78470990 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *74039340
46
+ version_requirements: *78470990
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: ripl-multi_line
49
- requirement: &74039110 !ruby/object:Gem::Requirement
49
+ requirement: &78470760 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *74039110
57
+ version_requirements: *78470760
58
58
  description:
59
59
  email:
60
60
  - jody@jodysalt.com