module Assertion::DSL::Attribute

Allows adding aliases to ‘#object` method.

Private Class Methods

extended(klass) click to toggle source

Ensures the ‘#object` is defined

@param [Class] klass

@return [undefined]

# File lib/assertion/dsl/attribute.rb, line 36
def self.extended(klass)
  klass.__send__ :attr_reader, :object
end

Public Instance Methods

attribute(name) click to toggle source

Adds alias to the [#object] method

@param [#to_sym] name

@return [undefined]

@raise [NameError]

When a given name is either used by instance methods,
or reserved by the `#state` method to be implemented later.
# File lib/assertion/dsl/attribute.rb, line 23
def attribute(name)
  __check_attribute__(name)
  alias_method name, :object
end

Private Instance Methods

__check_attribute__(key) click to toggle source

Checks if alias name for ‘#object` is free

@param [#to_sym] key

@return [undefined]

@raise [NameError] if the key is already in use

# File lib/assertion/dsl/attribute.rb, line 48
def __check_attribute__(key)
  return unless (instance_methods << :state).include? key.to_sym
  fail NameError.new "#{self}##{key} is already defined"
end