Sha256: 15d5ad956f7177680b9eae95756fb708d70123693c4f3139d4a9529338561079

Contents?: true

Size: 1.09 KB

Versions: 16

Compression:

Stored size: 1.09 KB

Contents

class VoucherUser
    include Mongoid::Document
    include Mongoid::Timestamps

    field :name, type: String
    field :email, type: String
    field :confirmed, type: Boolean, default: false
    field :confirmation_date, type: Date

    belongs_to :voucher

    attr_protected :confirmed, :confirmation_date
    validates_presence_of :name, :email
    validates :email, email: true

    after_create :send_confirmation_email


    def confirm
        @confirmed = true
        @confirmation_date = Time.now
        @save
    end

    # @param voucher instance of Voucher
    def already_required(voucher)
        user = VoucherUser.where({voucher_id: voucher[:_id], _id: @attributes['_id']}).first
        if user
            true
        else
            false
        end
    end

    def has_confirmed(voucher)
        user = VoucherUser.where({voucher_id: voucher[:_id], _id: @attributes['_id'], confirmed: true}).first
        if user
            true
        else
            false
        end
    end

    def send_confirmation_email
        VoucherMailer.send_confirmation_link(self).deliver
    end

end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
mix-rails-0.22.0 mix-rails-vouchers/app/models/voucher_user.rb
mix-rails-vouchers-0.22.0 app/models/voucher_user.rb
mix-rails-0.16.0 mix-rails-vouchers/app/models/voucher_user.rb
mix-rails-vouchers-0.16.0 app/models/voucher_user.rb
mix-rails-0.15.0 mix-rails-vouchers/app/models/voucher_user.rb
mix-rails-vouchers-0.15.0 app/models/voucher_user.rb
mix-rails-0.12.2 mix-rails-vouchers/app/models/voucher_user.rb
mix-rails-vouchers-0.12.2 app/models/voucher_user.rb
mix-rails-0.12.1 mix-rails-vouchers/app/models/voucher_user.rb
mix-rails-vouchers-0.12.1 app/models/voucher_user.rb
mix-rails-0.10.4 mix-rails-vouchers/app/models/voucher_user.rb
mix-rails-vouchers-0.10.4 app/models/voucher_user.rb
mix-rails-0.10.3 mix-rails-vouchers/app/models/voucher_user.rb
mix-rails-vouchers-0.10.3 app/models/voucher_user.rb
mix-rails-0.7.0 vouchers/app/models/voucher_user.rb
mix-rails-0.6.0 vouchers/app/models/voucher_user.rb