Module: Hippo::API::Updates

Defined in:
lib/hippo/api/updates.rb

Class Method Summary collapse

Class Method Details

.relay!Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/hippo/api/updates.rb', line 18

def self.relay!
    if @relaying_messages
        raise "Already relaying messages, calling relay! twice will lead to message duplication"
    end
    @relaying_messages = true
    Hippo::Model.observe(:save) do |model|
        if model.saved_changes.any?
            path = "#{model.class.api_path(with_module: true)}/#{model.id}"
            Hippo::API::PubSub.publish(path, {
                by: self.(model),
                update: model.saved_changes
            })
        end
    end

end

.user_info_for_change(model) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/hippo/api/updates.rb', line 10

def self.(model)
    if model.class.reflect_on_aggregation(:updated_by)
        model.updated_by.as_json(only:[:id,:name,:email])
    else
        {}
    end
end