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.
306 307 308 309 |
# File 'app/models/global_setting.rb', line 306 def initialize(file) @file = file @data = {} end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
301 302 303 |
# File 'app/models/global_setting.rb', line 301 def data @data end |
Class Method Details
.from(file) ⇒ Object
302 303 304 |
# File 'app/models/global_setting.rb', line 302 def self.from(file) parse(file) if File.exist?(file) end |
Instance Method Details
#keys ⇒ Object
328 329 330 |
# File 'app/models/global_setting.rb', line 328 def keys @data.keys end |
#lookup(key, default) ⇒ Object
323 324 325 326 |
# File 'app/models/global_setting.rb', line 323 def lookup(key, default) var = @data[key] resolve(var, var.nil? ? default : "") end |
#read ⇒ Object
311 312 313 314 315 316 317 318 319 320 321 |
# File 'app/models/global_setting.rb', line 311 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 |