Class: Puppetfactory::Plugins::Tree
- Inherits:
-
Puppetfactory::Plugins
- Object
- Puppetfactory::Plugins
- Puppetfactory::Plugins::Tree
- Defined in:
- lib/puppetfactory/plugins/tree.rb
Overview
inherit from Puppetfactory::Plugins
Instance Attribute Summary collapse
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Instance Method Summary collapse
-
#initialize(options) ⇒ Tree
constructor
A new instance of Tree.
- #pathwalker(path, parent) ⇒ Object
- #userinfo(username, extended = false) ⇒ Object
Constructor Details
#initialize(options) ⇒ Tree
Returns a new instance of Tree.
7 8 9 10 11 12 |
# File 'lib/puppetfactory/plugins/tree.rb', line 7 def initialize() super() # call the superclass to initialize it @weight = 1 @environments = [:environments] end |
Instance Attribute Details
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
5 6 7 |
# File 'lib/puppetfactory/plugins/tree.rb', line 5 def weight @weight end |
Instance Method Details
#pathwalker(path, parent) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/puppetfactory/plugins/tree.rb', line 27 def pathwalker(path, parent) accumulator = [] Dir.glob("#{path}/*").each do |file| filename = File.basename file # this way .fixtures.yml, etc will show up next if ['.', '..'].include? filename if File.directory?(file) accumulator << { "id" => file, "parent" => parent, "text" => filename } accumulator << pathwalker(file, file) else accumulator << { "id" => file, "parent" => parent, "icon" => "jstree-file", "text" => filename } end end accumulator.flatten end |
#userinfo(username, extended = false) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/puppetfactory/plugins/tree.rb', line 14 def userinfo(username, extended = false) # we can bail if we don't want to add to the basic user object. # for example, if these are heavy operations. return unless extended environment = Puppetfactory::Helpers.environment_name(username) # return a hash with the :username key { :username => username, :tree => pathwalker("#{@environments}/#{environment}", '#' ).to_json, } end |