Class: Faml::StaticHashParser

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

Constant Summary collapse

FAILURE_TAG =
:failure
SPECIAL_ATTRIBUTES =
%w[id class data].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStaticHashParser

Returns a new instance of StaticHashParser.



12
13
14
15
# File 'lib/faml/static_hash_parser.rb', line 12

def initialize
  @static_attributes = {}
  @dynamic_attributes = {}
end

Instance Attribute Details

#dynamic_attributesObject (readonly)

Returns the value of attribute dynamic_attributes.



10
11
12
# File 'lib/faml/static_hash_parser.rb', line 10

def dynamic_attributes
  @dynamic_attributes
end

#static_attributesObject (readonly)

Returns the value of attribute static_attributes.



10
11
12
# File 'lib/faml/static_hash_parser.rb', line 10

def static_attributes
  @static_attributes
end

Instance Method Details

#parse(text) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/faml/static_hash_parser.rb', line 17

def parse(text)
  parser = ::Parser::CurrentRuby.default_parser
  parser.builder.emit_file_line_as_literals = false
  parser.diagnostics.consumer = nil
  buffer = ::Parser::Source::Buffer.new('(faml)')
  buffer.source = text
  walk(parser.parse(buffer))
rescue ::Parser::SyntaxError
  false
end

#walk(node) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/faml/static_hash_parser.rb', line 28

def walk(node)
  catch(FAILURE_TAG) do
    walk_hash(node)
    return true
  end
  false
end