Sha256: 8f976367c208963ca98b628f63c40ff595591621a7fa5640c6a409e8d55f7ddb

Contents?: true

Size: 638 Bytes

Versions: 3

Compression:

Stored size: 638 Bytes

Contents

require 'active_resource'

module Highrise
  class Base < ActiveResource::Base
    protected
    # Dynamic finder for attributes
    def self.method_missing(method, *args)
      if method.to_s =~ /^find_(all_)?by_([_a-zA-Z]\w*)$/
        raise ArgumentError, "Dynamic finder method must take an argument." if args.empty?
        options = args.extract_options!
        resources = respond_to?(:find_all_across_pages) ? send(:find_all_across_pages, options) : send(:find, :all)
        resources.send($1 == 'all_' ? 'select' : 'detect') { |container| container.send($2) == args.first }
      else
        super
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
highrise-3.0.3 lib/highrise/base.rb
highrise-3.0.1 lib/highrise/base.rb
highrise-3.0.0 lib/highrise/base.rb