Method: Hanami::Slice::ClassMethods#environment

Defined in:
lib/hanami/slice.rb

#environment(env_name) ⇒ self #environment(env_name) {|slice| ... } ⇒ self

Evaluates the block for a given app environment only.

If the given env_name matches Hanami.env, then the block will be evaluated in the context of self (the slice) via instance_eval. The slice is also passed as the block’s optional argument.

If the env does not match, then the block is not evaluated at all.

Examples:

module MySlice
  class Slice < Hanami::Slice
    environment(:test) do
      config.logger.level = :info
    end
  end
end

Overloads:

  • #environment(env_name) ⇒ self

    Parameters:

    • env_name (Symbol)

      the environment name

  • #environment(env_name) {|slice| ... } ⇒ self

    Parameters:

    • env_name (Symbol)

      the environment name

    Yield Parameters:

    • slice (self)

      the slice

Returns:

  • (self)

See Also:

Since:

  • 2.0.0



161
162
163
164
# File 'lib/hanami/slice.rb', line 161

def environment(env_name, &block)
  instance_eval(&block) if env_name == config.env
  self
end