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

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

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
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


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

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 = {}, &block) ⇒ Object


85
86
87
88
89
# File 'app/api/core/endpoint/basic_handler/actions.rb', line 85

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

#check_request_io_class!(request) ⇒ Object

Raises:

  • (StandardError)

53
54
55
# File 'app/api/core/endpoint/basic_handler/actions.rb', line 53

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

#deprecate(*actions) ⇒ Object


73
74
75
76
77
78
79
80
81
82
83
# File 'app/api/core/endpoint/basic_handler/actions.rb', line 73

def deprecate(*actions)
  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


61
62
63
64
65
66
67
68
69
70
71
# File 'app/api/core/endpoint/basic_handler/actions.rb', line 61

def disable(*actions)
  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


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

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


112
113
114
115
116
117
118
# File 'app/api/core/endpoint/basic_handler/actions.rb', line 112

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