push_type_core 0.5.0 → 0.5.1
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/app/fields/push_type/tag_list_field.rb +60 -4
- data/lib/push_type/version.rb +1 -1
- data/test/dummy/config/initializers/push_type.rb +1 -1
- data/test/dummy/config/secrets.yml +2 -2
- data/test/dummy/db/migrate/{20150716155017_create_push_type_users.push_type.rb → 20150816155440_create_push_type_users.push_type.rb} +0 -0
- data/test/dummy/db/migrate/{20150716155018_create_push_type_nodes.push_type.rb → 20150816155441_create_push_type_nodes.push_type.rb} +0 -0
- data/test/dummy/db/migrate/{20150716155019_create_push_type_node_hierarchies.push_type.rb → 20150816155442_create_push_type_node_hierarchies.push_type.rb} +0 -0
- data/test/dummy/db/migrate/{20150716155020_create_push_type_assets.push_type.rb → 20150816155443_create_push_type_assets.push_type.rb} +0 -0
- data/test/dummy/db/migrate/{20150716155021_create_push_type_taxonomies.push_type.rb → 20150816155444_create_push_type_taxonomies.push_type.rb} +0 -0
- data/test/dummy/db/migrate/{20150716155022_create_push_type_taxonomy_hierarchies.push_type.rb → 20150816155445_create_push_type_taxonomy_hierarchies.push_type.rb} +0 -0
- data/test/dummy/db/migrate/{20150716155023_add_field_store_default_values.push_type.rb → 20150816155446_add_field_store_default_values.push_type.rb} +0 -0
- data/test/dummy/db/schema.rb +1 -1
- data/test/dummy/log/test.log +6465 -5452
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/{DIGO2XX0gV_Ebgs43ap-65y0MyrcySF3iz56xum2NCQ.cache → W8pDH0KBIZeASFfhb6FcCvgBnw5mwDr_n-_mL7uyJCg.cache} +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/{0tutfZEltPbqMrjMJpcgLOWDEBEA1_i4wAlgfGmDMaM.cache → XZ5YMTEXVVS0qOmL43QbUr0VO27mRh-7fqzgzfV5Ulc.cache} +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/g97nJc5YmnbscVR5pZZoxgfj652ml7dLjUIu0FHDwLA.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/vlJujjzOikOTUvCvT3C4o3vK0ySfxbQQ3RBE37vXH0U.cache +0 -0
- data/test/dummy/tmp/generators/app/models/home_page.rb +12 -0
- data/test/dummy/tmp/generators/app/views/nodes/home_page.html.erb +13 -0
- data/test/fields/push_type/tag_list_field_test.rb +29 -4
- metadata +28 -31
- data/lib/push_type/tag_list_query.rb +0 -38
- data/test/dummy/tmp/generators/config/initializers/push_type.rb +0 -38
- data/test/dummy/tmp/generators/config/routes.rb +0 -59
- data/test/lib/push_type/tag_list_query_test.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16d0e6e76e9303633cd1eeae3cf04f46bfddacdd
|
4
|
+
data.tar.gz: cfd2d279b8ea9c0b1795aac50ede8807a45fe10a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 179816006e6ef88d2e7bbaaa1fd69234b19a88f715e450197eaed905730660dfaf455711fd14389cf16257b6710d08b2504fe34e2882e70236a7778294bc6858
|
7
|
+
data.tar.gz: a33b0d15e08c116d449b76d804384276b6f88db9b2428aa619667a3c6beff46ea1686f9c72b3d1a0e2154844a0acfc2014b3ca80e8b9541237b6633dad743a70
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'push_type/tag_list_query'
|
2
|
-
|
3
1
|
module PushType
|
4
2
|
class TagListField < PushType::FieldType
|
5
3
|
|
@@ -12,8 +10,66 @@ module PushType
|
|
12
10
|
end
|
13
11
|
|
14
12
|
initialized_on_node do |object, field|
|
15
|
-
|
16
|
-
|
13
|
+
|
14
|
+
object.class_eval do
|
15
|
+
|
16
|
+
# Dynamically define standard scope .with_all_`field_name`
|
17
|
+
# Returns ActiveRecord::Relation
|
18
|
+
#
|
19
|
+
scope "with_all_#{ field.name }".to_sym, ->(*args) {
|
20
|
+
raise ArgumentError, 'wrong number of arguments' unless args.present?
|
21
|
+
tags = args[0].is_a?(Array) ? args[0] : args
|
22
|
+
|
23
|
+
where(["field_store->'tags' ?& ARRAY[:tags]", { tags: tags }])
|
24
|
+
}
|
25
|
+
|
26
|
+
|
27
|
+
# Dynamically define class method .with_any_`field_name`
|
28
|
+
# Returns Array
|
29
|
+
#
|
30
|
+
define_singleton_method "with_any_#{ field.name }".to_sym do |*args, &block|
|
31
|
+
raise ArgumentError, 'wrong number of arguments' unless args.present?
|
32
|
+
tags = args[0].is_a?(Array) ? args[0] : args
|
33
|
+
|
34
|
+
composed_scope = (
|
35
|
+
block.respond_to?(:call) ? block.call : all
|
36
|
+
).where(["field_store->'#{ field.name }' ?| ARRAY[:tags]", { tags: tags }])
|
37
|
+
|
38
|
+
t = Arel::Table.new('t', ActiveRecord::Base)
|
39
|
+
ct = Arel::Table.new('ct', ActiveRecord::Base)
|
40
|
+
|
41
|
+
arr_sql = Arel.sql "ARRAY[#{ tags.map { |t| Arel::Nodes::Quoted.new(t).to_sql }.join(', ') }]"
|
42
|
+
any_tags_func = Arel::Nodes::NamedFunction.new('ANY', [arr_sql])
|
43
|
+
|
44
|
+
lateral = ct
|
45
|
+
.project(Arel.sql('e').count(true).as('ct'))
|
46
|
+
.from(Arel.sql "jsonb_array_elements_text(t.field_store->'#{ field.name }') e")
|
47
|
+
.where(Arel::Nodes::Equality.new Arel.sql('e'), any_tags_func)
|
48
|
+
|
49
|
+
query = t
|
50
|
+
.project(t[Arel.star])
|
51
|
+
.from(composed_scope.as('t'))
|
52
|
+
.join(Arel.sql ", LATERAL (#{ lateral.to_sql }) ct")
|
53
|
+
.order(ct[:ct].desc)
|
54
|
+
|
55
|
+
find_by_sql query.to_sql
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
# Dynamically define class method .all_`field_name`
|
60
|
+
# Returns Array
|
61
|
+
#
|
62
|
+
define_singleton_method "all_#{ field.name }".to_sym do |*args, &block|
|
63
|
+
composed_scope = block.respond_to?(:call) ? block.call : all
|
64
|
+
composed_scope.projections = []
|
65
|
+
|
66
|
+
query = composed_scope
|
67
|
+
.project(Arel.sql "jsonb_array_elements_text(field_store->'#{ field.name }') t")
|
68
|
+
.distinct
|
69
|
+
.order(Arel.sql 't')
|
70
|
+
connection.select_all(query.to_sql).rows.flatten
|
71
|
+
end
|
72
|
+
|
17
73
|
end
|
18
74
|
end
|
19
75
|
|
data/lib/push_type/version.rb
CHANGED
@@ -33,6 +33,6 @@ PushType.setup do |config|
|
|
33
33
|
# secret_access_key: ENV['SECRET_ACCESS_KEY_ID']
|
34
34
|
# }
|
35
35
|
|
36
|
-
# config.dragonfly_secret = '
|
36
|
+
# config.dragonfly_secret = '35fe8a2c1976558822a17ce1b8467a821f5d6e78a7a2396eaf3212ab35c3f198'
|
37
37
|
|
38
38
|
end
|
@@ -11,10 +11,10 @@
|
|
11
11
|
# if you're sharing your code publicly.
|
12
12
|
|
13
13
|
development:
|
14
|
-
secret_key_base:
|
14
|
+
secret_key_base: 6d3edcb0dc341ba9de0d6903d0807a89ecb267c0873d6106374e4a0f0b9bebc3d61126bff26ff0a655f302990ba8c5bd7beca17d03f1228eb9dfb1aeb8d23833
|
15
15
|
|
16
16
|
test:
|
17
|
-
secret_key_base:
|
17
|
+
secret_key_base: dc233cacc45ce0389ddcfe8308585cf78b4c71db25ab442fa5fde21e32c98eb51e56f5551f124b00bda30d77d2db040ca5abecd23d1d992b53235ab0c3dc038a
|
18
18
|
|
19
19
|
# Do not keep production secrets in the repository,
|
20
20
|
# instead read values from the environment.
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/test/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20150816155446) do
|
15
15
|
|
16
16
|
# These are extensions that must be enabled in order to support this database
|
17
17
|
enable_extension "plpgsql"
|