app/models/unidom/common/concerns/model_extension.rb in unidom-common-0.6 vs app/models/unidom/common/concerns/model_extension.rb in unidom-common-0.7
- old
+ new
@@ -98,9 +98,16 @@
scope :"#{matched[1]}_after", ->(time) { where "#{table_name}.#{name} > :time", time: time }
scope :"#{matched[1]}_not_before", ->(time) { where "#{table_name}.#{name} >= :time", time: time }
end
end
+ if name.ends_with? '_state'
+ matched = /\A(.+)_state\z/.match name
+ class_eval do
+ scope :"#{matched[1]}_transited_to", ->(states) { where name => states }
+ end
+ end
+
end
includer.define_singleton_method :default_scope do
includer.all.order("#{includer.table_name}.ordinal ASC") if includer.columns_hash['ordinal'].present?
includer.all.order("#{includer.table_name}.created_at ASC")
\ No newline at end of file