carload 0.5.1 → 0.5.2

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: ff22a6684193d3260d0c364a034f2e3fc5f41871
4
- data.tar.gz: f4d5c92e4c6d469982c5582b217a5d6bfd6e8055
3
+ metadata.gz: f350dacce7aa957bd2c6af9782006929339f7491
4
+ data.tar.gz: 4b7e30376296ee3e46ee6fe6e2be768190cd8af7
5
5
  SHA512:
6
- metadata.gz: 46ad15299795918e1e24bfbc17044083339316d844f5efdc2b6f74c2b9dcefb94e8d3a78fcda937d16e6d2c8686a64c55ea9fd02d99549d69e065f0737b414c5
7
- data.tar.gz: 7a573e700e86417e212caa46ec9ed20d739bd7a7f755dc4b1c792b2f42aab4eb459c1a5ff5d80d42c36f78941a663b614115044f7fcde7b93265e27124720217
6
+ metadata.gz: 9400063af855689cf4f18789cd61c6c2138b878305fc9e5aec918c983fd2b7cefca0006d5ffbd8c39cd39c24a79feef7d1967524e4007aa4e57fc5b01f124bbd
7
+ data.tar.gz: 8c100d526f14dd09b6cb1ad3eb08c6b072df0490aee3518fe730686405a61855584b7520621c895c007711249159c662ac1228889e6e2288f052d51aeefcf2ef
@@ -16,8 +16,8 @@ module Carload
16
16
  false
17
17
  end
18
18
 
19
- def image? attribute_name
20
- attribute_name.to_s =~ /image|logo|img/
19
+ def image? model_name, attribute_name
20
+ attribute_name.to_s =~ /image|logo|img/ or (Dashboard.model(model_name).attributes.images.include? attribute_name.to_sym rescue nil)
21
21
  end
22
22
 
23
23
  def associated_model_name model_name, attribute_name
@@ -35,7 +35,7 @@ module Carload
35
35
  placeholder: t('carload.placeholder.select', thing: t("activerecord.attributes.#{class_name}.#{label_attribute}"))
36
36
  }
37
37
  }
38
- elsif needs_upload?(model_name, attribute_name) and image?(attribute_name)
38
+ elsif needs_upload?(model_name, attribute_name) and image?(model_name, attribute_name)
39
39
  upload_image form: form, image_name: attribute_name, width: 150, height: 150
40
40
  elsif options[:type] == :text
41
41
  form.input(attribute_name, label: raw(<<-EOT
@@ -63,16 +63,16 @@ module Carload
63
63
  # Reopen model classes to handle polymorphic association.
64
64
  Dashboard.models.each do |name, spec|
65
65
  spec.associations.values.select { |x| x[:reflection].options[:polymorphic] }.each do |association|
66
- polymorphic_objects = []
67
- association[:instance_models].each do |instance_model|
68
- Dashboard.model(instance_model).klass.all.each do |object|
69
- polymorphic_objects << ["#{object.class} - #{object.send(association[:choose_by])}", "#{object.id},#{object.class}"]
70
- end
71
- end
72
66
  spec.klass.class_eval do
73
67
  class_eval <<-RUBY
74
68
  def self.#{association[:reflection].name.to_s.pluralize}
75
- #{polymorphic_objects}
69
+ polymorphic_objects = []
70
+ #{association[:instance_models]}.each do |instance_model|
71
+ Dashboard.model(instance_model).klass.all.each do |object|
72
+ polymorphic_objects << ["\#{object.class} - \#{object.send(:#{association[:choose_by]})}", "\#{object.id},\#{object.class}"]
73
+ end
74
+ end
75
+ polymorphic_objects
76
76
  end
77
77
  RUBY
78
78
  end
@@ -53,7 +53,8 @@ module Carload
53
53
  @attributes[:permitted] << { :"#{reflection.delegate_reflection.name.to_s.singularize}_ids" => [] }
54
54
  end
55
55
  elsif reflection.options[:polymorphic]
56
- ActiveRecord::Base.descendants.each do |_model|
56
+ Dir.glob("#{Rails.root}/app/models/*.rb").each do |filename|
57
+ _model = File.basename(filename).gsub('.rb', '').camelize.constantize rescue next
57
58
  next if _model.name == 'ApplicationRecord' or _model.name.underscore == @name.to_s
58
59
  _model.reflect_on_all_associations.each do |_reflection|
59
60
  next unless _reflection.options[:as] == reflection.name
@@ -1,3 +1,3 @@
1
1
  module Carload
2
- VERSION = '0.5.1'
2
+ VERSION = '0.5.2'
3
3
  end
@@ -8,7 +8,7 @@ module Carload
8
8
  # Process model once atime.
9
9
  model_specs = {}
10
10
  ActiveRecord::Base.descendants.each do |model| # Rails 5 can use ApplicationRecord.
11
- next if model.name == 'ApplicationRecord' or model.name == 'PgSearch::Document'
11
+ next if ['ApplicationRecord', 'PgSearch::Document', 'ActsAsTaggableOn::Tagging', 'ActsAsTaggableOn::Tag'].include? model.name
12
12
  model_specs[model.name.underscore.to_sym] = ModelSpec.new model
13
13
  end
14
14
  model_name = file_name.to_sym
@@ -18,14 +18,18 @@ module Carload
18
18
  spec.associations.each do |name, association|
19
19
  next if association[:filtered]
20
20
  reflection = association[:reflection]
21
- next if reflection.class ==
22
- if reflection.options[:polymorphic]
23
- attributes = association[:attributes]
24
- elsif reflection.options[:class_name]
25
- attributes = model_specs[reflection.options[:class_name].underscore.to_sym].attributes.permitted.select { |x| x.class != Hash }
26
- else
27
- attributes = model_specs[reflection.name.to_s.singularize.to_sym].attributes.permitted.select { |x| x.class != Hash }
21
+ begin
22
+ if reflection.options[:polymorphic]
23
+ attributes = association[:attributes]
24
+ elsif reflection.options[:class_name]
25
+ attributes = model_specs[reflection.options[:class_name].underscore&.to_sym].attributes.permitted.select { |x| x.class != Hash }
26
+ else
27
+ attributes = model_specs[reflection.name.to_s.singularize.to_sym].attributes.permitted.select { |x| x.class != Hash }
28
+ end
29
+ rescue
30
+ attributes = nil
28
31
  end
32
+ next unless attributes
29
33
  if attributes.size == 1
30
34
  association[:choose_by] = attributes.first
31
35
  else
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Li Dong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-18 00:00:00.000000000 Z
11
+ date: 2016-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails