draft_box 0.0.1 → 0.0.3

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: e3fefedd7a473d1101e01fc2577793271f1a31fc642e8487c3bc60816a982291
4
- data.tar.gz: 8d3d685787454a383ad1184d763fe8c0546bce85b33c4aabdbae3570e90d500c
3
+ metadata.gz: 1dc9cf8a9519b398b986ab18e390772663f053ce25c6869eda6a6b7fbbeb72be
4
+ data.tar.gz: 80243f6424c99fc312cb7d497b46d1b5dfa3b571683f0693901ae76b86ad49ef
5
5
  SHA512:
6
- metadata.gz: 8995b11fd93e62153dde02c26d074671e9dee9c71fb9196f0ffe4c33067b3b6fa06c3e3fa8055e37a389171df83493135e1c29154452c777866314ff9673a19a
7
- data.tar.gz: f86a3b3102af31ce86e356304c9ea9428d27bd2d258712a35bf5f90c1eaf6a81be3ec9aebf924f14e7ce2b4936d5caf2e64fad0480d056cd62cf1592f966cfd2
6
+ metadata.gz: 3ebf36e1a8da2d791fae17a97d38d98eb5550cee8c82fbc1f0d32c65f431777d675d81e08ee91fffc19f31c46f4571f5cade5d75ac04e63c0719c64c0dbb7a62
7
+ data.tar.gz: e6d50e905acef3486de12c3e4c33bbab26fcd5bb91dcafc49ed16d42fb3a9e177270e4b1db8b1b3e86a8a98431b7a48678b15e819752501b9747afe160fd429d
@@ -9,27 +9,14 @@ module DraftBox
9
9
  def deliver!(mail)
10
10
  validate_mail!(mail)
11
11
 
12
- # subject: mail.subject
13
- # body: mail.body.to_s
14
- # from: mail.from
15
- # to: mail.to
16
- # cc: mail.cc
17
- # bcc: mail.bcc
18
- # attachments: mail.attachments
19
-
20
- # Attachment:
21
- # filename: attachment.filename
22
- # content_type: attachment.content_type
23
- # content: attachment.body.to_s
24
-
25
12
  ActiveRecord::Base.transaction do
26
13
  email = DraftBox::Email.create!(
27
14
  subject: mail.subject,
28
15
  body: mail.parts.empty? ? mail.body.to_s : mail.parts.find { |p| p.content_type.start_with?('text/html', 'text/plain') }&.body.to_s,
29
16
  from: mail.from.first,
30
- to: mail.to,
31
- cc: mail.cc,
32
- bcc: mail.bcc
17
+ recipients: mail.to,
18
+ carbon_copies: mail.cc || [],
19
+ blind_copies: mail.bcc || []
33
20
  )
34
21
 
35
22
  mail.attachments.each do |attachment|
@@ -3,7 +3,7 @@ module DraftBox
3
3
  module_function
4
4
 
5
5
  def to_s
6
- '0.0.1'
6
+ '0.0.3'
7
7
  end
8
8
  end
9
9
  end
@@ -16,8 +16,6 @@ module Generators
16
16
  template "attachments_migration.rb", "db/migrate/#{timestamp}_create_draft_box_attachments.rb"
17
17
  end
18
18
 
19
- private
20
-
21
19
  def migration_version
22
20
  "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
23
21
  end
@@ -30,6 +28,18 @@ module Generators
30
28
  key_string = options[:primary_key_type]
31
29
  ", id: :#{key_string}" if key_string
32
30
  end
31
+
32
+ def sqlite?
33
+ db_adapter.match?(/sqlite/i)
34
+ end
35
+
36
+ def mysql?
37
+ db_adapter.match?(/mysql/i)
38
+ end
39
+
40
+ def db_adapter
41
+ ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: "primary").adapter_class.to_s
42
+ end
33
43
  end
34
44
  end
35
45
  end
@@ -4,9 +4,22 @@ class CreateDraftBoxEmails < ActiveRecord::Migration<%= migration_version %>
4
4
  t.string :subject
5
5
  t.text :body
6
6
  t.string :from
7
- t.string :to, array: true, default: []
8
- t.string :cc, array: true, default: []
9
- t.string :bcc, array: true, default: []
7
+ <% if mysql? -%>
8
+ t.string :recipients, default: '[]'
9
+ t.string :carbon_copies, default: '[]'
10
+ t.string :blind_copies, default: '[]'
11
+ <% elsif sqlite? %>
12
+ t.json :recipients, null: false, default: []
13
+ t.json :carbon_copies, null: false, default: []
14
+ t.json :blind_copies, null: false, default: []
15
+ t.check_constraint "JSON_TYPE(recipients) = 'array'", name: 'draft_box_emails_recipients_is_array'
16
+ t.check_constraint "JSON_TYPE(carbon_copies) = 'array'", name: 'draft_box_emails_carbon_copies_is_array'
17
+ t.check_constraint "JSON_TYPE(blind_copies) = 'array'", name: 'draft_box_emails_blind_copies_is_array'
18
+ <% else %>
19
+ t.string :recipients, array: true, default: []
20
+ t.string :carbon_copies, array: true, default: []
21
+ t.string :blind_copies, array: true, default: []
22
+ <% end -%>
10
23
 
11
24
  t.timestamps
12
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: draft_box
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paweł Dąbrowski