Class: Transpec::Syntax::RSpecConfigure::FrameworkConfiguration

Inherits:
Object
  • Object
show all
Includes:
AST::Sexp
Defined in:
lib/transpec/syntax/rspec_configure.rb

Instance Method Summary collapse

Constructor Details

#initialize(rspec_configure_node, framework_config_method_name, source_rewriter) ⇒ FrameworkConfiguration

Returns a new instance of FrameworkConfiguration.



40
41
42
43
44
# File 'lib/transpec/syntax/rspec_configure.rb', line 40

def initialize(rspec_configure_node, framework_config_method_name, source_rewriter)
  @rspec_configure_node = rspec_configure_node
  @framework_config_method_name = framework_config_method_name
  @source_rewriter = source_rewriter
end

Instance Method Details

#modify_syntaxes!(syntaxes) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/transpec/syntax/rspec_configure.rb', line 61

def modify_syntaxes!(syntaxes)
  unless [Array, Symbol].include?(syntaxes.class)
    fail ArgumentError, 'Syntaxes must be either an array or a symbol.'
  end

  @source_rewriter.replace(syntaxes_node.loc.expression, syntaxes.inspect)
end

#syntaxesObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/transpec/syntax/rspec_configure.rb', line 46

def syntaxes
  return [] unless syntaxes_node

  case syntaxes_node.type
  when :sym
    [syntaxes_node.children.first]
  when :array
    syntaxes_node.children.map do |child_node|
      child_node.children.first
    end
  else
    fail UnknownSyntaxError, "Unknown syntax specification: #{syntaxes_node}"
  end
end