Module: HeyYou::Receiver

Includes:
Helper
Defined in:
lib/hey_you/receiver.rb

Defined Under Namespace

Classes: NotRegisteredChannel

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helper

#config

Instance Attribute Details

#receiver_channelsObject (readonly)

Returns the value of attribute receiver_channels.



8
9
10
# File 'lib/hey_you/receiver.rb', line 8

def receiver_channels
  @receiver_channels
end

#receiver_dataObject (readonly)

Returns the value of attribute receiver_data.



8
9
10
# File 'lib/hey_you/receiver.rb', line 8

def receiver_data
  @receiver_data
end

Class Method Details

.extended(klass) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/hey_you/receiver.rb', line 10

def self.extended klass
  klass.class_eval do
    # Method will be injected for instances methods of class.
    #
    # This can use something like: user.send_notification('key', options).
    def send_notification(notification_key, **options)
      Sender.send_to(self, notification_key, options)
    end
  end
end

Instance Method Details

#receive(receiver_data) ⇒ Object

Registrate class as receiver. In parameters pass hash where keys - channels names, and values - procs with values for receive.

For instances of classes will be created methods ‘#channel_name_ch_receive_info` after registrate your class as receiver.

Example:

class User

extend HeyYou::Receiver

receive(
  push:  -> { push_tokens.value },
  email: -> { priority_email }
)

## Or you can use receive with options:
receive(
  email: { subject: -> { priority_email }, options: { mailer_class: UserMailer, mailer_method: :notify } }
)

...

end

user = User.new( push_tokens: PushToken.new(value: “456”), priority_email: ‘[email protected]’) user.push_ch_receive_info # => 456



49
50
51
52
53
54
55
56
57
# File 'lib/hey_you/receiver.rb', line 49

def receive(receiver_data)
  check_channels(receiver_data.keys)

  @receiver_data = receiver_data
  @receiver_channels = receiver_data.keys
  config.registrate_receiver(self)

  define_receive_info_methods
end