file_resources_manager 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,25 +1,25 @@
1
1
  require 'file_resources_manager'
2
2
 
3
3
  class SettingsManager
4
- attr_accessor :name,:file_type,:file_location,:filename,:data
4
+ attr_accessor :name,:file_type,:file_path,:filename,:data
5
5
 
6
6
  def initialize(settings_name)
7
7
  @name = settings_name
8
- @data,@file_type,@file_location,@filename = nil
8
+ @data,@file_type,@file_path,@filename = nil
9
9
  load_data
10
10
  end
11
11
 
12
12
  def load_data
13
13
  smd = SettingsManager.settings_manager_data[@name]
14
- @file_location = Dir.pwd
14
+ @file_path = Dir.pwd
15
15
  @filename = @name
16
16
  @file_type = :yaml
17
17
  if smd then
18
18
  @file_type = smd["file_type"].to_sym
19
- @file_location = smd["file_location"] || Dir.pwd
19
+ @file_path = smd["file_path"] || Dir.pwd
20
20
  @filename = smd["filename"] || @name
21
21
 
22
- data = File.read(File.join(@file_location,@filename))
22
+ data = File.read(File.join(@file_path,@filename))
23
23
  @data=self.send("decode_" + @file_type.to_s,data)
24
24
  else
25
25
  @data={}
@@ -28,7 +28,7 @@ class SettingsManager
28
28
  end
29
29
 
30
30
  def save_data
31
- File.open(File.join(@file_location,@filename),"w"){|f|
31
+ File.open(File.join(@file_path,@filename),"w"){|f|
32
32
  case @file_type
33
33
  when nil
34
34
  @file_type = :yaml
@@ -39,7 +39,7 @@ class SettingsManager
39
39
  }
40
40
  file_data = {}
41
41
  file_data["file_type"] = @file_type.to_s if @file_type
42
- file_data["file_location"] = @file_location if @file_location
42
+ file_data["file_path"] = @file_path if @file_path
43
43
  file_data["filename"] = @filename if @filename
44
44
  smd = SettingsManager.settings_manager_data
45
45
  smd[@name] = file_data
@@ -60,6 +60,10 @@ class SettingsManager
60
60
  def [](key)
61
61
  @data[key]
62
62
  end
63
+
64
+ def file_path=(file_path)
65
+ @file_path = File::expand_path(file_path)
66
+ end
63
67
 
64
68
  def self.settings(settings_name)
65
69
  self.new(settings_name)
@@ -22,13 +22,13 @@ class TestSettingsManager < Test::Unit::TestCase
22
22
  ENV["APP_SETTING"] = @@test_directory_location
23
23
  settings_name = "test_database_info"
24
24
  settings = SettingsManager.settings(settings_name)
25
- settings.file_location = @@test_directory_location
25
+ settings.file_path = @@test_directory_location
26
26
  assert_not_equal(settings,nil,"an empty settings file should not be nil")
27
27
  assert_equal(settings.name,settings_name, "just the settings name is set")
28
28
  assert_equal(settings.file_type,:yaml,"should be defaulted to yaml")
29
29
  settings["server"] = "127.0.0.1"
30
30
  assert_equal(settings["server"],"127.0.0.1","server address should match 127.0.0.1")
31
- assert_equal(settings.file_location,@@test_directory_location ,"should be equal to the current directory")
31
+ assert_equal(settings.file_path,@@test_directory_location ,"should be equal to the current directory")
32
32
  assert_equal(settings.filename,settings.name,"should equal the name test_database_info")
33
33
  settings.save_data
34
34
 
@@ -38,7 +38,7 @@ class TestSettingsManager < Test::Unit::TestCase
38
38
  assert_equal(settings["server"],"127.0.0.1","it should still equal home")
39
39
 
40
40
  settings2 = SettingsManager.settings(settings_name+"2")
41
- settings2.file_location = @@test_directory_location
41
+ settings2.file_path = @@test_directory_location
42
42
  settings2.file_type = :csv
43
43
  settings2["server"] = "1.1.1.1"
44
44
  settings2.save_data
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file_resources_manager
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 1
10
- version: 1.0.1
9
+ - 2
10
+ version: 1.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Branden Giacoletto