Class: WorldSettings
- Inherits:
-
Object
- Object
- WorldSettings
- Defined in:
- lib/cl/magic/dk/world_settings.rb
Instance Method Summary collapse
- #get_code_path_from_settings ⇒ Object
- #get_world_path_from_settings ⇒ Object
- #get_world_project_path ⇒ Object
-
#get_world_settings_hash ⇒ Object
world settings.
-
#get_world_yml_hash ⇒ Object
world yaml.
-
#initialize(working_dir) ⇒ WorldSettings
constructor
A new instance of WorldSettings.
- #save_world_settings(world_settings_hash) ⇒ Object
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_settings ⇒ Object
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_settings ⇒ Object
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_path ⇒ Object
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_hash ⇒ Object
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_hash ⇒ Object
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 |