unidom-contact 1.2 → 1.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
  SHA1:
3
- metadata.gz: e1352769a30dacb2e61ede38eb018a7fb88e9511
4
- data.tar.gz: 0ac784280303119e027fa6c95f45ba0f434e60c7
3
+ metadata.gz: 1bb8c1c4bdc3a86388a814536a16e4f9b8ba82f9
4
+ data.tar.gz: 1f4d011717a2e97db9fcdfe03bed37ea657055bf
5
5
  SHA512:
6
- metadata.gz: 73d7215db5354e4e43658c0c269e5ef18ac04fbb1aa4a87e8717e7290429d47d94b450719e4247b7c5cbe57f4df6207e190522b422f6f28dce8575076ef2a5bb
7
- data.tar.gz: 79d399cbd561687621903b1d341ae4f504039e05e0b5f2790bc5c44d8ca7df45e8e22204a84c730a39892ddcd041e2e856c6113ff87a79c9ec075ae7ffe50524
6
+ metadata.gz: b7df296b4b00638a8c727b5a425fdf6039e914bc984bd4199baabc48902b304474642b195b457386cfc11a3fb3e32f30bc2d53fc5a1a3a826c59a655a46312a6
7
+ data.tar.gz: 713ecf0b3d6b4578781c6bda6fba35fc70f3ef65686ba7a78d48b57b2e3c46dd2fba925da826e14b94185552ece1111209ba0a9b8f2e9b721851eb887cc9d3f9
data/README.md CHANGED
@@ -51,12 +51,14 @@ include Unidom::Contact::Concerns::AsEmailAddressSubscriber
51
51
  ### As Contact concern
52
52
  The As Contact concern do the following tasks for the includer automatically:
53
53
  1. Define the has_many :contact_subscriptions macro as: ``has_many :contact_subscriptions, class_name: 'Unidom::Contact::ContactSubscription', as: :contact``
54
- 2. Define the #subscribe_contact! method as: ``def subscribe_contact!(contact, at: Time.now)``
54
+ 2. Define the #is_subscribed_as_contact! method as: ``is_subscribed_as_contact!(by: nil, at: Time.now, name: by.try(:name), primary: true)``
55
+ 3. Define the #is_subscribed_as_contact? method as: ``is_subscribed_as_contact?(by: nil, at: Time.now, primary: true)``
55
56
 
56
57
  ### As Subscriber concern
57
58
  The As Subscriber concern do the following tasks for the includer automatically:
58
59
  1. Define the has_many :contact_subscriptions macro as: ``has_many :contact_subscriptions, class_name: 'Unidom::Contact::ContactSubscription', as: :subscriber``
59
- 2. Define the #is_subscribed_as_contact! method as: ``def is_subscribed_as_contact!(by: nil, at: Time.now)``
60
+ 2. Define the #subscribe_contact! method as: ``subscribe_contact!(contact, at: Time.now, name: nil, primary: true)``
61
+ 3. Define the #subscribe_contact? method as: ``subscribe_contact?(contact, at: Time.now, primary: true)``
60
62
 
61
63
  ### As Email Address Subscriber concern
62
64
  The As Email Address Subscriber concern do the following tasks for the includer automatically:
@@ -6,12 +6,21 @@ module Unidom::Contact::Concerns::AsContact
6
6
 
7
7
  has_many :contact_subscriptions, class_name: 'Unidom::Contact::ContactSubscription', as: :contact
8
8
 
9
- def is_subscribed_as_contact!(by: nil, at: Time.now, name: by.try(:name))
9
+ def is_subscribed_as_contact!(by: nil, at: Time.now, name: by.try(:name), primary: true)
10
10
 
11
11
  raise ArgumentError.new('The by argument is required.') if by.blank?
12
12
  raise ArgumentError.new('The at argument is required.') if at.blank?
13
13
 
14
- contact_subscriptions.create! subscriber: by, opened_at: at, name: name
14
+ contact_subscriptions.subscribed_by(by).valid_at(now: at).alive.first_or_create! name: name, elemental: primary, opened_at: at
15
+
16
+ end
17
+
18
+ def is_subscribed_as_contact?(by: nil, at: Time.now, primary: true)
19
+
20
+ raise ArgumentError.new('The by argument is required.') if by.blank?
21
+ raise ArgumentError.new('The at argument is required.') if at.blank?
22
+
23
+ contact_subscriptions.subscribed_by(by).valid_at(now: at).alive.primary(primary).exists?
15
24
 
16
25
  end
17
26
 
@@ -6,12 +6,21 @@ module Unidom::Contact::Concerns::AsSubscriber
6
6
 
7
7
  has_many :contact_subscriptions, class_name: 'Unidom::Contact::ContactSubscription', as: :subscriber
8
8
 
9
- def subscribe_contact!(contact, at: Time.now, name: nil)
9
+ def subscribe_contact!(contact, at: Time.now, name: nil, primary: true)
10
10
 
11
11
  raise ArgumentError.new('The contact argument is required.') if contact.blank?
12
12
  raise ArgumentError.new('The at argument is required.' ) if at.blank?
13
13
 
14
- contact_subscriptions.create! contact: contact, opened_at: at, name: name||self.name
14
+ contact_subscriptions.contact_is(contact).valid_at(now: at).alive.first_or_create! name: name||self.name, elemental: primary, opened_at: at
15
+
16
+ end
17
+
18
+ def subscribe_contact?(contact, at: Time.now, primary: true)
19
+
20
+ raise ArgumentError.new('The contact argument is required.') if contact.blank?
21
+ raise ArgumentError.new('The at argument is required.' ) if at.blank?
22
+
23
+ contact_subscriptions.contact_is(contact).valid_at(now: at).alive.primary(primary).exists?
15
24
 
16
25
  end
17
26
 
@@ -16,16 +16,8 @@ class Unidom::Contact::ContactSubscription < ActiveRecord::Base
16
16
  scope :contact_is, ->(contact) { where contact: contact }
17
17
  scope :subscribed_by, ->(subscriber) { where subscriber: subscriber }
18
18
 
19
- #def self.subscribe(contact, subscriber, name: subscriber.name, primary: false, grade: 0, priority: 0, opened_at: Time.now)
20
- # contact_is(contact).subscribed_by(subscriber).valid_at.alive.first_or_create name: name, elemental: primary, grade: grade, priority: priority, opened_at: opened_at
21
- #end
22
-
23
- def self.subscribe!(contact: nil, subscriber: nil, name: subscriber.name, primary: false, grade: 0, priority: 0, opened_at: Time.now)
24
- contact_is(contact).subscribed_by(subscriber).valid_at.alive.first_or_create! name: name, elemental: primary, grade: grade, priority: priority, opened_at: opened_at
19
+ def self.subscribe!(contact: nil, subscriber: nil, name: subscriber.try(:name), primary: true, grade: 0, priority: 0, opened_at: Time.now)
20
+ contact_is(contact).subscribed_by(subscriber).valid_at(now: opened_at).alive.first_or_create! name: name, elemental: primary, grade: grade, priority: priority, opened_at: opened_at
25
21
  end
26
22
 
27
- #class << self
28
- # deprecate subscribe: :subscribe!, deprecator: ActiveSupport::Deprecation.new('1.0', 'unidom-contact')
29
- #end
30
-
31
23
  end
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Contact
3
- VERSION = '1.2'.freeze
3
+ VERSION = '1.3'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-contact
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: '1.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-29 00:00:00.000000000 Z
11
+ date: 2016-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common