Module: Renee::Core::EnvAccessors::ClassMethods

Defined in:
lib/renee_core/env_accessors.rb

Overview

Class-methods included by this module.

Instance Method Summary collapse

Instance Method Details

#env_accessor(*attrs) ⇒ Object

Defines getters and setters for a list of attributes. If the attributes cannot easily be expressed, use the hash-syntax for defining them.

Examples:

env_accessor "some_value" # will define methods to read and write env['some_value']
env_accessor "current.user" => :current_user will define methods to read and write env['current.user']


20
21
22
23
# File 'lib/renee_core/env_accessors.rb', line 20

def env_accessor(*attrs)
  env_reader(*attrs)
  env_writer(*attrs)
end

#env_reader(*attrs) ⇒ Object

Defines getters for a list of attributes.

See Also:



27
28
29
30
31
32
33
34
35
# File 'lib/renee_core/env_accessors.rb', line 27

def env_reader(*attrs)
  instance_eval do
    env_attr_iter(*attrs) do |key, meth|
      define_method(meth) do
        env[key]
      end
    end
  end
end

#env_writer(*attrs) ⇒ Object

Defines setters for a list of attributes.

See Also:



39
40
41
42
43
44
45
46
47
# File 'lib/renee_core/env_accessors.rb', line 39

def env_writer(*attrs)
  instance_eval do
    env_attr_iter(*attrs) do |key, meth|
      define_method("#{meth}=") do |val|
        env[key] = val
      end
    end
  end
end