Sha256: 13a00cf807b65dccb0e1df2bf65691c2f5ebd1504d0359441ea220abf9388789

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

module FinePrint
  module Utilities
    # Returns true iff the given user has signed any version of the given contract.
    #   contract -- can be a Contract object, its ID, or its name as a String or Symbol
    def self.any_signed_contract_version?(contract, user)
      contract = FinePrint::get_contract(contract)
      !user.nil? && 
      !Signature.joins(:contract)
                .where(:contract => {:name => contract.name},
                       :user_type => user.class.name,
                       :user_id => user.id).first.nil?
    end

    # Returns the latest version of the named contract (since contracts don't have
    # versions until they are published this only returns published contracts).
    # If no such contract exists, returns nil.  
    #   name -- can be a String or a Symbol
    def self.latest_contract_named(name)
      name = name.to_s
      contract = Contract.where(:name => name).published.first
      raise IllegalState, "Published version of #{name} not found" \
        if contract.nil?
      contract
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fine_print-1.3.0 lib/fine_print/utilities.rb~
fine_print-1.2.0 lib/fine_print/utilities.rb~
fine_print-1.1.1 lib/fine_print/utilities.rb~
fine_print-1.1.0 lib/fine_print/utilities.rb~
fine_print-1.0.0 lib/fine_print/utilities.rb~