diff options
-rw-r--r-- | activemodel/lib/active_model/naming.rb | 18 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/batches.rb | 13 | ||||
-rw-r--r-- | activestorage/lib/active_storage/previewer.rb | 4 |
4 files changed, 30 insertions, 11 deletions
diff --git a/activemodel/lib/active_model/naming.rb b/activemodel/lib/active_model/naming.rb index dfccd03cd8..983401801f 100644 --- a/activemodel/lib/active_model/naming.rb +++ b/activemodel/lib/active_model/naming.rb @@ -111,6 +111,22 @@ module ActiveModel # BlogPost.model_name.eql?('Blog Post') # => false ## + # :method: match? + # + # :call-seq: + # match?(regexp) + # + # Equivalent to <tt>String#match?</tt>. Match the class name against the + # given regexp. Returns +true+ if there is a match, otherwise +false+. + # + # class BlogPost + # extend ActiveModel::Naming + # end + # + # BlogPost.model_name.match?(/Post/) # => true + # BlogPost.model_name.match?(/\d/) # => false + + ## # :method: to_s # # :call-seq: @@ -131,7 +147,7 @@ module ActiveModel # to_str() # # Equivalent to +to_s+. - delegate :==, :===, :<=>, :=~, :"!~", :eql?, :to_s, + delegate :==, :===, :<=>, :=~, :"!~", :eql?, :match?, :to_s, :to_str, :as_json, to: :name # Returns a new ActiveModel::Name instance. By default, the +namespace+ diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index e1cd5cbf29..a7523563e2 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -43,6 +43,12 @@ module ActiveRecord klass.arel_attribute(name, table) end + def bind_attribute(name, value) # :nodoc: + attr = arel_attribute(name) + bind = predicate_builder.build_bind_attribute(attr.name, value) + yield attr, bind + end + # Initializes new record from relation while maintaining the current # scope. # diff --git a/activerecord/lib/active_record/relation/batches.rb b/activerecord/lib/active_record/relation/batches.rb index ec4bb06c57..9c579843b1 100644 --- a/activerecord/lib/active_record/relation/batches.rb +++ b/activerecord/lib/active_record/relation/batches.rb @@ -251,8 +251,9 @@ module ActiveRecord end end - bind = primary_key_bind(primary_key_offset) - batch_relation = relation.where(arel_attribute(primary_key).gt(bind)) + batch_relation = relation.where( + bind_attribute(primary_key, primary_key_offset) { |attr, bind| attr.gt(bind) } + ) end end @@ -265,15 +266,11 @@ module ActiveRecord end def apply_start_limit(relation, start) - relation.where(arel_attribute(primary_key).gteq(primary_key_bind(start))) + relation.where(bind_attribute(primary_key, start) { |attr, bind| attr.gteq(bind) }) end def apply_finish_limit(relation, finish) - relation.where(arel_attribute(primary_key).lteq(primary_key_bind(finish))) - end - - def primary_key_bind(value) - predicate_builder.build_bind_attribute(primary_key, value) + relation.where(bind_attribute(primary_key, finish) { |attr, bind| attr.lteq(bind) }) end def batch_order diff --git a/activestorage/lib/active_storage/previewer.rb b/activestorage/lib/active_storage/previewer.rb index fb202f029a..95a041fd16 100644 --- a/activestorage/lib/active_storage/previewer.rb +++ b/activestorage/lib/active_storage/previewer.rb @@ -2,8 +2,8 @@ module ActiveStorage # This is an abstract base class for previewers, which generate images from blobs. See - # ActiveStorage::Previewer::PDFPreviewer and ActiveStorage::Previewer::VideoPreviewer for examples of - # concrete subclasses. + # ActiveStorage::Previewer::MuPDFPreviewer and ActiveStorage::Previewer::VideoPreviewer for + # examples of concrete subclasses. class Previewer attr_reader :blob |