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.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/app/fields/push_type/tag_list_field.rb +60 -4
  3. data/lib/push_type/version.rb +1 -1
  4. data/test/dummy/config/initializers/push_type.rb +1 -1
  5. data/test/dummy/config/secrets.yml +2 -2
  6. data/test/dummy/db/migrate/{20150716155017_create_push_type_users.push_type.rb → 20150816155440_create_push_type_users.push_type.rb} +0 -0
  7. data/test/dummy/db/migrate/{20150716155018_create_push_type_nodes.push_type.rb → 20150816155441_create_push_type_nodes.push_type.rb} +0 -0
  8. 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
  9. data/test/dummy/db/migrate/{20150716155020_create_push_type_assets.push_type.rb → 20150816155443_create_push_type_assets.push_type.rb} +0 -0
  10. data/test/dummy/db/migrate/{20150716155021_create_push_type_taxonomies.push_type.rb → 20150816155444_create_push_type_taxonomies.push_type.rb} +0 -0
  11. 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
  12. 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
  13. data/test/dummy/db/schema.rb +1 -1
  14. data/test/dummy/log/test.log +6465 -5452
  15. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/{DIGO2XX0gV_Ebgs43ap-65y0MyrcySF3iz56xum2NCQ.cache → W8pDH0KBIZeASFfhb6FcCvgBnw5mwDr_n-_mL7uyJCg.cache} +0 -0
  16. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/{0tutfZEltPbqMrjMJpcgLOWDEBEA1_i4wAlgfGmDMaM.cache → XZ5YMTEXVVS0qOmL43QbUr0VO27mRh-7fqzgzfV5Ulc.cache} +0 -0
  17. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/g97nJc5YmnbscVR5pZZoxgfj652ml7dLjUIu0FHDwLA.cache +0 -0
  18. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/vlJujjzOikOTUvCvT3C4o3vK0ySfxbQQ3RBE37vXH0U.cache +0 -0
  19. data/test/dummy/tmp/generators/app/models/home_page.rb +12 -0
  20. data/test/dummy/tmp/generators/app/views/nodes/home_page.html.erb +13 -0
  21. data/test/fields/push_type/tag_list_field_test.rb +29 -4
  22. metadata +28 -31
  23. data/lib/push_type/tag_list_query.rb +0 -38
  24. data/test/dummy/tmp/generators/config/initializers/push_type.rb +0 -38
  25. data/test/dummy/tmp/generators/config/routes.rb +0 -59
  26. 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: 6aa55009b4f8a6c03b6fb102406df0571d67b025
4
- data.tar.gz: 84db15a256012cfade4359e65df44e3ad25c6e0b
3
+ metadata.gz: 16d0e6e76e9303633cd1eeae3cf04f46bfddacdd
4
+ data.tar.gz: cfd2d279b8ea9c0b1795aac50ede8807a45fe10a
5
5
  SHA512:
6
- metadata.gz: 23d987c95bedbc81a6391c0204cb1d6b499b8dc98ad70d291f0a8f348423264b0cf76a030a6e233d0b11644363726ac1a5f307203354ab3fa895bff600408225
7
- data.tar.gz: 1bd32879b186951bbf24ac36320fdbd101b75547040a7e9f30e0fdba476cc12e83dc2941f6741d000a6e7ae0d71e0db8e6ff69197b5bc1757e620c897cd4f5d7
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
- object.define_singleton_method "all_#{ field.name }".to_sym do |*args|
16
- TagListQuery.new(field.name, object.name.underscore.to_sym).all *args
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
 
@@ -1,3 +1,3 @@
1
1
  module PushType
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
@@ -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 = 'ecd8c099d97873bfcba21a3f63d298e86a7b4342be8493eb56b291d0ca46b187'
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: b88deb276072e733b6a6b83a5d5362b6e21a3b0d083b025c5317c5f5a52c037bf58548da93d789c587f33d73484df50681fd5389ba378a9c3a2431cc1a01ad7f
14
+ secret_key_base: 6d3edcb0dc341ba9de0d6903d0807a89ecb267c0873d6106374e4a0f0b9bebc3d61126bff26ff0a655f302990ba8c5bd7beca17d03f1228eb9dfb1aeb8d23833
15
15
 
16
16
  test:
17
- secret_key_base: 2bdc9c611035f1a8d28c68f1fccfc3a9917277fb2785620953a8d30c8665e88a0f5fd52195a4e815f63687233bc57fa358aad0a71d8531d64f252b44841d25c8
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.
@@ -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: 20150716155023) do
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"