push_type_core 0.6.0.beta.1 → 0.6.0.beta.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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/app/fields/push_type/asset_field.rb +0 -4
  3. data/app/fields/push_type/matrix_field.rb +11 -16
  4. data/app/fields/push_type/relation_field.rb +2 -2
  5. data/app/fields/push_type/repeater_field.rb +21 -23
  6. data/app/fields/push_type/tag_list_field.rb +3 -0
  7. data/lib/push_type/field_type.rb +1 -1
  8. data/lib/push_type/primitives/object_type.rb +7 -0
  9. data/lib/push_type/version.rb +1 -1
  10. data/test/dummy/config/initializers/push_type.rb +1 -1
  11. data/test/dummy/config/secrets.yml +2 -2
  12. data/test/dummy/db/schema.rb +1 -1
  13. data/test/dummy/log/test.log +12060 -12009
  14. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/0ANSDcZJu9gPyqtYPIW729qm1kriQ29Vn9LU8T2SGQU.cache +0 -0
  15. data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/_d65qW7wxRtKVSYpmfSenECz5QUWVI9pppUgV7TA1Rk.cache +0 -0
  16. data/test/dummy/tmp/generators/app/models/category.rb +7 -0
  17. data/test/dummy/tmp/generators/app/views/taxonomies/category.html.erb +3 -0
  18. data/test/fields/push_type/asset_field_test.rb +0 -1
  19. data/test/fields/push_type/repeater_field_test.rb +7 -4
  20. metadata +24 -24
  21. data/test/dummy/tmp/generators/config/initializers/push_type.rb +0 -55
  22. data/test/dummy/tmp/generators/config/routes.rb +0 -59
  23. /data/test/dummy/db/migrate/{20151015181653_create_push_type_users.push_type.rb → 20151102165837_create_push_type_users.push_type.rb} +0 -0
  24. /data/test/dummy/db/migrate/{20151015181654_create_push_type_nodes.push_type.rb → 20151102165838_create_push_type_nodes.push_type.rb} +0 -0
  25. /data/test/dummy/db/migrate/{20151015181655_create_push_type_node_hierarchies.push_type.rb → 20151102165839_create_push_type_node_hierarchies.push_type.rb} +0 -0
  26. /data/test/dummy/db/migrate/{20151015181656_create_push_type_assets.push_type.rb → 20151102165840_create_push_type_assets.push_type.rb} +0 -0
  27. /data/test/dummy/db/migrate/{20151015181657_create_push_type_taxonomies.push_type.rb → 20151102165841_create_push_type_taxonomies.push_type.rb} +0 -0
  28. /data/test/dummy/db/migrate/{20151015181658_create_push_type_taxonomy_hierarchies.push_type.rb → 20151102165842_create_push_type_taxonomy_hierarchies.push_type.rb} +0 -0
  29. /data/test/dummy/db/migrate/{20151015181659_add_field_store_default_values.push_type.rb → 20151102165843_add_field_store_default_values.push_type.rb} +0 -0
  30. /data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/{MSZIb53M-WSslpcsxtT_LlGognclDpLjB9YyJ1qLm3c.cache → aTa2i4fIuP1rB3Te3BmhxVW3c0wwyYQtTIQW710wrm0.cache} +0 -0
  31. /data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/{jE1v4kSAksoYAFuvE0Nbl5ZIcuyFYlWX8cb9YkFd5BY.cache → idBOP3HLwMKqIi2fmJ86l7s0AJCQq-p3JBAe01H630c.cache} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d2e4ab5d33d0814637934a8bdcf85e998a5a59d
4
- data.tar.gz: 69ef1e5c8346a126fb9de81c9287444666904a09
3
+ metadata.gz: 695f0cf51a3d8408ce92094dfe92610f6e079546
4
+ data.tar.gz: 727b6d4d5c39f6c0b3196362a113823e0a416fa5
5
5
  SHA512:
6
- metadata.gz: aca95e9efd081d8c74567fc9f1a2350dd1b8ffb66efda6fcdfbd23e9d0ad559d00683f5335051862f60017080571f0963653fb056c21c4a5b64f03284d5e3caf
7
- data.tar.gz: 8c8aa84c7ea8912e2fbb86904ddc922177a17fabcd6961a50b5cda08ea0376b72813705173af742f97be218aacbf11d920304ba72c0000aeba660ef8b73e2bee
6
+ metadata.gz: 374753265c5c609f1602a81d7f0138e0c47a96ace93124ba45bfda9d7c02772b4a29bbf760c12e8158e39d36d1da5903330949a987f74ccd93e5c63b63f2a9ac
7
+ data.tar.gz: 994a863f1bdb86cf7189ddb78f89dc10df1714fc66a4be0938b9bda6a6a088e88c15ee9613a84d2434af8824a4ec7e06fc18e133733808b006c868f27b3c24c2
@@ -3,10 +3,6 @@ module PushType
3
3
 
4
4
  options template: 'asset'
5
5
 
6
- def id_attr
7
- "#{ name }-asset-modal"
8
- end
9
-
10
6
  def relation_class
11
7
  PushType::Asset
12
8
  end
@@ -7,36 +7,31 @@ module PushType
7
7
  def initialize(*args, &block)
8
8
  super
9
9
  structure_class.class_eval(&block) if block
10
- validate_field_types!
11
10
  end
12
11
 
13
12
  def value
14
13
  return if json_value.blank?
15
- json_value.map do |h|
16
- structure_class.new(field_store: h)
17
- end
14
+ rows
18
15
  end
19
16
 
20
17
  def fields
21
18
  @fields ||= structure_class.new.fields
22
19
  end
23
20
 
24
- private
25
-
26
- def structure_class
27
- @structure_class ||= PushType::Structure.clone
21
+ def rows
22
+ Array(json_value).map do |h|
23
+ structure_class.new(field_store: h)
24
+ end
28
25
  end
29
26
 
30
- def validate_field_types!
31
- fields.values.each do |f|
32
- unless field_type_whitelist.include?(f.kind)
33
- raise ArgumentError, "Invalid field type. `#{ kind }` cannot be used in #{ self.class.name }."
34
- end
35
- end
27
+ def structure
28
+ @structure ||= structure_class.new
36
29
  end
37
30
 
38
- def field_type_whitelist
39
- [:number, :string, :text]
31
+ private
32
+
33
+ def structure_class
34
+ @structure_class ||= PushType::Structure.clone
40
35
  end
41
36
 
42
37
  end
@@ -5,7 +5,7 @@ module PushType
5
5
 
6
6
  def initialize(*args)
7
7
  super
8
- raise ArgumentError, "Relation field names must end with suffix `_id` or `ids`." unless relation_name
8
+ raise ArgumentError, "Relation field names must end with suffix `_id` or `_ids`." unless relation_name
9
9
  end
10
10
 
11
11
  def json_primitive
@@ -33,7 +33,7 @@ module PushType
33
33
  end
34
34
 
35
35
  def relation_class
36
- (@opts[:to] || relation_name.singularize).classify.constantize
36
+ (@opts[:to] || relation_name.singularize).to_s.classify.constantize
37
37
  end
38
38
 
39
39
  def relation_root
@@ -6,22 +6,31 @@ module PushType
6
6
 
7
7
  def initialize(*args)
8
8
  super
9
- validate_field_type!
9
+ raise ArgumentError, "Invalid field type. `#{ @opts[:repeats] }` cannot be used in #{ self.class.name }." if [:tag_list].include?(@opts[:repeats])
10
+ _key, _opts = structure_json_key, @opts
11
+ structure_class.class_eval do
12
+ field _key, _opts[:repeats], _opts.except(:css_class, :repeats).merge(multiple: false)
13
+ define_method(:f) { fields[_key] }
14
+ end
10
15
  end
11
16
 
12
17
  def value
13
18
  return if json_value.blank?
14
- json_value.map do |j|
15
- generate_field('_f' => j).value
16
- end
19
+ rows.map(&:_f)
17
20
  end
18
21
 
19
22
  def template
20
23
  'repeater'
21
24
  end
22
25
 
23
- def field
24
- @field ||= generate_field
26
+ def rows
27
+ Array(json_value).map do |j|
28
+ structure_class.new(field_store: { structure_json_key => j }.as_json)
29
+ end
30
+ end
31
+
32
+ def structure
33
+ @structure ||= structure_class.new
25
34
  end
26
35
 
27
36
  private
@@ -30,27 +39,16 @@ module PushType
30
39
  super.except(:template, :form_helper)
31
40
  end
32
41
 
33
- def generate_field(json = {})
34
- field_type.new :_f, PushType::Structure.new(field_store: json), @opts.except(:css_class).merge(multiple: false)
42
+ def structure_class
43
+ @structure_class ||= PushType::Structure.clone
35
44
  end
36
45
 
37
- def field_type
38
- begin
39
- "push_type/#{ @opts[:repeats] }_field".camelize.constantize
40
- rescue NameError
41
- "#{ @opts[:repeats] }_field".camelize.constantize
46
+ def structure_json_key
47
+ case @opts[:repeats]
48
+ when :relation, :node, :taxonomy, :asset then :_f_id
49
+ else :_f
42
50
  end
43
51
  end
44
52
 
45
- def validate_field_type!
46
- unless field_type_whitelist.include?(@opts[:repeats])
47
- raise ArgumentError, "Invalid field type. `#{ @opts[:repeats] }` cannot be used in #{ self.class.name }."
48
- end
49
- end
50
-
51
- def field_type_whitelist
52
- [:number, :string, :text]
53
- end
54
-
55
53
  end
56
54
  end
@@ -24,6 +24,9 @@ module PushType
24
24
  on_class do |klass, field_name, field_class|
25
25
  klass.class_eval do
26
26
 
27
+ # Break unless we are working on an ActiveRecord klass
28
+ break unless respond_to?(:scope)
29
+
27
30
  # Dynamically define standard scope .with_all_`field_name`
28
31
  # Returns ActiveRecord::Relation
29
32
  #
@@ -28,7 +28,7 @@ module PushType
28
28
  def initialize(name, model, opts = {})
29
29
  @name = name
30
30
  @model = model
31
- @opts = [defaults, self.class.options, opts].compact.inject(&:merge)
31
+ @opts = [defaults, self.class.options, opts].compact.inject(&:deep_merge)
32
32
  end
33
33
 
34
34
  def kind
@@ -1,6 +1,13 @@
1
1
  module PushType
2
2
  module Primitives
3
3
  class ObjectType < Base
4
+
5
+ def to_json
6
+ unless value.blank? or value.values.all?(&:blank?)
7
+ super
8
+ end
9
+ end
10
+
4
11
  end
5
12
  end
6
13
  end
@@ -1,3 +1,3 @@
1
1
  module PushType
2
- VERSION = '0.6.0.beta.1'
2
+ VERSION = '0.6.0.beta.2'
3
3
  end
@@ -50,6 +50,6 @@ PushType.setup do |config|
50
50
  # secret_access_key: ENV['SECRET_ACCESS_KEY_ID']
51
51
  # }
52
52
 
53
- # config.dragonfly_secret = '00043bc391450eed15067f573d180cdbe11701d4ac2071846afedf63a0b0ff97'
53
+ # config.dragonfly_secret = '95ec48e6fde12daa65a9093d7c6cd8a626019001f388ed0d407154d78ac44f30'
54
54
 
55
55
  end
@@ -11,10 +11,10 @@
11
11
  # if you're sharing your code publicly.
12
12
 
13
13
  development:
14
- secret_key_base: f1b64e4e941325944b2519b10024c2b271e7237e0938afb8aad157c8701a1ef3f899fd1026297f82fad973d6c4f070ee56c6b4d54b80cbd01f98577a254dd7da
14
+ secret_key_base: 992655c5cb254e30f6a08279cae78c7bb529da42b7f3f598f2ae57e3809c19e934351882962572232d8d2bc801734f7a269b042b04be4263d2b67f1a48406924
15
15
 
16
16
  test:
17
- secret_key_base: fef760fdb11a957790330541b9117b84f83b8355d4795cecc6e28fe4877abf837eb20a317380d203880d4e0e439bfa064d0dede3697edd70feaa1304917e65ab
17
+ secret_key_base: 1962b2ff958bc3e4bf7281cafde40cb1e34e1419dc68293ac323e874027d1600bb6538bb74ac7f34856ede2702dfe57f5d9eb6c96b00735606fd7b3ba5a9fa1d
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: 20151015181659) do
14
+ ActiveRecord::Schema.define(version: 20151102165843) do
15
15
 
16
16
  # These are extensions that must be enabled in order to support this database
17
17
  enable_extension "plpgsql"