Class: Mystro::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/mystro/provider.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



25
26
27
# File 'lib/mystro/provider.rb', line 25

def data
  @data
end

#fileObject (readonly)

Returns the value of attribute file.



26
27
28
# File 'lib/mystro/provider.rb', line 26

def file
  @file
end

#nameObject (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

.readObject



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_hashObject



36
37
38
# File 'lib/mystro/provider.rb', line 36

def to_hash
  @data.to_hash.symbolize_keys
end