Module: PuppetRepl::Support
- Included in:
- Cli
- Defined in:
- lib/puppet-repl/support.rb,
lib/puppet-repl/support/node.rb,
lib/puppet-repl/support/facts.rb,
lib/puppet-repl/support/scope.rb,
lib/puppet-repl/support/compiler.rb,
lib/puppet-repl/support/functions.rb,
lib/puppet-repl/support/environment.rb
Defined Under Namespace
Modules: Compilier, Environment, Facts, Functions, Node, Scope
Instance Method Summary collapse
- #compiler ⇒ Object
-
#do_initialize ⇒ Object
this is required in order to load things only when we need them.
- #known_resource_types ⇒ Object
- #lib_dirs ⇒ Object
- #load_lib_dirs ⇒ Object
- #manifests_dir ⇒ Object
-
#mod_finder ⇒ Object
returns either the module name or puppet version.
-
#module_dirs ⇒ Object
returns an array of module directories.
-
#node ⇒ node
Puppet node object.
-
#parser ⇒ Object
returns a future parser for evaluating code.
- #puppet_lib_dir ⇒ Object
-
#scope ⇒ Scope
Puppet scope object.
Methods included from Node
Methods included from Functions
#function_files, #function_map
Methods included from Scope
Methods included from Facts
Methods included from Environment
#environment_loaders, #puppet_env_name, #puppet_environment
Methods included from Compilier
Instance Method Details
#compiler ⇒ Object
81 82 83 |
# File 'lib/puppet-repl/support.rb', line 81 def compiler @compiler end |
#do_initialize ⇒ Object
this is required in order to load things only when we need them
46 47 48 49 50 51 52 |
# File 'lib/puppet-repl/support.rb', line 46 def do_initialize begin Puppet.initialize_settings rescue # do nothing otherwise calling init twice raises an error end end |
#known_resource_types ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/puppet-repl/support.rb', line 26 def known_resource_types res = { :hostclasses => scope.known_resource_types.hostclasses.keys, :definitions => scope.known_resource_types.definitions.keys, :nodes => scope.known_resource_types.nodes.keys, } if sites = scope.known_resource_types.instance_variable_get(:@sites) res.merge!(:sites => scope.known_resource_types.instance_variable_get(:@sites).first) end if scope.known_resource_types.respond_to?(:applications) res.merge!(:applications => scope.known_resource_types.applications.keys) end # some versions of puppet do not support capabilities if scope.known_resource_types.respond_to?(:capability_mappings) res.merge!(:capability_mappings => scope.known_resource_types.capability_mappings.keys) end res end |
#lib_dirs ⇒ Object
64 65 66 67 68 |
# File 'lib/puppet-repl/support.rb', line 64 def lib_dirs module_dirs.map do |mod_dir| Dir["#{mod_dir}/*/lib"].entries end.flatten end |
#load_lib_dirs ⇒ Object
70 71 72 73 74 |
# File 'lib/puppet-repl/support.rb', line 70 def load_lib_dirs lib_dirs.each do |lib| $LOAD_PATH << lib end end |
#manifests_dir ⇒ Object
99 100 101 |
# File 'lib/puppet-repl/support.rb', line 99 def manifests_dir File.join(Puppet[:environmentpath],puppet_env_name,'manifests') end |
#mod_finder ⇒ Object
returns either the module name or puppet version
60 61 62 |
# File 'lib/puppet-repl/support.rb', line 60 def mod_finder @mod_finder ||= Regexp.new('\/([\w\-\.]+)\/lib') end |
#module_dirs ⇒ Object
returns an array of module directories
18 19 20 21 22 23 24 |
# File 'lib/puppet-repl/support.rb', line 18 def module_dirs dirs = [] do_initialize if Puppet[:codedir].nil? dirs << File.join(Puppet[:environmentpath],puppet_env_name,'modules') unless Puppet[:environmentpath].empty? dirs << Puppet.settings[:basemodulepath].split(':') dirs.flatten end |
#node ⇒ node
Returns puppet node object.
86 87 88 |
# File 'lib/puppet-repl/support.rb', line 86 def node @node ||= create_node end |
#parser ⇒ Object
returns a future parser for evaluating code
77 78 79 |
# File 'lib/puppet-repl/support.rb', line 77 def parser @parser || ::Puppet::Pops::Parser::EvaluatingParser.new end |
#puppet_lib_dir ⇒ Object
54 55 56 57 |
# File 'lib/puppet-repl/support.rb', line 54 def puppet_lib_dir # returns something like "/Library/Ruby/Gems/2.0.0/gems/puppet-4.2.2/lib/puppet.rb" @puppet_lib_dir ||= File.dirname(Puppet.method(:[]).source_location.first) end |
#scope ⇒ Scope
Returns puppet scope object.
91 92 93 94 95 96 97 |
# File 'lib/puppet-repl/support.rb', line 91 def scope unless @scope do_initialize @scope ||= create_scope(node) end @scope end |