Sha256: 24e7ce518a7778dd1d75db3d4f4b62397508349c2b40fed927718dd0f2fb6ac7

Contents?: true

Size: 954 Bytes

Versions: 9

Compression:

Stored size: 954 Bytes

Contents

module Postal
  class Base
    
    class << self
      
      # Find objects based on some options
      def find(*args)
        options = extract_options(args)
        case args.first
        when :all then  find_all(options)
        else            find_some(args,options)
        end
      end
      
      
      # Alias for find(:all)
      def all
        find(:all)
      end
      
      
      # Make a new user and immediately save to Lyris
      def create(*args)
        instance = self.new(*args)
        instance.save
        return instance
      end
      
      
      # Make a new user and immediately save to Lyris, but throw an error if the save fails.
      def create!(*args)
        instance = self.new(*args)
        instance.save!
        return instance
      end
      
      
      private
      
        def extract_options(opts)
          opts.last.is_a?(::Hash) ? opts.pop : {}
        end
        
    end
    
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
cannikin-postal-0.1.0 lib/postal/base.rb
cannikin-postal-0.1.1 lib/postal/base.rb
cannikin-postal-0.1.2 lib/postal/base.rb
cannikin-postal-0.1.4 lib/postal/base.rb
postal-0.3.0 lib/postal/base.rb
postal-0.2.3 lib/postal/base.rb
postal-0.2.2 lib/postal/base.rb
postal-0.1.5 lib/postal/base.rb
postal-0.1.4 lib/postal/base.rb