mobility 0.1.1 → 0.1.2

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: 467aca5ee0a6e74cadac7d747155c0939f28d29a
4
- data.tar.gz: 3dc1bb58a099f817cbfc0485c6627a4c336fe76b
3
+ metadata.gz: aac3bb5bf5117b879aeeeea717cfd40bca0bbf55
4
+ data.tar.gz: 8348b8cd48048d74457084c434488abdb5ffc73f
5
5
  SHA512:
6
- metadata.gz: 0aaac38959f17591a70347eb5002a6df688964cb17c8b10225f7baf5eebb9f2fa540c98af4cfd34f681aa6e0bbf51c6718829b61d347313d5dd43e428f90484b
7
- data.tar.gz: 3d8a226d567fbe9fbe64ac62393127e8f92b8e04b789cc861ac0a4ea37894344ba6de440de9627ec11af48d17a41a89c335e593d81f407f00a25c7fab51338d6
6
+ metadata.gz: d7f75384116e3af82a6f6d6424a0bed7532fef85868939c050abe295495adbfb9addf118c47bde7087b30942c2edf201263bed57c7ecb38ab42b1e52a6275d95
7
+ data.tar.gz: de8f613e3047477e9ee5d2de368bb71cbb1d3a9101404f810d765f430dedd8db626b77403e46fba047ec1573e7eb751a45f4763bbf4fe5782c802d8b881fbbad
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Mobility Changelog
2
+
3
+ ## 0.1.2
4
+
5
+ * Fix issues with querying in ActiveRecord jsonb and hstore backends (758608294076249f1a66553c55531fc7897a71e3 and 5e6addd6f01cf255f5e71666324502ace96d3eac)
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mobility (0.0.1)
5
- i18n
4
+ mobility (0.1.1)
5
+ i18n (>= 0.6.10)
6
6
  request_store (~> 1.0)
7
7
 
8
8
  GEM
@@ -147,7 +147,7 @@ DEPENDENCIES
147
147
  rspec (~> 3.0)
148
148
  rspec-its (~> 1.2.0)
149
149
  sqlite3
150
- yard
150
+ yard (~> 0.9.0)
151
151
 
152
152
  BUNDLED WITH
153
153
  1.12.5
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # Mobility
2
+ ![Build Status](https://travis-ci.org/shioyama/mobility.svg?branch=master)
3
+
2
4
 
3
5
  Mobility is a gem for storing and retrieving localized data through attributes
4
6
  on a class. A variety of different storage strategies are supported through
@@ -499,7 +501,7 @@ To this end, Mobility backends strictly enforce the rule that *no backend
499
501
  should modify a parent class in any way which would interfere with other
500
502
  backends operating on the same class*. This is done using a heavy dose of
501
503
  metaprogramming, details of which can be found in the [API
502
- documentation](http://www.rubydoc.info/gems/mobility) and in the actual code.
504
+ documentation](http://www.rubydoc.info/gems/mobility/0.1.1) and in the actual code.
503
505
 
504
506
  In practice, this means that you can use different backends for different
505
507
  attributes *on the same class* without any conflict, e.g. (assuming we
@@ -579,7 +581,7 @@ end
579
581
 
580
582
  For details on how to define a backend class, see the {Mobility::Backend}
581
583
  module and other classes defined in the [API
582
- documentation](http://www.rubydoc.info/gems/mobility).
584
+ documentation](http://www.rubydoc.info/gems/mobility/0.1.1).
583
585
 
584
586
  ### Testing Backends
585
587
 
@@ -624,7 +626,7 @@ particular implementations.
624
626
  ## More Information
625
627
 
626
628
  - [Github repository](https://www.github.com/shioyama/mobility)
627
- - [API documentation](http://www.rubydoc.info/gems/mobility)
629
+ - [API documentation](http://www.rubydoc.info/gems/mobility/0.1.1)
628
630
 
629
631
  ## License
630
632
 
data/Rakefile CHANGED
@@ -18,6 +18,7 @@ namespace :db do
18
18
  require "database"
19
19
  driver = Mobility::Test::Database.driver
20
20
  config = Mobility::Test::Database.config[driver]
21
+ exit if config["database"] == ":memory:"
21
22
  commands = {
22
23
  "mysql" => "mysql -u #{config['username']} -e 'create database #{config["database"]};' >/dev/null",
23
24
  "postgres" => "psql -c 'create database #{config['database']};' -U #{config['username']} >/dev/null"
@@ -30,6 +31,7 @@ namespace :db do
30
31
  require "database"
31
32
  driver = Mobility::Test::Database.driver
32
33
  config = Mobility::Test::Database.config[driver]
34
+ exit if config["database"] == ":memory:"
33
35
  commands = {
34
36
  "mysql" => "mysql -u #{config['username']} -e 'drop database #{config["database"]};' >/dev/null",
35
37
  "postgres" => "psql -c 'drop database #{config['database']};' -U #{config['username']} >/dev/null"
@@ -39,6 +41,10 @@ namespace :db do
39
41
 
40
42
  desc "Set up the database schema"
41
43
  task :up => :load_path do
44
+ require "database"
45
+ driver = Mobility::Test::Database.driver
46
+ config = Mobility::Test::Database.config[driver]
47
+ exit if config["database"] == ":memory:"
42
48
  require "spec_helper"
43
49
  Mobility::Test::Schema.up
44
50
  end
@@ -7,19 +7,25 @@ module Mobility
7
7
 
8
8
  define_method :where! do |opts, *rest|
9
9
  if i18n_keys = attributes_extractor.call(opts)
10
- locale = Mobility.locale
10
+ m = arel_table
11
+ locale = Arel::Nodes.build_quoted(Mobility.locale.to_s)
11
12
  opts = opts.with_indifferent_access
13
+ infix = Arel::Nodes::InfixOperation
12
14
 
13
- result = i18n_keys.inject(all) do |scope, attr|
15
+ i18n_query = i18n_keys.inject(nil) { |ops, attr|
16
+ column = m[attr.to_sym]
14
17
  value = opts.delete(attr)
15
- if value.nil?
16
- scope.where.not("#{table_name}.#{attr} ? '#{locale}'")
17
- else
18
- scope.where!("#{table_name}.#{attr} @> hstore('#{locale}', ?)", value.to_s)
19
- end
20
- end
21
- result = result.where!(opts, *rest) if opts.present?
22
- result
18
+
19
+ op =
20
+ if value.nil?
21
+ infix.new(:'?', column, locale).not
22
+ else
23
+ infix.new(:'->', m[attr.to_sym], locale).eq(value)
24
+ end
25
+ ops ? ops.and(op) : op
26
+ }
27
+
28
+ opts.empty? ? where(i18n_query) : super(opts, *rest).where(i18n_query)
23
29
  else
24
30
  super(opts, *rest)
25
31
  end
@@ -29,18 +35,25 @@ module Mobility
29
35
  def extended(relation)
30
36
  super
31
37
  attributes_extractor = @attributes_extractor
32
- table_name = relation.model.table_name
38
+ m = relation.model.arel_table
33
39
 
34
40
  mod = Module.new do
35
41
  define_method :not do |opts, *rest|
36
42
  if i18n_keys = attributes_extractor.call(opts)
37
- locale = Mobility.locale
43
+ locale = Arel::Nodes.build_quoted(Mobility.locale.to_s)
38
44
  opts = opts.with_indifferent_access
45
+ infix = Arel::Nodes::InfixOperation
46
+
47
+ i18n_query = i18n_keys.inject(nil) { |ops, attr|
48
+ column = m[attr.to_sym]
49
+ value = Arel::Nodes.build_quoted(opts.delete(attr).to_s)
50
+ has_key = infix.new(:'?', column, locale)
51
+ not_eq_value = infix.new(:'->', column, locale).not_eq(value)
52
+ op = has_key.and(not_eq_value)
53
+ ops ? ops.and(op) : op
54
+ }
39
55
 
40
- i18n_keys.inject(relation) { |scope, attr|
41
- scope.where!("#{table_name}.#{attr} ? '#{locale}'").
42
- where.not("#{table_name}.#{attr} @> hstore('#{locale}', ?)", opts.delete(attr).to_s)
43
- }.where.not(opts, *rest)
56
+ super(opts, *rest).where(i18n_query)
44
57
  else
45
58
  super(opts, *rest)
46
59
  end
@@ -7,19 +7,26 @@ module Mobility
7
7
 
8
8
  define_method :where! do |opts, *rest|
9
9
  if i18n_keys = attributes_extractor.call(opts)
10
- locale = Mobility.locale
10
+ m = arel_table
11
+ locale = Arel::Nodes.build_quoted(Mobility.locale.to_s)
11
12
  opts = opts.with_indifferent_access
13
+ infix = Arel::Nodes::InfixOperation
12
14
 
13
- result = i18n_keys.inject(all) do |scope, attr|
15
+ i18n_query = i18n_keys.inject(nil) { |ops, attr|
16
+ column = m[attr.to_sym]
14
17
  value = opts.delete(attr)
15
- if value.nil?
16
- scope.where.not("#{table_name}.#{attr} ? :locale", locale: locale)
17
- else
18
- scope.where!("#{table_name}.#{attr} @> (?)::jsonb", { locale => value }.to_json)
19
- end
20
- end
21
- result = result.where!(opts, *rest) if opts.present?
22
- result
18
+
19
+ op =
20
+ if value.nil?
21
+ infix.new(:'?', column, locale).not
22
+ else
23
+ predicate = Arel::Nodes.build_quoted({ Mobility.locale => value }.to_json)
24
+ infix.new(:'@>', m[attr.to_sym], predicate)
25
+ end
26
+ ops ? ops.and(op) : op
27
+ }
28
+
29
+ opts.empty? ? where(i18n_query) : super(opts, *rest).where(i18n_query)
23
30
  else
24
31
  super(opts, *rest)
25
32
  end
@@ -29,18 +36,25 @@ module Mobility
29
36
  def extended(relation)
30
37
  super
31
38
  attributes_extractor = @attributes_extractor
32
- table_name = relation.model.table_name
39
+ m = relation.model.arel_table
33
40
 
34
41
  mod = Module.new do
35
42
  define_method :not do |opts, *rest|
36
43
  if i18n_keys = attributes_extractor.call(opts)
37
- locale = Mobility.locale
44
+ locale = Arel::Nodes.build_quoted(Mobility.locale.to_s)
38
45
  opts = opts.with_indifferent_access
46
+ infix = Arel::Nodes::InfixOperation
47
+
48
+ i18n_query = i18n_keys.inject(nil) { |ops, attr|
49
+ column = m[attr.to_sym]
50
+ has_key = infix.new(:'?', column, locale)
51
+ predicate = Arel::Nodes.build_quoted({ Mobility.locale => opts.delete(attr) }.to_json)
52
+ not_eq_value = infix.new(:'@>', m[attr.to_sym], predicate).not
53
+ op = has_key.and(not_eq_value)
54
+ ops ? ops.and(op) : op
55
+ }
39
56
 
40
- i18n_keys.inject(relation) { |scope, attr|
41
- scope.where!("#{table_name}.#{attr} ? :locale", locale: locale).
42
- where.not("#{table_name}.#{attr} @> (?)::jsonb", { locale => opts.delete(attr) }.to_json)
43
- }.where.not(opts, *rest)
57
+ super(opts, *rest).where(i18n_query)
44
58
  else
45
59
  super(opts, *rest)
46
60
  end
@@ -1,3 +1,3 @@
1
1
  module Mobility
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobility
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Salzberg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-22 00:00:00.000000000 Z
11
+ date: 2017-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: request_store
@@ -130,6 +130,7 @@ executables: []
130
130
  extensions: []
131
131
  extra_rdoc_files: []
132
132
  files:
133
+ - CHANGELOG.md
133
134
  - Gemfile
134
135
  - Gemfile.lock
135
136
  - Guardfile