module Hanami::Action::Exposable::Guard::ClassMethods

Exposures API Guard class methods

@since 0.7.1 @api private

Public Instance Methods

expose(*names) click to toggle source

Prevents exposure if names contain a reserved word.

@param names [Array<Symbol>] the name(s) of the attribute(s) to be

exposed

@return [void]

@since 0.7.1 @api private

Calls superclass method
# File lib/hanami/action/exposable/guard.rb, line 52
def expose(*names)
  detect_reserved_words!(names)

  super
end

Private Instance Methods

detect_reserved_words!(names) click to toggle source

Raises error if given names contain a reserved word.

@param names [Array<Symbol>] a list of names to be checked.

@return [void]

@raise [IllegalExposeError] if names contain one or more of reserved

words

@since 0.7.1 @api private

# File lib/hanami/action/exposable/guard.rb, line 71
def detect_reserved_words!(names)
  names.each do |name|
    if reserved_word?(name)
      raise Hanami::Controller::IllegalExposureError.new("#{name} is a reserved word. It cannot be exposed")
    end
  end
end
reserved_word?(name, namespace = 'Hanami') click to toggle source

Checks if a string is a reserved word

Reserved word is a name of the method defined in one of the modules of a given namespace.

@param name [Symbol] the word to be checked @param namespace [String] the namespace containing internal modules

@return [true, false]

@since 0.7.1 @api private

# File lib/hanami/action/exposable/guard.rb, line 91
def reserved_word?(name, namespace = 'Hanami')
  if method_defined?(name) || private_method_defined?(name)
    method_owner = instance_method(name).owner

    Utils::String.namespace(method_owner) == namespace
  else
    false
  end
end