0.01
No release in over 3 years
Low commit activity in last 3 years
Generates initializers and attributes
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Initializer

The initializer library defines initializers that receive parameters and assign to attributes. It also defines the attributes, allowing the attribute visibility to be declared as well.

Usage

Use the initializer macro to define the initializer method and attributes:

class SomeItem
  initializer :name, :age, :address, :phone_number
end

The above usage is equivalent to:

class SomeItem
  attr_reader :name, :age, :address, :phone_number

  def initialize(name, age, address, phone_number)
    @name = name
    @age = age
    @address = address
    @phone_number = phone_number
  end
end

Visibility

class SomeItem
  initializer r(:name), w(:age), rw(:address), na(:phone_number)
end

The above usage is equivalent to:

class SomeItem
  attr_reader :name
  attr_writer :age
  attr_accessor :address

  def initialize(name, age, address, phone_number)
    @name = name
    @age = age
    @address = address
    @phone_number = phone_number
  end
end
Visibility Effect Equivalent
r Read Only attr_reader
w Write Only attr_writer
rw Read/Write attr_accessor
na No Accessor (none)

Note: The rw visibility can also be aliased as a.

Default Visibility

An attribute that is not declared with an explicit visibility is given the r (read only) visibility by default.

class SomeItem
  initializer :name
end

The above usage is equivalent to:

class SomeItem
  initializer r(:name)
end

Setup

Require initializer library and activate the macro in you're project's boot up code (e.g.: an initializer in a rails app, or some init file in a library, etc):

require 'initializer'
Initializer.activate

It's not strictly necessary to activate the macro "globally". Include initializer specifically in the class that you want to use it in:

class SomeItem
  include Initializer

  initializer :name, :age, :address
end

Installation

RubyGems

gem install evt-initializer

Bundler

gem 'evt-initializer'

License

Initializer is released under the MIT License.