Class: Rapid::Services::Requests::Handler

Inherits:
Handler
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ury_rapid/services/requests/handler.rb

Overview

Abstract class for handlers for a given model object

Handlers are installed on model objects so that, when the server attempts to modify the model object, the handler translates it into a playout system command to perform the actual playout system event the model change represents.

Direct Known Subclasses

NullHandler, UrlHashHandler, VariableHandler

Constant Summary collapse

HOOKS =
{}

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Handler

def_targets, register_into, #targets, targets?, use_poster

Constructor Details

#initialize(in_parent, in_action, in_object, in_payload) ⇒ Handler


22
23
24
25
26
27
# File 'lib/ury_rapid/services/requests/handler.rb', line 22

def initialize(in_parent, in_action, in_object, in_payload)
  super(in_parent)
  @action  = in_action
  @object  = in_object
  @payload = in_payload
end

Class Method Details

.add_hook(action, &block) ⇒ Object


74
75
76
77
# File 'lib/ury_rapid/services/requests/handler.rb', line 74

def self.add_hook(action, &block)
  HOOKS[action] = [] unless HOOKS.key?(action)
  HOOKS[action] << block
end

.add_id_hook(action, ids) ⇒ Object


66
67
68
69
70
71
72
# File 'lib/ury_rapid/services/requests/handler.rb', line 66

def self.add_id_hook(action, ids)
  add_hook(action) do |handler, object, payload|
    active = ids.empty? || ids.include?(payload.id)
    yield(handler, object, payload) if active
    active
  end
end

.delete_by_deleting_childrenObject

Requests that a DELETE on this handler be sent to the item's children


34
35
36
37
38
39
40
# File 'lib/ury_rapid/services/requests/handler.rb', line 34

def self.delete_by_deleting_children
  class_eval do
    def delete
      object.children.each { |_, child| child.delete(@payload) }
    end
  end
end

.on_delete(&block) ⇒ Object


79
80
81
# File 'lib/ury_rapid/services/requests/handler.rb', line 79

def self.on_delete(&block)
  define_method(:delete) { instance_exec(&block) }
end

.post_by_putting_to_child_for(*ids) ⇒ Object


48
49
50
51
52
# File 'lib/ury_rapid/services/requests/handler.rb', line 48

def self.post_by_putting_to_child_for(*ids)
  add_id_hook(:post, ids) do |_handler, object, payload|
    object.get_child(payload.id).put(payload)
  end
end

.put_by_payload_processorObject


54
55
56
57
58
# File 'lib/ury_rapid/services/requests/handler.rb', line 54

def self.put_by_payload_processor
  add_hook(:put) do |handler, _object, payload|
    payload.process(handler)
  end
end

.put_by_posting_to_parentObject


60
61
62
63
64
# File 'lib/ury_rapid/services/requests/handler.rb', line 60

def self.put_by_posting_to_parent
  add_hook(:put) do |_handler, object, payload|
    object.post_to_parent(payload)
  end
end

.service_should_override(*methods) ⇒ Object

Generates NotSupportedByService stubs for the given methods


84
85
86
87
88
89
90
# File 'lib/ury_rapid/services/requests/handler.rb', line 84

def self.service_should_override(*methods)
  methods.each do |method|
    define_method(method) do |*_args|
      fail(Rapid::Common::Exceptions::NotSupportedByService)
    end
  end
end

.use_payload_processor_for(action, *ids) ⇒ Object


42
43
44
45
46
# File 'lib/ury_rapid/services/requests/handler.rb', line 42

def self.use_payload_processor_for(action, *ids)
  add_id_hook(action, ids) do |handler, _object, payload|
    payload.process(handler)
  end
end

Instance Method Details

#runObject


29
30
31
# File 'lib/ury_rapid/services/requests/handler.rb', line 29

def run
  send(action)
end

#to_sObject


18
19
20
# File 'lib/ury_rapid/services/requests/handler.rb', line 18

def to_s
  self.class.name
end