Class: Notify::PayloadClass
- Inherits:
-
Object
- Object
- Notify::PayloadClass
- Defined in:
- lib/notify/payload_class.rb
Constant Summary collapse
- RESERVED_KEYS =
%i[subject email_to email_from email_cc email_bcc tg_bots delivery_method].freeze
- DSL_METHODS =
%i[subject email_recipients email_from email_cc email_bcc tg_recipients locals].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #default_locals ⇒ Object
-
#initialize(**payload) ⇒ PayloadClass
constructor
A new instance of PayloadClass.
- #resolve(name) ⇒ Object
- #resolve_locals ⇒ Object
Constructor Details
#initialize(**payload) ⇒ PayloadClass
Returns a new instance of PayloadClass.
32 |
# File 'lib/notify/payload_class.rb', line 32 def initialize(**payload); end |
Class Method Details
.dsl_definitions ⇒ Object
10 11 12 |
# File 'lib/notify/payload_class.rb', line 10 def dsl_definitions @_dsl_definitions ||= {} end |
.new(**payload) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/notify/payload_class.rb', line 25 def self.new(**payload) instance = allocate instance.instance_variable_set(:@_raw_payload, payload.freeze) instance.send(:initialize, **payload) instance end |
Instance Method Details
#default_locals ⇒ Object
48 49 50 |
# File 'lib/notify/payload_class.rb', line 48 def default_locals @_raw_payload.reject { |k, _| RESERVED_KEYS.include?(k) } end |
#resolve(name) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/notify/payload_class.rb', line 34 def resolve(name) if respond_to?(name) public_send(name) elsif self.class.dsl_definitions.key?(name) dsl_val = self.class.dsl_definitions[name] dsl_val.respond_to?(:call) ? instance_exec(&dsl_val) : dsl_val end end |
#resolve_locals ⇒ Object
43 44 45 46 |
# File 'lib/notify/payload_class.rb', line 43 def resolve_locals result = resolve(:locals) result.nil? ? default_locals : result end |