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.



74
75
76
# File 'opal/lib/opal/rewriter.rb', line 74

def initialize(sexp)
  @sexp = sexp
end

Class Method Details

.delete(rewriter) ⇒ Object



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

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

.disable(except: nil) ⇒ Object



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

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

.disabled?Boolean

Returns:

  • (Boolean)


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

def disabled?
  @disabled == true
end

.listObject



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

def list
  @list ||= []
end

.rewritter_disabled?(rewriter) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.use(rewriter) ⇒ Object



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

def use(rewriter)
  list << rewriter
end

Instance Method Details

#processObject



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

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