Class: Azeroth::Decorator::MethodBuilder Private

Inherits:
Sinclair
  • Object
show all
Defined in:
lib/azeroth/decorator/method_builder.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Responsible for building readers for attributes

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, options) ⇒ MethodBuilder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of MethodBuilder.



21
22
23
24
# File 'lib/azeroth/decorator/method_builder.rb', line 21

def initialize(klass, options)
  super(klass)
  @options = options
end

Class Method Details

.build_reader(klass, attribute, options) ⇒ Array<Sinclair::MethodDefinition>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Builds reader

reaader delegate method calls to @object

Returns:

  • (Array<Sinclair::MethodDefinition>)


16
17
18
# File 'lib/azeroth/decorator/method_builder.rb', line 16

def build_reader(klass, attribute, options)
  new(klass, options).build_reader(attribute)
end

Instance Method Details

#build_reader(attribute) ⇒ Array<Sinclair::MethodDefinition>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Builds reader

reaader delegate method calls to @object

Returns:

  • (Array<Sinclair::MethodDefinition>)


27
28
29
30
31
32
# File 'lib/azeroth/decorator/method_builder.rb', line 27

def build_reader(attribute)
  return if skip_creation?(attribute)

  add_method(attribute, "@object.#{attribute}")
  build
end

#skip_creation?(attribute) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


34
35
36
37
38
39
# File 'lib/azeroth/decorator/method_builder.rb', line 34

def skip_creation?(attribute)
  return true unless options.reader
  return false unless klass.method_defined?(attribute)

  !options.override
end