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.



70
71
72
# File 'opal/lib/opal/rewriter.rb', line 70

def initialize(sexp)
  @sexp = sexp
end

Class Method Details

.delete(rewriter) ⇒ Object



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

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

.disable(except: nil) ⇒ Object



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

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

.disabled?Boolean

Returns:

  • (Boolean)


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

def disabled?
  @disabled == true
end

.listObject



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

def list
  @list ||= []
end

.rewritter_disabled?(rewriter) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.use(rewriter) ⇒ Object



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

def use(rewriter)
  list << rewriter
end

Instance Method Details

#processObject



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

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