application_configuration 1.1.10 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,44 +6,7 @@ module Application
6
6
 
7
7
  class Configuration
8
8
 
9
- # this class is used to namespace configurations
10
- class Namespace
11
-
12
- attr_accessor :namespace_name
13
-
14
- def initialize(name)
15
- self.namespace_name = name
16
- end
17
-
18
- def to_s
19
- self.namespace_name
20
- end
21
-
22
- def method_missing(sym, *args)
23
- Application::Configuration.send("#{self}__#{sym}", *args)
24
- end
25
-
26
- end
27
-
28
- class Location
29
-
30
- attr_accessor :type
31
- attr_accessor :file_location
32
-
33
- def initialize(loc, type = Application::Configuration::Location::FILE)
34
- self.type = type
35
- self.file_location = loc
36
- end
37
-
38
- def self.supported_types
39
- [Application::Configuration::Location::FILE, Application::Configuration::Location::URL]
40
- end
41
-
42
- FILE = :file
43
- URL = :url
44
-
45
- end
46
-
9
+ DEFAULT_RELOAD_SETTINGS_EVERY = 1200
47
10
 
48
11
  include Singleton
49
12
 
@@ -52,7 +15,7 @@ module Application
52
15
  def method_missing(sym, *args)
53
16
  inst = Application::Configuration.instance
54
17
  # check to see if the configuration needs to be reloaded.
55
- if (Time.now - (inst.reload_settings_every || 0)) > inst.last_reload_time
18
+ if (Time.now - (inst.reload_settings_every || DEFAULT_RELOAD_SETTINGS_EVERY)) > inst.last_reload_time
56
19
  inst.reload
57
20
  end
58
21
  inst.send(sym, *args)
@@ -60,18 +23,18 @@ module Application
60
23
 
61
24
  end
62
25
 
63
- attr_reader :final_configuration_settings #stores the final configuration settings
64
- attr_reader :last_reload_time #stores the last time settings were reloaded
65
- attr_reader :is_rails #stores whether or not we're in a rails app
66
- attr_reader :loaded_files
67
- attr_reader :rails_root
68
- attr_reader :rails_env
26
+ attr_reader :final_configuration_settings #stores the final configuration settings
27
+ attr_reader :last_reload_time #stores the last time settings were reloaded
28
+ attr_reader :is_rails #stores whether or not we're in a rails app
29
+ attr_reader :loaded_files
30
+ attr_reader :rails_root
31
+ attr_reader :rails_env
69
32
  attr_accessor :whiny_config_missing
70
33
 
71
34
  def initialize
72
35
  self.whiny_config_missing = false
73
36
  @loaded_files = []
74
- @final_configuration_settings = {}
37
+ @final_configuration_settings = {:reload_settings_every => DEFAULT_RELOAD_SETTINGS_EVERY}
75
38
  @last_reload_time = Time.now # set the first load time
76
39
  @is_rails = Object.const_defined?("RAILS_ENV") # set whether it's rails
77
40
  if self.is_rails
@@ -89,7 +52,7 @@ module Application
89
52
  unless path_to_file.nil?
90
53
  begin
91
54
  path_to_file = Application::Configuration::Location.new(path_to_file) if path_to_file.is_a? String
92
- settings = load_from_file(path_to_file.file_location)
55
+ settings = load_from_file(path_to_file.name)
93
56
  handle_settings(settings, path_to_file)
94
57
  return self
95
58
  rescue Exception => e
@@ -103,7 +66,7 @@ module Application
103
66
  unless path_to_file.nil?
104
67
  begin
105
68
  path_to_file = Application::Configuration::Location.new(path_to_file, Application::Configuration::Location::URL) if path_to_file.is_a? String
106
- settings = load_from_url(path_to_file.file_location)
69
+ settings = load_from_url(path_to_file.name)
107
70
  handle_settings(settings, path_to_file)
108
71
  return self
109
72
  rescue Exception => e
@@ -113,17 +76,28 @@ module Application
113
76
  end
114
77
  end
115
78
 
79
+ def load_hash(settings, name)
80
+ loc = Application::Configuration::Location.new(name, Application::Configuration::Location::HASH)
81
+ loc.options = settings
82
+ handle_settings(settings, loc)
83
+ return self
84
+ end
85
+
116
86
  def reload
117
87
  puts "Loading Configuration Settings!"
118
- @final_configuration_settings = {:reload_settings_every => 1200} # reset the configuration
88
+ @final_configuration_settings = {:reload_settings_every => DEFAULT_RELOAD_SETTINGS_EVERY} # reset the configuration
119
89
 
120
90
  self.loaded_files.each do |lf|
121
- puts "Loading Configuration Settings from file: #{lf.file_location}"
122
91
  case lf.type
123
92
  when Application::Configuration::Location::FILE
93
+ puts "Loading Configuration Settings from file: #{lf.name}"
124
94
  load_file(lf)
125
95
  when Application::Configuration::Location::URL
96
+ puts "Loading Configuration Settings from url: #{lf.name}"
126
97
  load_url(lf)
98
+ when Application::Configuration::Location::HASH
99
+ puts "Loading Configuration Settings from hash: #{lf.name}"
100
+ load_hash(lf.options, lf.name)
127
101
  else
128
102
  raise TypeError.new("The Application::Configuration::Location type '#{lf.type}' is not supported!")
129
103
  end
@@ -162,9 +136,9 @@ WARNING: Tried to access configuration parameter: #{sym}, but there is no config
162
136
  YAML.load(template.result)
163
137
  end
164
138
 
165
- def handle_settings(settings, path_to_file)
139
+ def handle_settings(settings, location)
166
140
  @final_configuration_settings.merge!(settings || {})
167
-
141
+ # puts "@final_configuration_settings: #{@final_configuration_settings.inspect}"
168
142
  self.final_configuration_settings.each_pair do |k,v|
169
143
  k = k.to_s.downcase
170
144
  # start a list of methods that need to be generated
@@ -189,10 +163,62 @@ WARNING: Tried to access configuration parameter: #{sym}, but there is no config
189
163
  end
190
164
  end
191
165
 
192
- @loaded_files << path_to_file
166
+ @loaded_files << location
193
167
  @loaded_files.uniq!
194
168
  end
195
169
 
170
+ # this class is used to namespace configurations
171
+ class Namespace
172
+
173
+ attr_accessor :namespace_name
174
+
175
+ def initialize(name)
176
+ self.namespace_name = name
177
+ end
178
+
179
+ def to_s
180
+ self.namespace_name
181
+ end
182
+
183
+ def method_missing(sym, *args)
184
+ Application::Configuration.send("#{self}__#{sym}", *args)
185
+ end
186
+
187
+ end
188
+
189
+ class Location
190
+
191
+ attr_accessor :type
192
+ attr_accessor :name
193
+ attr_accessor :options
194
+
195
+ def initialize(loc, type = Application::Configuration::Location::FILE)
196
+ self.type = type
197
+ self.name = loc
198
+ end
199
+
200
+ def self.supported_types
201
+ [Application::Configuration::Location::FILE, Application::Configuration::Location::URL, Application::Configuration::Location::HASH]
202
+ end
203
+
204
+ FILE = :file
205
+ URL = :url
206
+ HASH = :hash
207
+
208
+ def ==(other)
209
+ self.name.to_s == other.name.to_s
210
+ end
211
+
212
+ def eql?(other)
213
+ self.name.to_s == other.name.to_s
214
+ end
215
+
216
+ def hash
217
+ self.name.to_s.hash
218
+ end
219
+
220
+ end
221
+
196
222
  end
197
223
 
198
224
  end
@@ -2,4 +2,4 @@
2
2
  gem_name: application_configuration
3
3
  package: application_configuration
4
4
  project: magrathea
5
- version: 1.1.10
5
+ version: 1.2.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: application_configuration
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.10
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - markbates
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2008-01-31 00:00:00 -05:00
14
+ date: 2008-02-18 00:00:00 -05:00
15
15
  default_executable:
16
16
  dependencies: []
17
17