ActiveRecord::DynamicMatchers::Method Ruby on Rails 5.1.2 Class ActiveRecord::DynamicMatchers::Method < Object activerecord/lib/active_record/dynamic_matchers.rb Methods D define M match N new P pattern, prefix S suffix V valid? Attributes [R] matchers [R] attribute_names [R] model [R] name Class Public methods match(model, name) Link Source: show | on GitHub # File activerecord/lib/active_record/dynamic_matchers.rb, line 32 def match(model, name) klass = matchers.find { |k| k.pattern.match?(name) } klass.new(model, name) if klass end new(model, name) Link Source: show | on GitHub # File activerecord/lib/active_record/dynamic_matchers.rb, line 52 def initialize(model, name) @model = model @name = name.to_s @attribute_names = @name.match(self.class.pattern)[1].split("_and_") @attribute_names.map! { |n| @model.attribute_aliases[n] || n } end pattern() Link Source: show | on GitHub # File activerecord/lib/active_record/dynamic_matchers.rb, line 37 def pattern @pattern ||= /\A#{prefix}_([_a-zA-Z]\w*)#{suffix}\Z/ end prefix() Link Source: show | on GitHub # File activerecord/lib/active_record/dynamic_matchers.rb, line 41 def prefix raise NotImplementedError end suffix() Link Source: show | on GitHub # File activerecord/lib/active_record/dynamic_matchers.rb, line 45 def suffix "" end Instance Public methods define() Link Source: show | on GitHub # File activerecord/lib/active_record/dynamic_matchers.rb, line 63 def define model.class_eval " def self.#{name}(#{signature}) #{body} end ", __FILE__, __LINE__ + 1 end valid?() Link Source: show | on GitHub # File activerecord/lib/active_record/dynamic_matchers.rb, line 59 def valid? attribute_names.all? { |name| model.columns_hash[name] || model.reflect_on_aggregation(name.to_sym) } end