avo 1.18.1 → 1.18.2.pre.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of avo might be problematic. Click here for more details.

@@ -154,5 +154,23 @@ module Avo
154
154
 
155
155
  classes
156
156
  end
157
+
158
+ def get_model_class(model)
159
+ if model.instance_of?(Class)
160
+ model
161
+ else
162
+ model.class.base_class
163
+ end
164
+ end
165
+
166
+ def singular_name(model_or_class)
167
+ model_class = get_model_class model_or_class
168
+
169
+ if ActiveModel::Naming.uncountable? model_class
170
+ model_class.base_class.model_name.route_key.singularize.gsub('_index', '')
171
+ else
172
+ model_class.base_class.model_name.route_key.singularize
173
+ end
174
+ end
157
175
  end
158
176
  end
data/db/factories.rb CHANGED
@@ -44,4 +44,13 @@ FactoryBot.define do
44
44
  factory :comment do
45
45
  body { Faker::Lorem.paragraphs(number: rand(4...10)).join("\n") }
46
46
  end
47
+
48
+ factory :person do
49
+ name { "#{Faker::Name.first_name} #{Faker::Name.last_name}" }
50
+ end
51
+
52
+ factory :spouse do
53
+ name { "#{Faker::Name.first_name} #{Faker::Name.last_name}" }
54
+ type { "Spouse" }
55
+ end
47
56
  end
@@ -74,7 +74,7 @@ module Avo
74
74
  end
75
75
 
76
76
  def initialize
77
- self.class.model_class = model_class
77
+ self.class.model_class = model_class.base_class
78
78
  end
79
79
 
80
80
  def hydrate(model: nil, view: nil, user: nil, params: nil)
@@ -198,10 +198,13 @@ module Avo
198
198
  end
199
199
 
200
200
  def model_class
201
+ # get the model class off of the static property
201
202
  return self.class.model_class if self.class.model_class.present?
202
203
 
203
- return @model.class if @model.present?
204
+ # get the model class off of the model
205
+ return @model.base_class if @model.present?
204
206
 
207
+ # generate a model class
205
208
  class_name_without_resource.safe_constantize
206
209
  end
207
210
 
@@ -410,5 +413,9 @@ module Avo
410
413
  rescue
411
414
  nil
412
415
  end
416
+
417
+ def form_scope
418
+ model.class.base_class.to_s.downcase
419
+ end
413
420
  end
414
421
  end
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "1.18.1"
2
+ VERSION = "1.18.2.pre.0"
3
3
  end