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.



13
14
15
16
17
# File 'lib/transpec/syntax/rspec_configure.rb', line 13

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



34
35
36
37
38
39
40
# File 'lib/transpec/syntax/rspec_configure.rb', line 34

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/transpec/syntax/rspec_configure.rb', line 19

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
  end
end