Class: Fanforce::Factory::Addons

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Singleton
Defined in:
lib/fanforce/factory/addons.rb

Instance Method Summary collapse

Instance Method Details

#countObject



119
120
121
# File 'lib/fanforce/factory/addons.rb', line 119

def count
  dir_names.size
end

#dir_namesObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/fanforce/factory/addons.rb', line 81

def dir_names
  @dirs ||= Dir.chdir($HomeDir) do Dir['*/'].inject([]) do |dirs, d|
    d = d.gsub('/', '')
    next dirs if d !~ /^((app|plugin|widget)-(.+))\/?$/
    next dirs << d if $Filter.blank?
    next dirs << d if $Filter[:dir_name].present? and $Filter[:dir_name] == $1
    if $Filter[:type] and $Filter[:type] == $2.to_sym and !$Filter[:plugin_type]
      next dirs << d
    elsif $Filter[:type] and $Filter[:type] == $2.to_sym and $Filter[:plugin_type]
      next dirs if !File.exists?("#{$HomeDir}/#{$1}/config.ru")
      File.open("#{$HomeDir}/#{$1}/config.ru", 'r') do |f|
        if f.read =~ /FanforcePlugin\.config.+config.type\s+=\W+(data_connector|data_processor|broadcaster|identifier|behavior)/m
          next dirs << d if $Filter[:plugin_type] == $1.to_sym
        else
          raise "#{d} is not correctly specifying its type in the config.ru file"
        end
      end
    end
    dirs
  end end
end

#dirsObject



103
104
105
106
107
# File 'lib/fanforce/factory/addons.rb', line 103

def dirs
  dir_names.inject([]) do |result, d|
    result << "#{$HomeDir}/#{d}"
  end
end

#each(&block) ⇒ Object



109
110
111
112
113
114
115
116
117
# File 'lib/fanforce/factory/addons.rb', line 109

def each(&block)
  cur_count = 0
  total = dir_names.size
  dir_names.each do |d|
    cur_count += 1
    addon = Fanforce::Factory::Addon.load("#{$HomeDir}/#{d}")
    Dir.chdir(addon.dir) { block.call(addon, cur_count, total) }
  end
end