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.



64
65
66
# File 'opal/lib/opal/rewriter.rb', line 64

def initialize(sexp)
  @sexp = sexp
end

Class Method Details

.delete(rewriter) ⇒ Object



31
32
33
# File 'opal/lib/opal/rewriter.rb', line 31

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

.disableObject



35
36
37
38
39
40
# File 'opal/lib/opal/rewriter.rb', line 35

def disable
  @disabled = true
  yield
ensure
  @disabled = false
end

.disabled?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'opal/lib/opal/rewriter.rb', line 42

def disabled?
  @disabled if defined?(@disabled)
end

.listObject



23
24
25
# File 'opal/lib/opal/rewriter.rb', line 23

def list
  @list ||= []
end

.use(rewriter) ⇒ Object



27
28
29
# File 'opal/lib/opal/rewriter.rb', line 27

def use(rewriter)
  list << rewriter
end

Instance Method Details

#processObject



68
69
70
71
72
73
74
75
76
77
# File 'opal/lib/opal/rewriter.rb', line 68

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

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

  @sexp
end