跳至内容 跳至搜索
方法
D
M
N
P
S
V

属性

[R] matchers
[R] attribute_names
[R] model
[R] name

类公共方法

match(model, name)

# 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, method_name)

# File activerecord/lib/active_record/dynamic_matchers.rb, line 52
def initialize(model, method_name)
  @model           = model
  @name            = method_name.to_s
  @attribute_names = @name.match(self.class.pattern)[1].split("_and_")
  @attribute_names.map! { |name| @model.attribute_aliases[name] || name }
end

pattern()

# File activerecord/lib/active_record/dynamic_matchers.rb, line 37
def pattern
  @pattern ||= /\A#{prefix}_([_a-zA-Z]\w*)#{suffix}\Z/
end

prefix()

# File activerecord/lib/active_record/dynamic_matchers.rb, line 41
def prefix
  raise NotImplementedError
end

suffix()

# File activerecord/lib/active_record/dynamic_matchers.rb, line 45
def suffix
  ""
end

实例公共方法

define()

# File activerecord/lib/active_record/dynamic_matchers.rb, line 63
        def define
          model.class_eval <<-CODE, __FILE__, __LINE__ + 1
            def self.#{name}(#{signature})
              #{body}
            end
          CODE
        end

valid?()

# 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