Class: Syntaxer::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/syntaxer/writer.rb

Constant Summary collapse

EXCLUDE_PROPERTIES =

Recreate config DSL string operation general rules and set of languages

"executor", "exec_existence", "deferred", "name"

Instance Method Summary collapse

Constructor Details

#initialize(langs, rules) ⇒ Writer

Initializing Writer

Parameters:

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/syntaxer/writer.rb', line 12

def initialize langs, rules
  raise ArgumentError unless rules.kind_of?(LanguageRules)
  @config = ''
  @allowed_methods = ["syntaxer", "lang", "languages"]

  @config = syntaxer do
    lang_st = ''
    langs.each do |l|
      language = l.first
      @paths = l.last
      rule = rules.find(language)
      next if rule.nil?
      
      @allowed_methods += rule.members if (rule.members - @allowed_methods).length > 0
      lang_st += languages(rule.send(:name)) do
        prop_st = ''
        rule.members.each do |m|
          properties = rule.send(m)
          prop_st += property(m, properties) if m != "name"
        end
        prop_st
      end
    end
    lang_st
  end

end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &b) ⇒ Object (protected)



48
49
50
51
52
53
54
55
56
# File 'lib/syntaxer/writer.rb', line 48

def method_missing name, *args, &b
  name = name.to_sym
  super unless @allowed_methods.include?(name.to_s)
  if name == :lang || name == :syntaxer || name == :languages
    block(name, args.first, &b)
  else
    property(name, args)
  end
end

Instance Method Details

#get_configString

return config

Returns:

  • (String)

    DSL config string



43
44
45
# File 'lib/syntaxer/writer.rb', line 43

def get_config
  @config
end