Skip to content

Commit

Permalink
Provide workshop level variables to content
Browse files Browse the repository at this point in the history
  • Loading branch information
marekjelen committed Jul 16, 2018
1 parent 8c38e04 commit d69b515
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
12 changes: 8 additions & 4 deletions lib/workshopper/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ module Workshopper

class Content

def initialize(prefix)
@prefix = prefix
@data = Workshopper::Loader.get(File.join(@prefix, '_modules.yml'))
def initialize(workshop)
@workshop = workshop
@data = Workshopper::Loader.get(File.join(prefix, '_modules.yml'))
@data = YAML.load(@data)
@data['config'] = {
'renderer' => 'adoc',
Expand All @@ -22,12 +22,16 @@ def initialize(prefix)
end
end

def workshop
@workshop
end

def lab(name)
@labs[name] ||= Workshopper::Lab.new(self, name)
end

def prefix
@prefix
@workshop.prefix
end

def ext
Expand Down
8 changes: 6 additions & 2 deletions lib/workshopper/lab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@ def env(workshop, session)
env[item] = @content.env[item]['value']
end if @lab['vars']

ENV.each_pair do |name, value|
@content.workshop.vars.each_pair do |name, value|
env[name] = value
end if @content.workshop.vars

env.each_key do |key|
env[key] = ENV[key] if ENV[key]
end

env.each_key do |key|
env[key] = session[key] if session[key]
end

if env['DYNAMIC_USER_NAME'] || true
if env['DYNAMIC_USER_NAME']
@user_id ||= 0
if env['NUM_USERS'] && env['NUM_USERS'] > 0 && @user_id >= Integer(env['NUM_USERS'])
raise Exception.new('Not enough users in workshop environment')
Expand Down
6 changes: 5 additions & 1 deletion lib/workshopper/workshop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialize(url)

@id = @data['id']

@content = Content.new(prefix)
@content = Content.new(self)
end

def prefix
Expand All @@ -31,6 +31,10 @@ def name
@data['name']
end

def vars
@data['vars']
end

def active_labs
@data['modules']['activate']
end
Expand Down

0 comments on commit d69b515

Please sign in to comment.