Module: Cased::Model
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#cased(action, category: cased_category, payload: {}) ⇒ Array
Instruments events for the model.
-
#cased_category ⇒ String
Defines the event key prefix for all model events.
-
#cased_context(category: cased_category) ⇒ Hash
Internal: Defines the payload to describe the current subject.
-
#cased_human ⇒ String
Internal: The String representation within the Cased object.
-
#cased_id ⇒ String
Defines the Cased identifier for the current instance.
-
#cased_payload ⇒ Hash
Defines the default payload for every event.
Instance Method Details
#cased(action, category: cased_category, payload: {}) ⇒ Array
Instruments events for the model. These events are sent directly to Cased.
32 33 34 35 36 |
# File 'lib/cased/model.rb', line 32 def cased(action, category: cased_category, payload: {}) body = cased_payload.deep_merge(payload) Cased.publish(body.merge(action: "#{category}.#{action}")) end |
#cased_category ⇒ String
Defines the event key prefix for all model events.
Defaults to :my_model if the class this thing is included in is MyModel. Feel free to override to provide a more semantic, meaningful name if you so desire.
45 46 47 |
# File 'lib/cased/model.rb', line 45 def cased_category self.class.cased_category end |
#cased_context(category: cased_category) ⇒ Hash
Internal: Defines the payload to describe the current subject. Can be overridden in model to change fields returned.
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/cased/model.rb', line 87 def cased_context(category: cased_category) context = {} context["#{category}_id".to_sym] = cased_id if cased_id if method(:to_s).owner == self.class context[category] = Cased::Sensitive::String.new(to_s, label: self.class.name) end context end |
#cased_human ⇒ String
Internal: The String representation within the Cased object.
73 74 75 |
# File 'lib/cased/model.rb', line 73 def cased_human cased_context[cased_category] end |
#cased_id ⇒ String
Defines the Cased identifier for the current instance.
68 |
# File 'lib/cased/model.rb', line 68 def cased_id; end |
#cased_payload ⇒ Hash
Defines the default payload for every event.
52 53 54 55 56 |
# File 'lib/cased/model.rb', line 52 def cased_payload { cased_category => self, } end |