Class: Opal::Rewriter

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sexp) ⇒ Rewriter

Returns a new instance of Rewriter.



76
77
78
# File 'lib/opal/rewriter.rb', line 76

def initialize(sexp)
  @sexp = sexp
end

Class Method Details

.delete(rewriter) ⇒ Object



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

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

.disable(except: nil) ⇒ Object



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

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

.disabled?Boolean

Returns:

  • (Boolean)


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

def disabled?
  @disabled == true
end

.listObject



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

def list
  @list ||= []
end

.rewritter_disabled?(rewriter) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.use(rewriter) ⇒ Object



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

def use(rewriter)
  list << rewriter
end

Instance Method Details

#processObject



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

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