Class: Modernize::BlockParsingContext

Inherits:
Object
  • Object
show all
Defined in:
lib/modernizer/parser.rb

Overview

Class for the context in which the block will get run

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBlockParsingContext

Returns a new instance of BlockParsingContext.



23
24
25
26
27
28
# File 'lib/modernizer/parser.rb', line 23

def initialize
  @translations = {}
  @initial_version = nil
  @has_version = false
  @order = :ascending
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Determines what versions there are and before + after if any.

Raises:

  • (NoMethodError)


32
33
34
35
# File 'lib/modernizer/parser.rb', line 32

def method_missing(method, *args, &block)
  raise NoMethodError.new("Undefined translation method #{method}") unless MetaMethods.respond_to?(method)
  MetaMethods.send(method, self, args, &block)
end

Instance Attribute Details

#has_versionObject

Returns the value of attribute has_version.



21
22
23
# File 'lib/modernizer/parser.rb', line 21

def has_version
  @has_version
end

#initial_versionObject

Returns the value of attribute initial_version.



21
22
23
# File 'lib/modernizer/parser.rb', line 21

def initial_version
  @initial_version
end

#orderObject

Returns the value of attribute order.



21
22
23
# File 'lib/modernizer/parser.rb', line 21

def order
  @order
end

#translationsObject

Returns the value of attribute translations.



21
22
23
# File 'lib/modernizer/parser.rb', line 21

def translations
  @translations
end

Instance Method Details

#migrationsObject

Returns the struct of version block and translation sets throws an error if no block is provided for determining version.

Raises:



40
41
42
43
# File 'lib/modernizer/parser.rb', line 40

def migrations
  raise VersionError.new('did not provide a way to determine version') unless @has_version
  CompiledMigrations.new(@translations, @initial_version, @order)
end