mobility 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +3 -3
- data/README.md +5 -3
- data/Rakefile +6 -0
- data/lib/mobility/backend/active_record/hstore/query_methods.rb +29 -16
- data/lib/mobility/backend/active_record/jsonb/query_methods.rb +30 -16
- data/lib/mobility/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aac3bb5bf5117b879aeeeea717cfd40bca0bbf55
|
4
|
+
data.tar.gz: 8348b8cd48048d74457084c434488abdb5ffc73f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7f75384116e3af82a6f6d6424a0bed7532fef85868939c050abe295495adbfb9addf118c47bde7087b30942c2edf201263bed57c7ecb38ab42b1e52a6275d95
|
7
|
+
data.tar.gz: de8f613e3047477e9ee5d2de368bb71cbb1d3a9101404f810d765f430dedd8db626b77403e46fba047ec1573e7eb751a45f4763bbf4fe5782c802d8b881fbbad
|
data/CHANGELOG.md
ADDED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mobility (0.
|
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
|
+

|
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
|
-
|
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
|
-
|
15
|
+
i18n_query = i18n_keys.inject(nil) { |ops, attr|
|
16
|
+
column = m[attr.to_sym]
|
14
17
|
value = opts.delete(attr)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
15
|
+
i18n_query = i18n_keys.inject(nil) { |ops, attr|
|
16
|
+
column = m[attr.to_sym]
|
14
17
|
value = opts.delete(attr)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/mobility/version.rb
CHANGED
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.
|
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-
|
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
|