Class: Ruote::MutationPoint

Inherits:
Object
  • Object
show all
Defined in:
lib/ruote/dboard/mutation.rb

Overview

Gathers info about a possible mutation. The point of application (fei), the new tree (tree) and if it's a re_apply or an update (only changing the tree of the expression behind (fei)).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fei, tree, type) ⇒ MutationPoint


39
40
41
42
43
44
# File 'lib/ruote/dboard/mutation.rb', line 39

def initialize(fei, tree, type)

  @fei = fei
  @tree = tree
  @type = type
end

Instance Attribute Details

#feiObject (readonly)

Returns the value of attribute fei


35
36
37
# File 'lib/ruote/dboard/mutation.rb', line 35

def fei
  @fei
end

#treeObject (readonly)

Returns the value of attribute tree


36
37
38
# File 'lib/ruote/dboard/mutation.rb', line 36

def tree
  @tree
end

#typeObject (readonly)

:re_apply or :update


37
38
39
# File 'lib/ruote/dboard/mutation.rb', line 37

def type
  @type
end

Instance Method Details

#apply(dboard, option = nil) ⇒ Object


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ruote/dboard/mutation.rb', line 60

def apply(dboard, option=nil)

  option ||= @type
  option = option.to_sym

  return if option != :force_update && option != @type

  type = option == :force_update ? :update : @type

  if type == :re_apply
    dboard.re_apply(@fei, :tree => @tree)
  else
    dboard.update_expression(@fei, :tree => @tree)
  end
end

#to_sObject


46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ruote/dboard/mutation.rb', line 46

def to_s

  s = []
  s << self.class.name
  s << "  at:      #{@fei.sid} (#{@fei.expid})"
  s << "  action:  #{@type.inspect}"
  s << "  tree:"

  s.concat(
    Ruote::Reader.to_radial(@tree).split("\n").map { |l| "    | #{l}" })

  s.join("\n")
end