Module: Pushable::ActsAsPushable

Extended by:
ActiveSupport::Concern
Defined in:
lib/pushable/acts_as_pushable.rb

Defined Under Namespace

Modules: ClassMethods, Rails

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
# File 'lib/pushable/acts_as_pushable.rb', line 7

def self.included(base)
  base.send :extend, ClassMethods
end

Instance Method Details

#collection_channelObject



25
26
27
# File 'lib/pushable/acts_as_pushable.rb', line 25

def collection_channel
  self.class.name.underscore.pluralize
end

#evaluate(channel) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pushable/acts_as_pushable.rb', line 33

def evaluate(channel)
  case channel
  when :collections
    collection_channel
  when :instances
    instance_channel
  when Symbol #references association
    associate = send(channel)
    "#{associate.class.name.underscore}_#{associate.id}_#{self.class.name.underscore.pluralize}"
  when String
    eval '"' + channel + '"'
  when Proc
    evaluate channel.call(self)
  end
end

#instance_channelObject



29
30
31
# File 'lib/pushable/acts_as_pushable.rb', line 29

def instance_channel
  "#{self.class.name.underscore}_#{id}"
end