Class: Dionysus::Producer::Outbox::Publishable
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Dionysus::Producer::Outbox::Publishable
- Defined in:
- lib/dionysus/producer/outbox/publishable.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #changeset ⇒ Object
-
#initialize(model, config: Dionysus::Producer.configuration) ⇒ Publishable
constructor
A new instance of Publishable.
- #model_class ⇒ Object
- #model_name ⇒ Object
-
#previous_changed_still_visible? ⇒ Boolean
TODO: Check if this is needed.
- #previous_changes_canceled? ⇒ Boolean
- #previous_changes_include_canceled? ⇒ Boolean
- #previous_changes_still_canceled? ⇒ Boolean
- #previous_changes_uncanceled? ⇒ Boolean
- #previously_changed? ⇒ Boolean
- #primary_key_attribute ⇒ Object
- #publishable_id ⇒ Object
- #resource_name ⇒ Object
- #soft_deletable? ⇒ Boolean
- #soft_deleted? ⇒ Boolean
- #topics ⇒ Object
- #visible? ⇒ Boolean
Constructor Details
#initialize(model, config: Dionysus::Producer.configuration) ⇒ Publishable
Returns a new instance of Publishable.
7 8 9 10 11 12 |
# File 'lib/dionysus/producer/outbox/publishable.rb', line 7 def initialize(model, config: Dionysus::Producer.configuration) @model = model @config = config @soft_delete_column = config.soft_delete_column.to_s super(model) end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
4 5 6 |
# File 'lib/dionysus/producer/outbox/publishable.rb', line 4 def model @model end |
Instance Method Details
#changeset ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/dionysus/producer/outbox/publishable.rb', line 86 def changeset if model.destroyed? { model.class.primary_key => [model.public_send(model.class.primary_key), nil], "created_at" => [model.created_at, nil] } else model.previous_changes end end |
#model_class ⇒ Object
14 15 16 |
# File 'lib/dionysus/producer/outbox/publishable.rb', line 14 def model_class model.class end |
#model_name ⇒ Object
26 27 28 |
# File 'lib/dionysus/producer/outbox/publishable.rb', line 26 def model_name model.class.model_name end |
#previous_changed_still_visible? ⇒ Boolean
TODO: Check if this is needed
55 56 57 |
# File 'lib/dionysus/producer/outbox/publishable.rb', line 55 def previous_changed_still_visible? previous_changes_include_canceled? && previous_changes[soft_delete_column][0].blank? && visible? end |
#previous_changes_canceled? ⇒ Boolean
46 47 48 |
# File 'lib/dionysus/producer/outbox/publishable.rb', line 46 def previous_changes_canceled? previous_changes_include_canceled? && previous_changes[soft_delete_column][0].blank? && soft_deleted? end |
#previous_changes_include_canceled? ⇒ Boolean
38 39 40 |
# File 'lib/dionysus/producer/outbox/publishable.rb', line 38 def previous_changes_include_canceled? !!previous_changes[soft_delete_column] end |
#previous_changes_still_canceled? ⇒ Boolean
50 51 52 |
# File 'lib/dionysus/producer/outbox/publishable.rb', line 50 def previous_changes_still_canceled? previous_changes_include_canceled? && previous_changes[soft_delete_column][0].present? && soft_deleted? end |
#previous_changes_uncanceled? ⇒ Boolean
42 43 44 |
# File 'lib/dionysus/producer/outbox/publishable.rb', line 42 def previous_changes_uncanceled? previous_changes_include_canceled? && previous_changes[soft_delete_column][0].present? && visible? end |
#previously_changed? ⇒ Boolean
34 35 36 |
# File 'lib/dionysus/producer/outbox/publishable.rb', line 34 def previously_changed? previous_changes.present? end |
#primary_key_attribute ⇒ Object
18 19 20 |
# File 'lib/dionysus/producer/outbox/publishable.rb', line 18 def primary_key_attribute model.class.primary_key end |
#publishable_id ⇒ Object
22 23 24 |
# File 'lib/dionysus/producer/outbox/publishable.rb', line 22 def publishable_id model.public_send(primary_key_attribute) end |
#resource_name ⇒ Object
30 31 32 |
# File 'lib/dionysus/producer/outbox/publishable.rb', line 30 def resource_name model_name.singular end |
#soft_deletable? ⇒ Boolean
63 64 65 |
# File 'lib/dionysus/producer/outbox/publishable.rb', line 63 def soft_deletable? model.respond_to?(soft_delete_column) end |
#soft_deleted? ⇒ Boolean
59 60 61 |
# File 'lib/dionysus/producer/outbox/publishable.rb', line 59 def soft_deleted? public_send(soft_delete_column).present? end |
#topics ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/dionysus/producer/outbox/publishable.rb', line 71 def topics top_level_topics = Dionysus::Producer .responders_for(model.class) .map(&:primary_topic) topics_from_dependencies = Dionysus::Producer .responders_for_dependency_parent(model.class) .map(&:last) .map(&:primary_topic) [top_level_topics, topics_from_dependencies] .flatten .uniq .tap { |standard_topics| standard_topics << observer_topic if add_observer_topic? } end |
#visible? ⇒ Boolean
67 68 69 |
# File 'lib/dionysus/producer/outbox/publishable.rb', line 67 def visible? !soft_deleted? end |