Module: Eigindir::API

Included in:
Eigindir
Defined in:
lib/eigindir/api.rb

Overview

The module provides class-level API

Author:

Instance Method Summary collapse

Instance Method Details

#attribute(name, coerce: nil, reader: nil, writer: nil, strict: nil) ⇒ undefined

Declares the attribute

Parameters:

  • [Proc, (Hash)

    a customizable set of options

  • name (Symbol, String)

    The name of the attribute

  • [Proc, (Hash)

    a customizable set of options

  • [Boolean] (Hash)

    a customizable set of options

Returns:

  • (undefined)


20
21
22
23
# File 'lib/eigindir/api.rb', line 20

def attribute(name, coerce: nil, reader: nil, writer: nil, strict: nil)
  attribute_reader name, coerce: (reader || coerce), strict: strict
  attribute_writer name, coerce: (writer || coerce), strict: strict
end

#attribute_reader(name, coerce: nil, strict: nil) ⇒ undefined

Declares the attribute getter

Parameters:

  • name (Symbol, String)

    The name of the attribute

  • [Proc, (Hash)

    a customizable set of options

  • [Boolean] (Hash)

    a customizable set of options

Returns:

  • (undefined)


36
37
38
39
# File 'lib/eigindir/api.rb', line 36

def attribute_reader(name, **options)
  __declare_reader name, Coercer.new(options)
  __readers << name.to_sym
end

#attribute_writer(name, coerce: nil, strict: nil) ⇒ undefined

Declares the attribute writer

Parameters:

  • name (Symbol, String)

    The name of the attribute

  • [Proc, (Hash)

    a customizable set of options

  • [Boolean] (Hash)

    a customizable set of options

Returns:

  • (undefined)


48
49
50
51
# File 'lib/eigindir/api.rb', line 48

def attribute_writer(name, **options)
  __declare_writer name, Coercer.new(options)
  __writers << name.to_sym
end