Module: RESTFramework::BaseControllerMixin::ClassMethods
- Defined in:
- lib/rest_framework/controller_mixins/base.rb
Instance Method Summary collapse
-
#get_actions_metadata ⇒ Object
Collect actions (including extra actions) metadata for this controller.
-
#get_label(s) ⇒ Object
Get a label from a field/column name, titleized and inflected.
-
#get_member_actions_metadata ⇒ Object
Collect member actions (including extra member actions) metadata for this controller.
-
#get_options_metadata ⇒ Object
Get a hash of metadata to be rendered in the ‘OPTIONS` response.
-
#get_title ⇒ Object
Get the title of this controller.
-
#rrf_finalize ⇒ Object
Define any behavior to execute at the end of controller definition.
Instance Method Details
#get_actions_metadata ⇒ Object
Collect actions (including extra actions) metadata for this controller.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rest_framework/controller_mixins/base.rb', line 78 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.get_label(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.get_label(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_label(s) ⇒ Object
Get a label from a field/column name, titleized and inflected.
70 71 72 73 74 75 |
# File 'lib/rest_framework/controller_mixins/base.rb', line 70 def get_label(s) return RESTFramework::Utils.inflect( s.to_s.titleize(keep_id_suffix: true), self.inflect_acronyms, ) end |
#get_member_actions_metadata ⇒ Object
Collect member actions (including extra member actions) metadata for this controller.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/rest_framework/controller_mixins/base.rb', line 110 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.get_label(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 |
#get_options_metadata ⇒ Object
Get a hash of metadata to be rendered in the ‘OPTIONS` response. Cache the result.
131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/rest_framework/controller_mixins/base.rb', line 131 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 |
#get_title ⇒ Object
Get the title of this controller. By default, this is the name of the controller class, titleized and with any custom inflection acronyms applied.
62 63 64 65 66 67 |
# File 'lib/rest_framework/controller_mixins/base.rb', line 62 def get_title return self.title || RESTFramework::Utils.inflect( self.name.demodulize.chomp("Controller").titleize(keep_id_suffix: true), self.inflect_acronyms, ) end |
#rrf_finalize ⇒ Object
Define any behavior to execute at the end of controller definition. :nocov:
147 148 149 150 151 152 153 154 |
# File 'lib/rest_framework/controller_mixins/base.rb', line 147 def rrf_finalize if RESTFramework.config.freeze_config self::RRF_BASE_CONTROLLER_CONFIG.keys.each { |k| v = self.send(k) v.freeze if v.is_a?(Hash) || v.is_a?(Array) } end end |