Class: WorldSettings

Inherits:
Object
  • Object
show all
Defined in:
lib/cl/magic/dk/world_settings.rb

Instance Method Summary collapse

Constructor Details

#initialize(working_dir) ⇒ WorldSettings

Returns a new instance of WorldSettings.



6
7
8
# File 'lib/cl/magic/dk/world_settings.rb', line 6

def initialize(working_dir)
  @working_dir = working_dir
end

Instance Method Details

#get_code_path_from_settingsObject



55
56
57
58
59
60
61
# File 'lib/cl/magic/dk/world_settings.rb', line 55

def get_code_path_from_settings()
  world_settings = get_world_settings_hash()
  if world_settings.key?(:code_path)
    return File.join(world_settings[:code_path])
  end
  return ""
end

#get_world_path_from_settingsObject



47
48
49
50
51
52
53
# File 'lib/cl/magic/dk/world_settings.rb', line 47

def get_world_path_from_settings()
  world_settings = get_world_settings_hash()
  if world_settings.key?(:world_path) and world_settings.key?(:context)
    return File.join(world_settings[:world_path], world_settings[:context])
  end
  return ""
end

#get_world_project_pathObject



40
41
42
43
44
45
# File 'lib/cl/magic/dk/world_settings.rb', line 40

def get_world_project_path()
  repo_basename = get_repo_basename()
  world_path = get_world_path_from_settings()
  return File.join(world_path, repo_basename) if world_path and repo_basename
  return nil
end

#get_world_settings_hashObject

world settings



28
29
30
31
# File 'lib/cl/magic/dk/world_settings.rb', line 28

def get_world_settings_hash()
  filepath = get_world_settings_filepath()
  return File.exist?(filepath) ? YAML.load_file(filepath) : {}
end

#get_world_yml_hashObject

world yaml



14
15
16
17
18
19
20
21
22
# File 'lib/cl/magic/dk/world_settings.rb', line 14

def get_world_yml_hash()
  yaml_filepath = File.join(self.get_world_path_from_settings, "world.yml")
  if File.exist?(yaml_filepath)
    contents = File.read(yaml_filepath)
    contents.gsub!('<dk-working-path>', @working_dir)
    return YAML.load(contents)
  end
  return nil
end

#save_world_settings(world_settings_hash) ⇒ Object



33
34
35
36
37
38
# File 'lib/cl/magic/dk/world_settings.rb', line 33

def save_world_settings(world_settings_hash)
  filepath = get_world_settings_filepath()
  tempfile = File.new(filepath, 'w')
  tempfile.write(world_settings_hash.to_yaml)
  tempfile.close
end