Class: Yoda::Parsing::TypeParser::Generator

Inherits:
Parslet::Transform
  • Object
show all
Defined in:
lib/yoda/parsing/type_parser.rb

Defined Under Namespace

Classes: Param

Class Method Summary collapse

Class Method Details

.create_function_type(context, param_types, return_type) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/yoda/parsing/type_parser.rb', line 98

def self.create_function_type(context, param_types, return_type)
  func_options = param_types.each_with_object({ context: context, return_type: return_type }).with_index do |(param, func_options), index|
    case param.kind
    when :required
      if func_options[:rest_parameter]
        func_options[:post_parameters] ||= []
        func_options[:post_parameters].push(param.type)
      else
        func_options[:required_parameters] ||= []
        func_options[:required_parameters].push(param.type)
      end
    when :optional
      func_options[:optional_parameters] ||= []
      func_options[:optional_parameters].push(param.type)
    when :rest
      func_options[:rest_parameter] = param.type
    when :required_keyword
      func_options[:required_keyword_parameters] ||= []
      func_options[:required_keyword_parameters].push(param.keyword, param.type)
    when :optional_keyword
      func_options[:optional_keyword_parameters] ||= []
      func_options[:optional_keyword_parameters].push(param.keyword, param.type)
    when :keyword_rest
      func_options[:keyword_rest_parameter] = param.type
    when :block
      func_options[:block_parameter] = param.type
    end
  end

  Model::Types::FunctionType.new(func_options)
end