Sha256: 44776d815b77a64fd8a5800a81dfc671ad4a55bfdb4e54d419d8e85a91bfbf9c

Contents?: true

Size: 1.08 KB

Versions: 11

Compression:

Stored size: 1.08 KB

Contents

module AMEE
  module Rails

    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods
      def has_amee_profile(options = {})
        # Include the instance methods for creation and desctruction
        include InstanceMethods
        # Install callbacks
        before_validation_on_create :amee_create
        before_save :amee_save
        before_destroy :amee_destroy
        # Check that this object has an AMEE profile UID when saving
        validates_presence_of :amee_profile        
      end
    end

    module InstanceMethods

      def amee_create
        # Create profile
        profile = AMEE::Profile::Profile.create(amee_connection)
        self.amee_profile = profile.uid
      end

      def amee_save
        # This is only here to be overridden
      end

      def amee_destroy
        # Delete profile
        AMEE::Profile::Profile.delete(amee_connection, amee_profile)        
      end

      def amee_connection
        # Should be overridden by code which doesn't use the global AMEE connection
        $amee
      end

    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
Floppy-amee-0.4.13 lib/amee/rails.rb
Floppy-amee-0.4.14 lib/amee/rails.rb
Floppy-amee-0.4.15 lib/amee/rails.rb
Floppy-amee-0.4.16 lib/amee/rails.rb
Floppy-amee-0.4.17 lib/amee/rails.rb
Floppy-amee-0.4.18 lib/amee/rails.rb
Floppy-amee-0.4.19 lib/amee/rails.rb
Floppy-amee-0.4.20 lib/amee/rails.rb
Floppy-amee-0.4.21 lib/amee/rails.rb
Floppy-amee-0.4.22 lib/amee/rails.rb
Floppy-amee-0.4.23 lib/amee/rails.rb