lease 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2be63f29aefc7beb86b4646de33e0b298a86988f207813028c2b1d20a707ea05
4
- data.tar.gz: b9de86ef8bd2e00212c520fb70ddf00534c86d7706842a20f6ef69218939a6d5
3
+ metadata.gz: d3f2c2ce536808731ab265d729a99b377450321923bae4358393eb913163ad9d
4
+ data.tar.gz: d9cccba084b9bc3c00683a46b87551c74895ba325d1c35d9b4befa4446fd8739
5
5
  SHA512:
6
- metadata.gz: 52d417ed5229121af07e8baf35741eba1965123792df62c515e48b77255b29476c69c72719d33a5fd1f7daea7f0d8aeefc088ccd85e5445d8fa906331f930219
7
- data.tar.gz: 4daf8ce6eb9a4bb39dd59e92b720c15e3e90d42cd1d9020f1dea06ab97a2cd24b263b43894ac72d9995354b672bde66bcf310c504ed76ce704269e3afa9c3752
6
+ metadata.gz: da1539967d5f6ad2d4f389675e9cc34cf52308af15bd5ac248c31c4ea876b99d4132b9bd445e3fed42c204b4fab0602a6d49a1194009ad888154a782fedfb836
7
+ data.tar.gz: a4571691e8a17c8b3c3fc82339aa424933414d4573087ac58300590fec7cf9305411067f253ae7db866323f455518ea8210185b953cb2e232f673172db84f467
data/README.md CHANGED
@@ -1,16 +1,48 @@
1
1
  # Lease
2
2
 
3
- Trying to simplify the lease pdf/html management
3
+ Simplify the lease pdf/html management. Specially designed for a real estate self-storage project.
4
4
 
5
5
  ## Usage
6
+ 1. `rails g lease:install`
7
+ `rake db:migrate`
6
8
 
7
- On any model you want to treat as a "signer" of an envelope/template, add `leasable` to create an association to both envelopes and templates:
8
-
9
+ 2. On any model you want to treat as a "signer" of an envelope/template, add `lease_signable`:
9
10
  ```ruby
10
11
  class User < ApplicationRecord
11
12
 
12
- leasable
13
+ lease_signable
14
+
15
+ end
16
+ ```
17
+ 3. On any model you want treat as a leasing property, add `lease_envelopable`:
18
+ ```ruby
19
+ class Occupancy < ApplicationRecord
13
20
 
21
+ lease_envelopable
22
+
23
+ end
24
+ ```
25
+ 4. You can now call some methods like:
26
+ ```ruby
27
+ user = User.new(full_name:'Jason Smolar') # the signable model
28
+ occupancy = Occupancy.new # the leasable model
29
+ template = Lease::Template.create(state: 'CA', template: File.open('/tmp/ca_lease_template.html'))
30
+ envelope = user.create_envelope(template: template, envelopable: occupancy)
31
+ vars = { # hash of variables to be interpolated into html file. Pass html id to hash key.
32
+ rental_price: '$12', # there should be a html DOM in the template file with the id 'rental_price'
33
+ ...
34
+ }
35
+ if user.has_unsigned_lease?
36
+ envelope = user.envelopes.unsigned.first
37
+ envelope.unsigned_html(vars) # returns html without tenant sign
38
+ envelope.with_unsigned_pdf(vars) do |pdf_file|
39
+ pdf_file.read # pdf_file is temporary use only and will be deleted after this block
40
+ end
41
+ envelope.unsigned? # true
42
+ # Generate and returns the signed pdf. PDF is stored in
43
+ envelope.sign(vars)
44
+ envelope.signed_pdf # Carrierwave::Storage::File
45
+ envelope.signed? # true
14
46
  end
15
47
  ```
16
48
  ## Development
@@ -25,5 +57,5 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/mingca
25
57
 
26
58
  ## License
27
59
 
28
- The gem is available as open source under the terms of the [GNU General Public License](https://www.gnu.org/licenses/gpl-3.0.en.html).
60
+ The gem is available as open source under the terms of the [MIT](https://opensource.org/licenses/MIT).
29
61
 
@@ -5,9 +5,9 @@ module Lease
5
5
 
6
6
  mount_uploader :signed_pdf, ::Lease::DocumentUploader
7
7
 
8
- belongs_to :template
9
- belongs_to :envelopable, polymorphic: true
10
- belongs_to :signable, polymorphic: true
8
+ belongs_to :template, required: true
9
+ belongs_to :envelopable, polymorphic: true, required: true
10
+ belongs_to :signable, polymorphic: true, required: true
11
11
 
12
12
  enum status: [:unsigned, :rejected, :signed]
13
13
 
@@ -20,33 +20,40 @@ module Lease
20
20
  end
21
21
 
22
22
  def sign(vars)
23
- return false if signed?
23
+ return nil if signed?
24
24
 
25
25
  html = interpolate(with_sign(vars))
26
26
  with_generate_pdf(html) do |temp_pdf|
27
- update(signed_pdf: temp_pdf)
27
+ update(signed_pdf: temp_pdf, status: :signed)
28
28
  end
29
29
  end
30
30
 
31
31
  private
32
32
 
33
- def with_generate_pdf(html, &block)
33
+ def with_generate_pdf(html)
34
34
  random = SecureRandom.hex(4)
35
35
  pdf_string = WickedPdf.new.pdf_from_string(html, extra: '--enable-forms')
36
36
  pdf_file_name = Rails.root.join('tmp', 'pdf_lease_documents', "pdf-lease-#{envelopable.id}-#{random}.pdf")
37
37
  pdf_file = File.new(pdf_file_name, 'a+:ASCII-8BIT')
38
38
  pdf_file.write(pdf_string)
39
39
 
40
- yield pdf_file
41
-
40
+ result = yield pdf_file if block_given?
42
41
  File.delete(pdf_file_name)
42
+ result
43
43
  end
44
44
 
45
+ # TODO: check if any field in html has not been interpolated
45
46
  def interpolate(vars)
46
47
  page = Nokogiri::HTML(template.html_file.read)
47
- vars.each do |id, value|
48
- span = page.at_css("[id=\"#{id}\"]")
49
- span.content = value
48
+ vars.each do |dom_id, value|
49
+ spans = page.css("[id=\"#{dom_id}\"]")
50
+ if spans.present?
51
+ spans.each do |span|
52
+ span.content = value
53
+ end
54
+ else
55
+ Rails.logger.info "Lease Envelope #{self.id}: dom id #{dom_id} not found in template"
56
+ end
50
57
  end
51
58
  page.to_html
52
59
  end
@@ -56,7 +63,7 @@ module Lease
56
63
  end
57
64
 
58
65
  def with_sign(vars)
59
- vars.merge(Lease.config.lessee_sign_key => signable.full_name)
66
+ vars.merge(Lease.config.lessee_sign_key => signable.full_name) if signable&.full_name.present?
60
67
  end
61
68
 
62
69
  end
@@ -6,5 +6,7 @@ module Lease
6
6
  has_many :envelopes
7
7
 
8
8
  validates :html_file, presence: true
9
+ validates :state, presence: true, uniqueness: true
10
+
9
11
  end
10
- end
12
+ end
@@ -2,11 +2,12 @@ class CreateLeaseEnvelopes < ActiveRecord::Migration[5.1]
2
2
  def change
3
3
  create_table :lease_envelopes do |t|
4
4
  t.integer :template_id
5
- t.string :lessee_name
6
5
  t.integer :status, default: 0
7
6
  t.string :signed_pdf
8
7
  t.references :envelopable, polymorphic: true, index: { name: 'index_lease_envelopes_on_envelopable_type_and_id' }
9
8
  t.references :signable, polymorphic: true, index: { name: 'index_lease_envelopes_on_signable_type_and_id' }
9
+
10
+ t.timestamps
10
11
  end
11
12
  end
12
13
  end
@@ -3,6 +3,8 @@ class CreateLeaseTemplates < ActiveRecord::Migration[5.1]
3
3
  create_table :lease_templates do |t|
4
4
  t.string :state
5
5
  t.string :html_file
6
+
7
+ t.timestamps
6
8
  end
7
9
  end
8
10
  end
data/lease.gemspec CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ['ninjarailsdev@gmail.com']
11
11
 
12
12
  spec.summary = %q{Lease templates and envelopes}
13
- spec.homepage = 'https://www.github.com/lease'
14
- spec.license = 'GPL-3.0'
13
+ spec.homepage = 'https://www.github.com/mingca/lease.git'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
17
  f.match(%r{^(test|spec|features)/})
@@ -23,6 +23,7 @@ Lease.setup do |config|
23
23
  config.lessee_sign_key = :tenant_full_name
24
24
 
25
25
  end
26
+
26
27
  FileUtils.mkdir_p "#{Rails.root}/tmp/pdf_lease_documents"
27
28
  CONTENT
28
29
  end
@@ -1,8 +1,16 @@
1
1
  module Lease
2
2
  module ActiveRecord
3
3
 
4
- def leasable
5
- has_many :envelopes, as: :envelopable, inverse_of: :envelopable, validate: true, autosave: true, class_name: '::Lease::Envelope'
4
+ def lease_envelopable
5
+ has_one :envelope, as: :envelopable, inverse_of: :envelopable, validate: true, autosave: true, class_name: '::Lease::Envelope'
6
+ end
7
+
8
+ def lease_signable
9
+ has_many :envelopes, as: :signable, inverse_of: :signable, validate: true, autosave: true, class_name: '::Lease::Envelope'
10
+
11
+ def has_unsigned_lease?
12
+ envelopes.unsigned.exists?
13
+ end
6
14
  end
7
15
 
8
16
  end
data/lib/lease/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lease
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lease
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ninja Rails
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-25 00:00:00.000000000 Z
11
+ date: 2019-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -180,9 +180,9 @@ files:
180
180
  - lib/lease/config.rb
181
181
  - lib/lease/engine.rb
182
182
  - lib/lease/version.rb
183
- homepage: https://www.github.com/lease
183
+ homepage: https://www.github.com/mingca/lease.git
184
184
  licenses:
185
- - GPL-3.0
185
+ - MIT
186
186
  metadata: {}
187
187
  post_install_message:
188
188
  rdoc_options: []