Module: ModelUpdates::ModelExtensions

Defined in:
lib/model_updates/model_extensions.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



2
3
4
# File 'lib/model_updates/model_extensions.rb', line 2

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#model_updates_attrs(key, more = {}) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/model_updates/model_extensions.rb', line 100

def model_updates_attrs(key, more = {})
  attrs = {
    model_updates_id: id,
    model_updates_model: self.class.name,
    model_updates_key: key
  }

  more.each do |hash_key, hash_value|
    attrs["model_updates_#{hash_key}"] = hash_value
  end

  attrs
end

#model_updates_call(event_name, args = {}) ⇒ Object



89
90
91
92
93
94
95
96
97
98
# File 'lib/model_updates/model_extensions.rb', line 89

def model_updates_call(event_name, args = {})
  ActionCable.server.broadcast(
    "model_updates_events_model_#{self.class.name}_model_#{id}_event_#{event_name}",
    event_name: event_name,
    id: id,
    model: self.class.name,
    callback_type: "model",
    args: args
  )
end

#model_updates_data_attrs(key, more = {}) ⇒ Object



114
115
116
117
118
119
120
# File 'lib/model_updates/model_extensions.rb', line 114

def model_updates_data_attrs(key, more = {})
  {
    id: id,
    model: self.class.name,
    key: key
  }.merge(more)
end