Class: Transpec::RecordBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/transpec/record.rb

Overview

This class is intended to be inherited to build complex record. The reasons why you should inherit this class rather than Record are:

* You need to care about String and Symbol around Record#old_syntax and #new_syntax.
* All record instances are kept in a Report until the end of Transpec process.
  This mean that if a custom record keeps a syntax object as an ivar,
  the AST kept by the syntax object won't be GCed.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(*args) ⇒ Object



97
98
99
# File 'lib/transpec/record.rb', line 97

def self.build(*args)
  new(*args).build
end

.param_names(*names) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/transpec/record.rb', line 101

def self.param_names(*names)
  names.each_with_index do |name, index|
    define_method(name) do
      @initializer_params[index]
    end
  end
end

Instance Method Details

#buildObject



109
110
111
# File 'lib/transpec/record.rb', line 109

def build
  Record.new(old_syntax, new_syntax, { type: type, annotation: annotation })
end