Class: Puppetfactory::Plugins::Tree

Inherits:
Puppetfactory::Plugins show all
Defined in:
lib/puppetfactory/plugins/tree.rb

Overview

inherit from Puppetfactory::Plugins

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options)
  super(options) # call the superclass to initialize it

  @weight  = 1
  @environments = options[:environments]
end

Instance Attribute Details

#weightObject (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