Sha256: 66a1cf64b1206ac2c1f580aa3becd826018674edb02e3a0174e42dd9359c23e8

Contents?: true

Size: 1.27 KB

Versions: 16

Compression:

Stored size: 1.27 KB

Contents

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

      module ClassMethods

        def acts_as_muck_access_code_request(options = {})

          validates_presence_of :email
          validates_uniqueness_of :email
          
          named_scope :unfullfilled, :conditions => 'access_code_requests.code_sent_at IS NULL'
          named_scope :by_newest, :order => "created_at DESC"
          named_scope :by_oldest, :order => "created_at ASC"
          
          include ActiveRecord::Acts::MuckAccessCodeRequest::InstanceMethods
          extend ActiveRecord::Acts::MuckAccessCodeRequest::SingletonMethods
          
        end
      end

      module SingletonMethods
        
        def get_requests(limit = nil)
          if limit && limit.to_i > 0
            self.by_oldest.unfullfilled.all(:limit => limit)
          else
            self.by_oldest.unfullfilled
          end
        end
        
        def mark_fullfilled(access_code_requests)
          access_code_requests.each do |request|
            request.update_attribute(:code_sent_at, DateTime.now)
          end
        end
        
      end
      
      module InstanceMethods
       
      end

    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
muck-users-0.3.20 lib/active_record/acts/muck_access_code_request.rb
muck-users-0.3.19 lib/active_record/acts/muck_access_code_request.rb
muck-users-0.3.18 lib/active_record/acts/muck_access_code_request.rb
muck-users-0.3.17 lib/active_record/acts/muck_access_code_request.rb
muck-users-0.3.16 lib/active_record/acts/muck_access_code_request.rb
muck-users-0.3.15 lib/active_record/acts/muck_access_code_request.rb
muck-users-0.3.14 lib/active_record/acts/muck_access_code_request.rb
muck-users-0.3.13 lib/active_record/acts/muck_access_code_request.rb
muck-users-0.3.12 lib/active_record/acts/muck_access_code_request.rb
muck-users-0.3.11 lib/active_record/acts/muck_access_code_request.rb
muck-users-0.3.10 lib/active_record/acts/muck_access_code_request.rb
muck-users-0.3.9 lib/active_record/acts/muck_access_code_request.rb
muck-users-0.3.8 lib/active_record/acts/muck_access_code_request.rb
muck-users-0.3.7 lib/active_record/acts/muck_access_code_request.rb
muck-users-0.3.6 lib/active_record/acts/muck_access_code_request.rb
muck-users-0.3.4 lib/active_record/acts/muck_access_code_request.rb