Class: Parsers::NativeFunction
- Inherits:
-
Object
- Object
- Parsers::NativeFunction
- Defined in:
- lib/retrospec/plugins/v1/plugin/generators/parsers/native_function.rb
Instance Attribute Summary collapse
-
#manifest_file ⇒ Object
readonly
Returns the value of attribute manifest_file.
Class Method Summary collapse
-
.load_function(file) ⇒ OpenStruct
-
a object with name and parameters.
-
Instance Method Summary collapse
- #ast ⇒ Object
-
#body ⇒ Object
return a manifest body object.
- #definition ⇒ Object
- #dumper ⇒ Object
- #function_name ⇒ Object
-
#initialize(file) ⇒ NativeFunction
constructor
A new instance of NativeFunction.
- #parameter_list ⇒ Object
- #parameters ⇒ Object
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_file ⇒ Object (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.
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
#ast ⇒ Object
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 |
#body ⇒ Object
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 |
#definition ⇒ Object
35 36 37 |
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/native_function.rb', line 35 def definition ast.body end |
#dumper ⇒ Object
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_name ⇒ Object
48 49 50 |
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/native_function.rb', line 48 def function_name body.name end |
#parameter_list ⇒ Object
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 |
#parameters ⇒ Object
44 45 46 |
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/native_function.rb', line 44 def parameters ast.body.parameters end |