Sha256: 039fa46c49c4af9af307faaf0024dfc8fa492270a08aa0cf1c6e12695c45b57e

Contents?: true

Size: 859 Bytes

Versions: 4

Compression:

Stored size: 859 Bytes

Contents

require 'active_resource'

module Highrise
  class Base < ActiveResource::Base
    
    self.format = :xml #Higrise API only works with xml and not JSON
    
    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

4 entries across 4 versions & 1 rubygems

Version Path
peterosullivan-highrise-3.0.6 lib/highrise/base.rb
peterosullivan-highrise-3.0.5 lib/highrise/base.rb
peterosullivan-highrise-3.0.4 lib/highrise/base.rb
peterosullivan-highrise-3.0.3 lib/highrise/base.rb