Class: ReactEmailRails::SharedProps
- Inherits:
-
Object
- Object
- ReactEmailRails::SharedProps
- Defined in:
- lib/react_email_rails/shared_props.rb
Overview
Collects props registered with ‘react_email_share` and merges them beneath the per-mail props, which win on conflict. Mirrors inertia-rails shared data.
Constant Summary collapse
- IVAR =
:@_react_email_shared
Instance Method Summary collapse
-
#initialize(mailer) ⇒ SharedProps
constructor
A new instance of SharedProps.
-
#merge_into(props, deep_merge:) ⇒ Object
Returns ‘props` untouched when nothing is shared, so non-Hash inputs (e.g. serializers) still flow straight through to serialization.
- #to_h ⇒ Object
Constructor Details
#initialize(mailer) ⇒ SharedProps
Returns a new instance of SharedProps.
6 7 8 |
# File 'lib/react_email_rails/shared_props.rb', line 6 def initialize(mailer) @mailer = mailer end |
Instance Method Details
#merge_into(props, deep_merge:) ⇒ Object
Returns ‘props` untouched when nothing is shared, so non-Hash inputs (e.g. serializers) still flow straight through to serialization.
12 13 14 15 16 17 18 19 |
# File 'lib/react_email_rails/shared_props.rb', line 12 def merge_into(props, deep_merge:) shared = to_h return props if shared.empty? base = shared.as_json incoming = props.as_json deep_merge ? base.deep_merge(incoming) : base.merge(incoming) end |
#to_h ⇒ Object
21 22 23 24 25 |
# File 'lib/react_email_rails/shared_props.rb', line 21 def to_h entries.each_with_object({}) do |entry, props| props.merge!(resolve(entry)) end end |