Module: RESTFramework::Mixins::BaseControllerMixin::ClassMethods

Defined in:
lib/rest_framework/mixins/base_controller_mixin.rb

Instance Method Summary collapse

Instance Method Details

#actions_metadataObject

Collect actions (including extra actions) metadata for this controller.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rest_framework/mixins/base_controller_mixin.rb', line 58

def 
  actions = {}

  # Start with builtin actions.
  RESTFramework::BUILTIN_ACTIONS.merge(
    RESTFramework::RRF_BUILTIN_ACTIONS,
  ).each do |action, methods|
    next unless self.method_defined?(action)

    actions[action] = {
      path: "", methods: methods, type: :builtin, metadata: {label: self.label_for(action)}
    }
  end

  # Add builtin bulk actions.
  RESTFramework::RRF_BUILTIN_BULK_ACTIONS.each do |action, methods|
    next unless self.method_defined?(action)

    actions[action] = {
      path: "", methods: methods, type: :builtin, metadata: {label: self.label_for(action)}
    }
  end

  # Add extra actions.
  if extra_actions = self.try(:extra_actions)
    actions.merge!(RESTFramework::Utils.parse_extra_actions(extra_actions, controller: self))
  end

  return actions
end

#get_titleObject

By default, this is the name of the controller class, titleized and with any custom inflection acronyms applied.



42
43
44
45
46
47
# File 'lib/rest_framework/mixins/base_controller_mixin.rb', line 42

def get_title
  return self.title || RESTFramework::Utils.inflect(
    self.name.demodulize.chomp("Controller").titleize(keep_id_suffix: true),
    self.inflect_acronyms,
  )
end

#label_for(s) ⇒ Object

Get a label from a field/column name, titleized and inflected.



50
51
52
53
54
55
# File 'lib/rest_framework/mixins/base_controller_mixin.rb', line 50

def label_for(s)
  return RESTFramework::Utils.inflect(
    s.to_s.titleize(keep_id_suffix: true),
    self.inflect_acronyms,
  )
end

#member_actions_metadataObject

Collect member actions (including extra member actions) metadata for this controller.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/rest_framework/mixins/base_controller_mixin.rb', line 90

def 
  actions = {}

  # Start with builtin actions.
  RESTFramework::BUILTIN_MEMBER_ACTIONS.each do |action, methods|
    next unless self.method_defined?(action)

    actions[action] = {
      path: "", methods: methods, type: :builtin, metadata: {label: self.label_for(action)}
    }
  end

  # Add extra actions.
  if extra_actions = self.try(:extra_member_actions)
    actions.merge!(RESTFramework::Utils.parse_extra_actions(extra_actions, controller: self))
  end

  return actions
end

#options_metadataObject



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/rest_framework/mixins/base_controller_mixin.rb', line 110

def 
  return {
    title: self.get_title,
    description: self.description,
    renders: [
      "text/html",
      self.serialize_to_json ? "application/json" : nil,
      self.serialize_to_xml ? "application/xml" : nil,
    ].compact,
    actions: self.,
    member_actions: self.,
  }.compact
end

#rrf_finalizeObject

Define any behavior to execute at the end of controller definition. :nocov:



126
127
128
129
130
131
132
133
# File 'lib/rest_framework/mixins/base_controller_mixin.rb', line 126

def rrf_finalize
  if RESTFramework.config.freeze_config
    (self::RRF_BASE_CONFIG.keys + self::RRF_BASE_INSTANCE_CONFIG.keys).each { |k|
      v = self.send(k)
      v.freeze if v.is_a?(Hash) || v.is_a?(Array)
    }
  end
end