Module: FinePrint
- Defined in:
- lib/fine_print.rb,
lib/fine_print/engine.rb,
lib/fine_print/version.rb,
app/models/fine_print/contract.rb,
app/models/fine_print/signature.rb,
lib/fine_print/controller_additions.rb,
lib/fine_print/security_transgression.rb,
app/helpers/fine_print/application_helper.rb,
app/controllers/fine_print/home_controller.rb,
app/controllers/fine_print/contracts_controller.rb,
app/controllers/fine_print/signatures_controller.rb,
app/controllers/fine_print/application_controller.rb
Defined Under Namespace
Modules: ApplicationHelper, ControllerAdditions Classes: ApplicationController, Contract, ContractsController, Engine, HomeController, SecurityTransgression, Signature, SignaturesController
Constant Summary collapse
- ENGINE_OPTIONS =
Can be set in initializer only
[ :current_user_proc, :user_admin_proc, :can_sign_contracts_proc, :pose_contracts_path, :redirect_path ]
- SIGNATURE_OPTIONS =
Can be set in initializer or passed as an option to fine_print_get_signatures
[ :pose_contracts_path ]
- VERSION =
'1.3.0'
Class Method Summary collapse
- .can_sign?(user) ⇒ Boolean
- .configure {|_self| ... } ⇒ Object
-
.get_contract(reference) ⇒ Object
Gets a contract given either the contract’s object, ID or name If given a name, it returns the latest published version of that contract - contract – can be a Contract object, its ID, or its name as a String or Symbol.
-
.get_unsigned_contract_names(user, *names) ⇒ Object
Returns an array of names for the contracts whose latest published version the given user has not signed.
- .is_admin?(user) ⇒ Boolean
- .raise_unless_admin(user) ⇒ Object
- .raise_unless_can_sign(user) ⇒ Object
-
.sign_contract(user, contract) ⇒ Object
Records that the given user has signed the given contract - user – the user in question - contract – can be a Contract object, its ID, or its name as a String or Symbol.
-
.signed_any_contract_version?(user, contract) ⇒ Boolean
Returns true iff the given user has signed any version of the given contract - user – the user in question - contract – can be a Contract object, its ID, or its name as a String or Symbol.
-
.signed_contract?(user, contract) ⇒ Boolean
Returns true iff the given user has signed the given contract - user – the user in question - contract – can be a Contract object, its ID, or its name as a String or Symbol.
Class Method Details
.can_sign?(user) ⇒ Boolean
105 106 107 |
# File 'lib/fine_print.rb', line 105 def self.can_sign?(user) can_sign_contracts_proc.call(user) end |
.configure {|_self| ... } ⇒ Object
26 27 28 |
# File 'lib/fine_print.rb', line 26 def self.configure yield self end |
.get_contract(reference) ⇒ Object
Gets a contract given either the contract’s object, ID or name If given a name, it returns the latest published version of that contract
- contract -- can be a Contract object, its ID, or its name as a String or Symbol
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fine_print.rb', line 34 def self.get_contract(reference) ref = Integer(reference) rescue reference case ref when Contract ref when Integer Contract.find(ref) when String, Symbol Contract.where(:name => ref.to_s).published.first end end |
.get_unsigned_contract_names(user, *names) ⇒ Object
Returns an array of names for the contracts whose latest published version the given user has not signed.
- user -- the user in question
- names -- contract names to check
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/fine_print.rb', line 90 def self.get_unsigned_contract_names(user, *names) raise_unless_can_sign(user) names = names.flatten.collect{|name| name.to_s} return [] if names.blank? signed_contracts = Contract .joins(:signatures) .where({:name => names, :fine_print_signatures => {:user_id => user.id, :user_type => user.class.name}}).latest signed_contract_names = signed_contracts.collect{|c| c.name} return names - signed_contract_names end |
.is_admin?(user) ⇒ Boolean
109 110 111 |
# File 'lib/fine_print.rb', line 109 def self.is_admin?(user) !user.nil? && user_admin_proc.call(user) end |
.raise_unless_admin(user) ⇒ Object
117 118 119 |
# File 'lib/fine_print.rb', line 117 def self.raise_unless_admin(user) raise SecurityTransgression unless is_admin?(user) end |
.raise_unless_can_sign(user) ⇒ Object
113 114 115 |
# File 'lib/fine_print.rb', line 113 def self.raise_unless_can_sign(user) raise IllegalState, 'User cannot sign contracts' unless can_sign?(user) end |
.sign_contract(user, contract) ⇒ Object
Records that the given user has signed the given contract
- user -- the user in question
- contract -- can be a Contract object, its ID, or its name as a String or Symbol
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fine_print.rb', line 50 def self.sign_contract(user, contract) raise_unless_can_sign(user) contract = get_contract(contract) raise IllegalState, 'Contract not found' if contract.nil? Signature.create do |signature| signature.user = user signature.contract = contract end end |
.signed_any_contract_version?(user, contract) ⇒ Boolean
Returns true iff the given user has signed any version of the given contract
- user -- the user in question
- contract -- can be a Contract object, its ID, or its name as a String or Symbol
76 77 78 79 80 81 82 83 |
# File 'lib/fine_print.rb', line 76 def self.signed_any_contract_version?(user, contract) raise_unless_can_sign(user) contract = get_contract(contract) !Signature.joins(:contract) .where(:fine_print_contracts => {:name => contract.name}, :user_type => user.class.name, :user_id => user.id).first.nil? end |
.signed_contract?(user, contract) ⇒ Boolean
Returns true iff the given user has signed the given contract
- user -- the user in question
- contract -- can be a Contract object, its ID, or its name as a String or Symbol
65 66 67 68 69 70 71 |
# File 'lib/fine_print.rb', line 65 def self.signed_contract?(user, contract) raise_unless_can_sign(user) contract = get_contract(contract) !contract.signatures.where(:user_id => user.id, :user_type => user.class.name).first.nil? end |