Sha256: 8ebe180fb009e7bb887936e23dc74ab09894a2df3c9a87d8eca810aa5862b651

Contents?: true

Size: 585 Bytes

Versions: 3

Compression:

Stored size: 585 Bytes

Contents

module Daywalker
  
  class DynamicFinderMatch # :nodoc:
    attr_accessor :finder, :attribute_names
    def initialize(method)
      case method.to_s
       when /^find_(all_by|by)_([_a-zA-Z]\w*)$/
         @finder = case $1
                   when 'all_by' then :all
                   when 'by' then :one
                   end
         @attribute_names = $2.split('_and_').map {|each| each.to_sym}
      end
    end

    def match?
      @attribute_names && @attribute_names.all? do |each|
        Daywalker::Legislator::VALID_ATTRIBUTES.include? each
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
technicalpickles-daywalker-0.1.0 lib/daywalker/dynamic_finder_match.rb
technicalpickles-daywalker-0.1.1 lib/daywalker/dynamic_finder_match.rb
technicalpickles-daywalker-0.1.2 lib/daywalker/dynamic_finder_match.rb