Sha256: 69f961c0ac4569e684b7a57e6c4c190ba104a8da888455ce3693014510ac56de

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

module ActiveRecord # :nodoc:
  module ActsAsGoogleAuthenticated # :nodoc:
    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods # :nodoc

      # Initializes the class attributes with the specified options and includes the 
      # GoogleAuthentication module
      # 
      # Options:
      #   [:column_name] the name of the column used to create the google_label
      #   [:method] name of the method to call to created the google_label
      #             it supercedes :column_name
      #   [:google_secret_column] the column the secret will be stored in, defaults
      #                           to "google_secret"
      def acts_as_google_authenticated(options = {})
        @google_label_column  = options[:column_name]           || :email
        @google_label_method  = options[:method]                || :default_google_label_method
        @google_secret_column = options[:google_secret_column]  || :google_secret
        
        attr_accessible @google_secret_column

        [:google_label_column, :google_label_method, :google_secret_column].each do |cattr|
          self.class.__send__(:define_method, cattr) do
            instance_variable_get("@#{cattr}")
          end
        end

        include ActiveRecord::GoogleAuthentication
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
google-authenticator-rails-0.0.1 lib/google-authenticator-rails/active_record/acts_as_google_authenticated.rb