Class: Opal::Rewriter

Inherits:
Object
  • Object
show all
Defined in:
opal/lib/opal/rewriter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sexp) ⇒ Rewriter

Returns a new instance of Rewriter.



72
73
74
# File 'opal/lib/opal/rewriter.rb', line 72

def initialize(sexp)
  @sexp = sexp
end

Class Method Details

.delete(rewriter) ⇒ Object



33
34
35
# File 'opal/lib/opal/rewriter.rb', line 33

def delete(rewriter)
  list.delete(rewriter)
end

.disable(except: nil) ⇒ Object



37
38
39
40
41
42
43
# File 'opal/lib/opal/rewriter.rb', line 37

def disable(except: nil)
  old_disabled = @disabled
  @disabled = except || true
  yield
ensure
  @disabled = old_disabled
end

.disabled?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'opal/lib/opal/rewriter.rb', line 45

def disabled?
  @disabled == true
end

.listObject



25
26
27
# File 'opal/lib/opal/rewriter.rb', line 25

def list
  @list ||= []
end

.rewritter_disabled?(rewriter) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
# File 'opal/lib/opal/rewriter.rb', line 49

def rewritter_disabled?(rewriter)
  return false if @disabled == false
  @disabled != rewriter
end

.use(rewriter) ⇒ Object



29
30
31
# File 'opal/lib/opal/rewriter.rb', line 29

def use(rewriter)
  list << rewriter
end

Instance Method Details

#processObject



76
77
78
79
80
81
82
83
84
85
86
# File 'opal/lib/opal/rewriter.rb', line 76

def process
  return @sexp if self.class.disabled?

  self.class.list.each do |rewriter_class|
    next if self.class.rewritter_disabled?(rewriter_class)
    rewriter = rewriter_class.new
    @sexp = rewriter.process(@sexp)
  end

  @sexp
end