Class: RubyHeaderParser::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_header_parser/config.rb

Overview

Manager for config file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file) ⇒ Config

Note:

See CONFIG.md for config file details

Returns a new instance of Config.

Parameters:

  • config_file (String)


13
14
15
16
# File 'lib/ruby_header_parser/config.rb', line 13

def initialize(config_file)
  yaml = File.read(config_file)
  @data = YAML.safe_load(yaml, aliases: true, permitted_classes: [Regexp])
end

Instance Attribute Details

#dataHash (readonly)

Returns:

  • (Hash)


8
9
10
# File 'lib/ruby_header_parser/config.rb', line 8

def data
  @data
end

Instance Method Details

#function_arg_pointer_hint(function_name:, pos:) ⇒ Symbol

Returns :ref, :array, :ref_array, :function, :sref, :str_array, :in_ref.

Parameters:

  • function_name (String)
  • pos (Integer)

    arg position (1 origin)

Returns:

  • (Symbol)

    :ref, :array, :ref_array, :function, :sref, :str_array, :in_ref



21
22
23
24
25
26
# File 'lib/ruby_header_parser/config.rb', line 21

def function_arg_pointer_hint(function_name:, pos:)
  pointer_hint = data["function"]["pointer_hint"].dig(function_name, pos)
  return pointer_hint.to_sym if pointer_hint

  :ref
end

#function_self_pointer_hint(function_name) ⇒ Symbol

Returns :ref, :raw.

Parameters:

  • function_name (String)

Returns:

  • (Symbol)

    :ref, :raw



30
31
32
33
34
35
# File 'lib/ruby_header_parser/config.rb', line 30

def function_self_pointer_hint(function_name)
  pointer_hint = data["function"]["pointer_hint"].dig(function_name, "self")
  return pointer_hint.to_sym if pointer_hint

  :ref
end

#should_generate_enum?(enum_name) ⇒ Boolean

Whether generate C enum to go

Parameters:

  • enum_name (String)

Returns:

  • (Boolean)


69
70
71
72
73
# File 'lib/ruby_header_parser/config.rb', line 69

def should_generate_enum?(enum_name)
  return false if data["enum"]["exclude_name"].any? { |format| format === enum_name }

  data["enum"]["include_name"].any? { |format| format === enum_name }
end

#should_generate_function?(function_name) ⇒ Boolean

Whether generate C function to go

Parameters:

  • function_name (String)

Returns:

  • (Boolean)


42
43
44
45
46
# File 'lib/ruby_header_parser/config.rb', line 42

def should_generate_function?(function_name)
  return false if data["function"]["exclude_name"].any? { |format| format === function_name }

  data["function"]["include_name"].any? { |format| format === function_name }
end

#should_generate_struct?(struct_name) ⇒ Boolean

Whether generate C struct to go

Parameters:

  • struct_name (String)

Returns:

  • (Boolean)


51
52
53
54
55
# File 'lib/ruby_header_parser/config.rb', line 51

def should_generate_struct?(struct_name)
  return false if data["struct"]["exclude_name"].any? { |format| format === struct_name }

  data["struct"]["include_name"].any? { |format| format === struct_name }
end

#should_generate_type?(type_name) ⇒ Boolean

Whether generate C type to go

Parameters:

  • type_name (String)

Returns:

  • (Boolean)


60
61
62
63
64
# File 'lib/ruby_header_parser/config.rb', line 60

def should_generate_type?(type_name)
  return false if data["type"]["exclude_name"].any? { |format| format === type_name }

  data["type"]["include_name"].any? { |format| format === type_name }
end