Class: ActiveWebhook::Adapter

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Defined in:
lib/active_webhook/adapter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ Adapter

Returns a new instance of Adapter.



92
93
94
95
96
97
# File 'lib/active_webhook/adapter.rb', line 92

def initialize(**kwargs)
  self.class.attributes.each do |attr_name|
    send("#{attr_name}=", kwargs[attr_name]) unless attr_name == :context
  end
  self.context = kwargs #.symbolize_keys! #with_indifferent_access
end

Class Method Details

.attribute(*attrs) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/active_webhook/adapter.rb', line 46

def attribute(*attrs)
  # Module.new.tap do |m| # Using anonymous modules so that super can be used to extend accessor methods
  # include m

  attrs = attrs.map(&:to_sym)
  (attrs - attributes).each do |attr_name|
    attributes << attr_name.to_sym
    # m.attr_accessor attr_name
    attr_accessor attr_name
    # end
  end
end

.attributesObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/active_webhook/adapter.rb', line 9

def attributes
  @attributes ||= if self == ActiveWebhook::Adapter
                    []
                  else
                    ancestors.each_with_object([]) do |ancestor, attrs|
                      break attrs += ancestor.attributes if ancestor != self && ancestor.respond_to?(:attributes)

                      attrs
                    end
                  end

  # # byebug
  # # puts ['start', self, @attributes].join(', ')
  # @attributes ||= ancestors.each_with_object([]) do |ancestor, attrs|
  #   # break attrs if ancestor == ActiveWebhook::Adapter

  #   if ancestor != self
  #     if ancestor.respond_to?(:attributes)
  #       break attrs += ancestor.attributes
  #     end
  #   end
  #   attrs

  #   # puts ['searching', ancestor, attrs].join(', ')

  #   # byebug
  #   # break attrs if ancestor == ActiveWebhook::Adapter
  #   # break attrs if ancestor != self && ancestor.respond_to?(:attributes))
  #   # byebug
  #   # attrs
  # end
  # puts ['finished', self, @attributes].join(' ,')
  # # byebug
  # # @attributes ||= []
  # @attributes
end

.call(*args, **kwargs, &block) ⇒ Object

attrs

                                             end)
# byebug
# x = 1

end



73
74
75
# File 'lib/active_webhook/adapter.rb', line 73

def call(*args, **kwargs, &block)
  new(*args, **kwargs).call(&block)
end

.component_configurationObject



85
86
87
# File 'lib/active_webhook/adapter.rb', line 85

def component_configuration
  configuration.send(component_name)
end

.component_nameObject

Raises:

  • (NotImplementedError)


77
78
79
# File 'lib/active_webhook/adapter.rb', line 77

def component_name
  raise NotImplementedError, ".component_name must be implemented."
end

.configurationObject



81
82
83
# File 'lib/active_webhook/adapter.rb', line 81

def configuration
  ActiveWebhook.configuration
end

Instance Method Details

#attributesObject



103
104
105
106
107
# File 'lib/active_webhook/adapter.rb', line 103

def attributes
  self.class.attributes.each_with_object({}) do |attr_name, h|
    h[attr_name] = send(attr_name)
  end
end

#callObject

Raises:

  • (NotImplementedError)


99
100
101
# File 'lib/active_webhook/adapter.rb', line 99

def call
  raise NotImplementedError, "#call must be implemented."
end

#component_configurationObject



113
114
115
# File 'lib/active_webhook/adapter.rb', line 113

def component_configuration
  self.class.component_configuration
end

#configurationObject



109
110
111
# File 'lib/active_webhook/adapter.rb', line 109

def configuration
  self.class.configuration
end