Module: Core::Endpoint::BasicHandler::Actions

Included in:
Core::Endpoint::BasicHandler
Defined in:
app/api/core/endpoint/basic_handler/actions.rb

Overview

rubocop:todo Metrics/ModuleLength

Defined Under Namespace

Classes: UnsupportedAction

Constant Summary collapse

ACTIONS_WITH_SUCCESS_CODES =
{
  create: 201,
  read: 200,
  update: 200,
  delete: 200,
  create_from_file: 201,
  update_from_file: 200
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'app/api/core/endpoint/basic_handler/actions.rb', line 10

def self.included(base)
  base.class_eval do
    include Core::Endpoint::BasicHandler::Actions::Bound
    include Core::Endpoint::BasicHandler::Actions::Factory
    include Core::Endpoint::BasicHandler::Actions::Guards
    include Core::Endpoint::BasicHandler::EndpointLookup
    include Core::Abilities::ActionBehaviour
  end
end

Instance Method Details

#action(name, options = {}) ⇒ Object



98
99
100
101
102
# File 'app/api/core/endpoint/basic_handler/actions.rb', line 98

def action(name, options = {}, &)
  declare_action(name, options, &)
  attach_action(options[:as] || name, name)
  action_guard(name, options[:if]) if options.key?(:if)
end

#check_request_io_class!(request) ⇒ Object

Raises:

  • (StandardError)


58
59
60
# File 'app/api/core/endpoint/basic_handler/actions.rb', line 58

def check_request_io_class!(request)
  raise StandardError, 'Need an I/O class for this request' if request.io.nil?
end

#deprecate(*actions) ⇒ Object

rubocop:todo Metrics/MethodLength



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/api/core/endpoint/basic_handler/actions.rb', line 82

def deprecate(*actions) # rubocop:todo Metrics/MethodLength
  actions.each do |action|
    line = __LINE__ + 1
    singleton_class.class_eval(
      "
      def _#{action}(request, response)
        raise ::Core::Service::DeprecatedAction
      end
    ",
      __FILE__,
      line
    )
    @actions.delete(action.to_sym)
  end
end

#disable(*actions) ⇒ Object

rubocop:todo Metrics/MethodLength



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/api/core/endpoint/basic_handler/actions.rb', line 66

def disable(*actions) # rubocop:todo Metrics/MethodLength
  actions.each do |action|
    line = __LINE__ + 1
    singleton_class.class_eval(
      "
      def _#{action}(request, response)
        raise ::Core::Service::UnsupportedAction
      end
    ",
      __FILE__,
      line
    )
    @actions.delete(action.to_sym)
  end
end

#does_not_require_an_io_classObject



62
63
64
# File 'app/api/core/endpoint/basic_handler/actions.rb', line 62

def does_not_require_an_io_class
  singleton_class.class_eval('def check_request_io_class!(_) ; end', __FILE__, __LINE__)
end

#generate_json_actions(object, options) ⇒ Object



130
131
132
133
134
# File 'app/api/core/endpoint/basic_handler/actions.rb', line 130

def generate_json_actions(object, options)
  options[:stream].block('actions') do |result|
    actions(object, options).each { |name, url| result.attribute(name, url) }
  end
end