Class: Parsers::NativeFunction

Inherits:
Object
  • Object
show all
Defined in:
lib/retrospec/plugins/v1/plugin/generators/parsers/native_function.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ NativeFunction

Returns a new instance of NativeFunction.



7
8
9
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/native_function.rb', line 7

def initialize(file)
  @manifest_file = file
end

Instance Attribute Details

#manifest_fileObject (readonly)

Returns the value of attribute manifest_file.



5
6
7
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/native_function.rb', line 5

def manifest_file
  @manifest_file
end

Class Method Details

.load_function(file) ⇒ OpenStruct

Returns - a object with name and parameters.

Parameters:

  • - (String)

    path to the function file

Returns:

  • (OpenStruct)
    • a object with name and parameters



13
14
15
16
17
18
19
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/native_function.rb', line 13

def self.load_function(file)
  f = new(file)
  @model = OpenStruct.new(:name => f.definition.name,
                          :parameters => f.parameter_list,
                          :parameter_names => f.parameter_list.keys)
  @model
end

Instance Method Details

#astObject



21
22
23
24
25
26
27
28
29
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/native_function.rb', line 21

def ast
  unless @ast
    raise ArgumentError, 'please set the manifest file' if manifest_file.nil?
    parser = ::Puppet::Pops::Parser::EvaluatingParser.new
    result = parser.parse_file(manifest_file)
    @ast = result.current
  end
  @ast
end

#bodyObject

return a manifest body object



40
41
42
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/native_function.rb', line 40

def body
  ast.body.body
end

#definitionObject



35
36
37
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/native_function.rb', line 35

def definition
  ast.body
end

#dumperObject



31
32
33
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/native_function.rb', line 31

def dumper
  @dumper ||= Retrospec::Puppet::RspecDumper.new
end

#function_nameObject



48
49
50
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/native_function.rb', line 48

def function_name
  body.name
end

#parameter_listObject



52
53
54
55
56
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/native_function.rb', line 52

def parameter_list
  list = {}
  parameters.each { |p| list[p.name.to_sym] = p.value }
  list
end

#parametersObject



44
45
46
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/native_function.rb', line 44

def parameters
  ast.body.parameters
end