Class: Mystro::Provider
- Inherits:
-
Object
- Object
- Mystro::Provider
- Defined in:
- lib/mystro/provider.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, file) ⇒ Provider
constructor
A new instance of Provider.
- #to_hash ⇒ Object
Constructor Details
#initialize(name, file) ⇒ Provider
Returns a new instance of Provider.
29 30 31 32 33 34 |
# File 'lib/mystro/provider.rb', line 29 def initialize(name, file) yaml = File.exists?(file) ? YAML.load_file(file) : { } @name = name @file = file @data = Hashie::Mash.new(yaml) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
25 26 27 |
# File 'lib/mystro/provider.rb', line 25 def data @data end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
26 27 28 |
# File 'lib/mystro/provider.rb', line 26 def file @file end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
27 28 29 |
# File 'lib/mystro/provider.rb', line 27 def name @name end |
Class Method Details
.[](name) ⇒ Object
4 5 6 |
# File 'lib/mystro/provider.rb', line 4 def [](name) get(name) end |
.get(name) ⇒ Object
8 9 10 11 |
# File 'lib/mystro/provider.rb', line 8 def get(name) @list ||= {} @list[name] end |
.read ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/mystro/provider.rb', line 13 def read dir = Mystro.directory @list ||= { } Dir["#{dir}/providers/*.y*ml"].each do |file| name = file.gsub(/#{dir}\/providers\//, "").gsub(/\.(\w+?)$/, "") Mystro::Log.debug "loading provider '#{name}' '#{file}'" @list[name] = self.new(name, file) end end |
Instance Method Details
#to_hash ⇒ Object
36 37 38 |
# File 'lib/mystro/provider.rb', line 36 def to_hash @data.to_hash.symbolize_keys end |