Sha256: 94640f8c2999269ec2b5fa0992e92cfd90b0471de37de5227c4bf30c248694f4

Contents?: true

Size: 785 Bytes

Versions: 1

Compression:

Stored size: 785 Bytes

Contents

require 'active_resource'

module Highrise
  class Base < ActiveResource::Base
    
    def self.url_for(n)
      base  = site.to_s.split('@')[1]
      File.join('https://', base, element_path(n)).gsub(".xml",'')
    end

    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

1 entries across 1 versions & 1 rubygems

Version Path
peterosullivan-highrise-3.0.2 lib/highrise/base.rb