Class: GlobalSetting::FileProvider
- Inherits:
-
BaseProvider
- Object
- BaseProvider
- GlobalSetting::FileProvider
- Defined in:
- app/models/global_setting.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file) ⇒ FileProvider
constructor
A new instance of FileProvider.
- #keys ⇒ Object
- #lookup(key, default) ⇒ Object
- #read ⇒ Object
Methods inherited from BaseProvider
Constructor Details
#initialize(file) ⇒ FileProvider
Returns a new instance of FileProvider.
272 273 274 275 |
# File 'app/models/global_setting.rb', line 272 def initialize(file) @file = file @data = {} end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
267 268 269 |
# File 'app/models/global_setting.rb', line 267 def data @data end |
Class Method Details
.from(file) ⇒ Object
268 269 270 |
# File 'app/models/global_setting.rb', line 268 def self.from(file) parse(file) if File.exist?(file) end |
Instance Method Details
#keys ⇒ Object
294 295 296 |
# File 'app/models/global_setting.rb', line 294 def keys @data.keys end |
#lookup(key, default) ⇒ Object
289 290 291 292 |
# File 'app/models/global_setting.rb', line 289 def lookup(key, default) var = @data[key] resolve(var, var.nil? ? default : "") end |
#read ⇒ Object
277 278 279 280 281 282 283 284 285 286 287 |
# File 'app/models/global_setting.rb', line 277 def read ERB .new(File.read(@file)) .result() .split("\n") .each do |line| if line =~ /\A\s*([a-z_]+[a-z0-9_]*)\s*=\s*(\"([^\"]*)\"|\'([^\']*)\'|[^#]*)/ @data[$1.strip.to_sym] = ($4 || $3 || $2).strip end end end |