effective_resources 0.3.2 → 0.3.3

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: 0c8221988f03d56ff83b0119d534ec05cc4da24b
4
- data.tar.gz: 90b6ac23aec80640c67a189c389c397d5490562f
3
+ metadata.gz: 092de6a5657f044dc7d24ef202f01b47b666a2f7
4
+ data.tar.gz: cb227dbf96b28597e2d8d9e05823895dd383874a
5
5
  SHA512:
6
- metadata.gz: f8a1bb0a89920994001dc31e28626c79c6ca34909c29d4d52a6b8b87edddf2c4a500982c70e5652643081a447b72daa81f2124adb38e8bf978ee95843e42d367
7
- data.tar.gz: 878d4fb2251e0ce4ce0160dc7913e263123b71593a60b796d973443d8f7068b39e127ee96e7326465e80154b2f53d485e5b7e77839eb6c18df7d7c15e8571a2b
6
+ metadata.gz: 1bccc81b7dc7044112946de7037065d0db21256bf8cd573f9f76fd8cec53d7ea1973018a57df48128459c7282dd1d0fa424ea8ac3707b9597683388728a88a92
7
+ data.tar.gz: f06f6e0235e2e40dc429c42e1c8b274403457038baa2f1dfc6c2f73508db0d6f79acc9246fec35fb79f76f6d8100576dcac52aa8a61cd7ef5b8931dd22ff6182
@@ -8,7 +8,8 @@ module Effective
8
8
  when :belongs_to
9
9
  { as: :select }.merge(search_form_field_collection(belongs_to(name)))
10
10
  when :belongs_to_polymorphic
11
- { as: :grouped_select, polymorphic: true, collection: nil}
11
+ #{ as: :grouped_select, polymorphic: true, collection: nil}
12
+ { as: :string }
12
13
  when :has_and_belongs_to_many
13
14
  { as: :select }.merge(search_form_field_collection(has_and_belongs_to_many(name)))
14
15
  when :has_many
@@ -35,7 +35,7 @@ module Effective
35
35
  0.upto(names.length-1) do |index|
36
36
  class_name = (names[index..-1].map { |name| name.classify } * '::')
37
37
 
38
- if (@model_klass = class_name.safe_constantize).present?
38
+ if (@model_klass ||= class_name.safe_constantize).present?
39
39
  @class_name = class_name
40
40
  @namespaces = names[0...index]
41
41
  break
@@ -3,11 +3,7 @@ module Effective
3
3
  module Klass
4
4
 
5
5
  def klass
6
- @model_klass ||= (
7
- namespaced_class_name.safe_constantize ||
8
- class_name.safe_constantize ||
9
- name.classify.safe_constantize
10
- )
6
+ @model_klass
11
7
  end
12
8
 
13
9
  def datatable_klass
@@ -12,7 +12,7 @@ module Effective
12
12
  end
13
13
 
14
14
  def class_name # 'Effective::Post'
15
- @class_name
15
+ @model_klass.try(:name) || @class_name || ''
16
16
  end
17
17
 
18
18
  def class_path # 'effective'
@@ -20,7 +20,7 @@ module Effective
20
20
  end
21
21
 
22
22
  def namespaced_class_name # 'Admin::Effective::Post'
23
- (namespaces.map { |name| name.classify } + [class_name]) * '::'
23
+ (namespaces.to_a.map { |name| name.classify } + [class_name]) * '::'
24
24
  end
25
25
 
26
26
  def namespace # 'admin/things'
@@ -54,14 +54,21 @@ module Effective
54
54
  end
55
55
 
56
56
  association = associated(name)
57
- term = Effective::Attribute.new(sql_type, klass: association.try(:klass) || klass).parse(value, name: name)
57
+
58
+ term = Effective::Attribute.new(sql_type, klass: (association.try(:klass) rescue nil) || klass).parse(value, name: name)
58
59
 
59
60
  case sql_type
60
61
  when :belongs_to, :has_and_belongs_to_many, :has_many, :has_one
61
62
  relation.where(search_by_associated_conditions(association, term, fuzzy: fuzzy))
62
63
  when :belongs_to_polymorphic
63
64
  (type, id) = term.split('_')
64
- relation.where("#{sql_column} = ?", id).where("#{sql_column.sub('_id', '_type')} = ?", type)
65
+
66
+ if type.present? && id.present?
67
+ relation.where("#{sql_column} = ?", id).where("#{sql_column.sub('_id', '_type')} = ?", type)
68
+ else
69
+ id ||= Effective::Attribute.new(:integer).parse(term)
70
+ relation.where("#{sql_column} = ? OR #{sql_column.sub('_id', '_type')} = ?", id, (type || term))
71
+ end
65
72
  when :effective_addresses
66
73
  raise 'not yet implemented'
67
74
  when :effective_obfuscation
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '0.3.2'.freeze
2
+ VERSION = '0.3.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-28 00:00:00.000000000 Z
11
+ date: 2017-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails