Class: Agree2::Template
- Defined in:
- lib/agree2/template.rb
Overview
The Template allows you to create agreements based on a template. You can pick between existing community created templates or create your own that fits your application.
To review some of the public templates available go to: agree2.com/masters/public
If you plan on creating and signing an agreement for your user to accept the process is like this:
-
Load your template
-
Prepare and Sign the agreement, which fills out the template, invites your user and signs it on your behalf
-
Redirect the User to Accept
-
User Accepts agreement
-
Agree2 optional calls an “endpoint” web service on your web service.
-
User is redirected back to your application to a URL you designate
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.collection_name ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#prepare(fields = {}, parties = {}, application_role = nil) ⇒ Object
Prepares a template and optionally invites parties.
-
#prepare_and_sign(fields = {}, parties = {}, application_role = 'application') ⇒ Object
Prepares a template, invites parties and signs it with your application.
Methods inherited from Agreement
#active?, #finalize!, #parties, #parties=, #respond_to?, #state, #to_param
Methods inherited from Base
attr_read_only, attr_serializable, #attributes, collection_path, #destroy, get, #initialize, instance_path, #new_record?, #path, read_only_attributes, #reload, #save, serializable_attributes, singular_name, #to_param, #to_url
Constructor Details
This class inherits a constructor from Agree2::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Agree2::Agreement
Class Method Details
.collection_name ⇒ Object
:nodoc:
18 19 20 |
# File 'lib/agree2/template.rb', line 18 def self.collection_name #:nodoc: "masters" end |
Instance Method Details
#prepare(fields = {}, parties = {}, application_role = nil) ⇒ Object
Prepares a template and optionally invites parties.
optional fields
fields
- a hash of parameters to be used to fill out the template. eg:
{:amount=>100,:valid_to=>1.month.from_now,:service=>'Ruby Developer'}
parties
- a hash of parties. The hash should follow this format:
{ :client=>{:first_name=>'Bob',:last_name=>'Bryson',:email=>'[email protected]',:organization_name=>'Big Client Inc'}}
The above adds a party with the role client. The first_name, last_name and email fields are all required.
application_role
if you would like to add your applications user as a party set this to the role that you want:
@template.prepare {},{},"broker"
Adds your application as a party with the role broker.
A typical example for a consulting agreement:
@template.prepare {:rate=>"140",:valid_to=>"1 month from today"},
{
:consultant=>{:first_name=>'Alice',:last_name=>'Springs',:email=>'[email protected]'},
:client=>{:first_name=>'Bob',:last_name=>'Bryson',:email=>'[email protected]',
:organization_name=>'Big Client Inc'}
}
}
52 53 54 55 56 |
# File 'lib/agree2/template.rb', line 52 def prepare(fields={},parties={},application_role=nil) Party.validate_parties_hash(parties) parties[application_role]=:application if application_role raw_prepare(:fields=>fields,:parties=>parties) end |
#prepare_and_sign(fields = {}, parties = {}, application_role = 'application') ⇒ Object
Prepares a template, invites parties and signs it with your application
required fields
fields
- a hash of parameters to be used to fill out the template. eg:
{:amount=>100,:valid_to=>1.month.from_now,:service=>'Ruby Developer'}
parties
- a hash of parties. The hash should follow this format:
{ :client=>{:first_name=>'Bob',:last_name=>'Bryson',:email=>'[email protected]',:organization_name=>'Big Client Inc'}}
The above adds a party with the role client. The first_name, last_name and email fields are all required.
application_role
if you would like to add your applications user as a party set this to the role that you want:
@template.prepare_and_sign {},{},"broker"
Adds your application as a party with the role broker.
A typical example for a user agreement:
@template.prepare_and_sign {:name=>"Alice Springs"},
{
:user=>{:first_name=>'Alice',:last_name=>'Springs',:email=>'[email protected]'}
},'service'
}
87 88 89 90 91 92 |
# File 'lib/agree2/template.rb', line 87 def prepare_and_sign(fields={},parties={},application_role='application') raise ArgumentError,"You need to add at least one party" if parties.empty? Party.validate_parties_hash(parties) parties[application_role]=:application raw_prepare(:fields=>fields,:parties=>parties,:sign=>application_role) end |