po_box 0.1.1 → 0.1.2

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: 0b10bd76b362d28e5cc7d9c09eda401a900209a05637ba7ff6155228c08e18b9
4
- data.tar.gz: 5bbe38a406dfd5635b322ca98838e2f58cfe7e556f0dd19629daa5021c541086
3
+ metadata.gz: cf5765334ed345c096a6e2432f6775772afc81d3830e9d668e3df23fb782a45f
4
+ data.tar.gz: bb13be4eaf786de61adf885bb0b3bc0df69c6740f3a94b5067512465c73d656c
5
5
  SHA512:
6
- metadata.gz: d59fc6330e0dab345da2e9c7281036138965239a8d1a8a560f274caeaba48da76031c182068dfe888541f6eefee2954142a00144c686406383d3eaaf2be4f9f8
7
- data.tar.gz: d3512b157ab338591529e9de8a4036df12fa58db8697206b6d94ec5795364caeca313469e81d2441ea77c222b648d859fb2594b1ccee938c023608d675cb8d98
6
+ metadata.gz: 688da89cf7a2dc81c270580a85ebf838aeb9209c14644ccb297dd90faa81743a3631981b43f057a3637e484bb6ea88d1f3b5f19baa249fc3823c8436410854d1
7
+ data.tar.gz: 9c82e7fdbd57649e2f2e0cdd93d56ffa3532216dcc2bd9df123d3c8f79e5340acfed35acb0c606b3b86cf9dbc7365e9d7c807e774f3ab34328db6a6087d4f181
@@ -52,7 +52,7 @@ module PoBox
52
52
  def set_inbox
53
53
  @inbox = Inbox.find(params[:inbox_id])
54
54
  rescue ActiveRecord::RecordNotFound
55
- redirect_to inboxes_path, notice: "Inbox not found"
55
+ redirect_to po_box_inboxes_path, notice: "Inbox not found"
56
56
  end
57
57
 
58
58
  # Use callbacks to share common setup or constraints between actions.
@@ -42,7 +42,7 @@ module PoBox
42
42
  private
43
43
 
44
44
  def inbox_params
45
- params.require(:inbox).permit(:name, :address)
45
+ params.require(:inbox).permit(:emailable_type, :emailable_id, :address)
46
46
  end
47
47
 
48
48
  def set_inbox
@@ -5,13 +5,13 @@ module PoBox
5
5
  included do
6
6
  has_many :inboxes, as: :emailable, class_name: "PoBox::Inbox", dependent: :destroy
7
7
 
8
- after_create_commit :set_inbox
8
+ after_create_commit :generate_inbox
9
9
 
10
10
  accepts_nested_attributes_for :inboxes, allow_destroy: true
11
11
 
12
12
  private
13
13
 
14
- def set_inbox
14
+ def generate_inbox
15
15
  return if inboxes.any?
16
16
 
17
17
  inbox_address = if email.present?
@@ -23,7 +23,7 @@ module PoBox
23
23
  inbox = inboxes.new
24
24
  loop do
25
25
  inbox.address = inbox_address
26
- break unless PoBox.emailable_class.joins(:inboxes).where(po_box_inboxes: {address: inbox.address}).exists?
26
+ break unless PoBox::Inbox.find_by(address: inbox.address).present?
27
27
  end
28
28
 
29
29
  save
@@ -1,5 +1,18 @@
1
1
  module PoBox
2
- class ApplicationRecord < ActiveRecord::Base
2
+ class ApplicationRecord < ::ActiveRecord::Base
3
3
  self.abstract_class = true
4
+
5
+ def self.sort_by_params(column, direction)
6
+ sortable_column = column.presence_in(sortable_columns) || "created_at"
7
+ order(sortable_column => direction)
8
+ end
9
+
10
+ # Returns an array of sortable columns on the model
11
+ # Used with the Sortable controller concern
12
+ #
13
+ # Override this method to add/remove sortable columns
14
+ def self.sortable_columns
15
+ @sortable_columns ||= columns.map(&:name)
16
+ end
4
17
  end
5
18
  end
@@ -7,5 +7,7 @@ module PoBox
7
7
  validates :from, presence: true
8
8
 
9
9
  delegate :raw_source, to: :body
10
+
11
+ scope :for_emailable, ->(emailable) { joins(:inbox).where(po_box_inboxes: {emailable: emailable}) }
10
12
  end
11
13
  end
@@ -2,6 +2,8 @@ module PoBox
2
2
  class Inbox < ApplicationRecord
3
3
  belongs_to :emailable, polymorphic: true, class_name: PoBox.emailable_class.to_s
4
4
 
5
+ validates :address, presence: true, uniqueness: true
6
+
5
7
  has_many :emails, class_name: "PoBox::Email", dependent: :destroy
6
8
 
7
9
  define_method PoBox.emailable_class.to_s.underscore do
@@ -9,6 +9,11 @@
9
9
  </ul>
10
10
  </div>
11
11
  <% end %>
12
+ <div>
13
+ <%= form.label "Emailable ID", style: "display: block" %>
14
+ <%= form.number_field :emailable_id %>
15
+ <%= form.hidden_field :emailable_type, value: PoBox.emailable_class %>
16
+ </div>
12
17
  <div>
13
18
  <%= form.label :address, style: "display: block" %>
14
19
  <%= form.text_field :address %>
@@ -1,3 +1,3 @@
1
1
  module PoBox
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: po_box
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leo Policastro