Class: Faml::AttributeOptimizer

Inherits:
Object
  • Object
show all
Defined in:
lib/faml/attribute_optimizer.rb

Instance Method Summary collapse

Instance Method Details

#try_optimize(old_attributes, new_attributes, static_id, static_class) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/faml/attribute_optimizer.rb', line 9

def try_optimize(old_attributes, new_attributes, static_id, static_class)
  parser = StaticHashParser.new
  unless parser.parse("{#{new_attributes}#{old_attributes}}")
    assert_valid_ruby_code!(old_attributes)
    return [nil, nil]
  end
  if old_attributes && new_attributes
    # TODO: Quit optimization. Merge id and class correctly.
    return [nil, nil]
  end

  static_attributes, dynamic_attributes = build_optimized_attributes(parser, static_id, static_class)
  if optimizable?(old_attributes, new_attributes, static_attributes, dynamic_attributes)
    [static_attributes, dynamic_attributes]
  else
    [nil, nil]
  end
end