Class: Fanforce::Factory::Addon

Inherits:
Object
  • Object
show all
Defined in:
lib/fanforce/factory/addons.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir, plugin_type) ⇒ Addon

Returns a new instance of Addon.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fanforce/factory/addons.rb', line 13

def initialize(dir, plugin_type)
  raise "This is an invalid directory name for a factory addon: #{dir}" if dir !~ /^(.*)\/((app|plugin|widget)-([^\/]+))\/?$/

  @_id         = $4
  @type        = $3.to_sym
  @dir         = "#{$1}/#{$2}"
  @dir_root    = $1
  @dir_name    = $2
  @root_domain = case @type when :app then $FF_APP_DOMAIN when :plugin then $FF_PLUGIN_DOMAIN when :widget then $FF_WIDGET_DOMAIN end
  @plugin_type = (plugin_type.present?) ? plugin_type.to_sym : nil

  if @type == :plugin and @plugin_type.blank?
    raise "No config.ru was found in the home directory: #{dir}" if !File.exists?("#{dir}/config.ru")

    File.open("#{@dir}/config.ru", 'r') do |f|
      if f.read =~ /FanforcePlugin\.config.+config.type\s+=\W+(data_connector|data_processor|broadcaster|identifier|behavior)/m
        @plugin_type = $1.to_sym
      else
        raise 'Factory plugins specify their type in the config.ru file'
      end
    end
  end
end

Instance Attribute Details

#_idObject (readonly)

Returns the value of attribute _id.



2
3
4
# File 'lib/fanforce/factory/addons.rb', line 2

def _id
  @_id
end

#dirObject (readonly)

Returns the value of attribute dir.



2
3
4
# File 'lib/fanforce/factory/addons.rb', line 2

def dir
  @dir
end

#dir_nameObject (readonly)

Returns the value of attribute dir_name.



2
3
4
# File 'lib/fanforce/factory/addons.rb', line 2

def dir_name
  @dir_name
end

#dir_rootObject (readonly)

Returns the value of attribute dir_root.



2
3
4
# File 'lib/fanforce/factory/addons.rb', line 2

def dir_root
  @dir_root
end

#plugin_typeObject (readonly)

Returns the value of attribute plugin_type.



2
3
4
# File 'lib/fanforce/factory/addons.rb', line 2

def plugin_type
  @plugin_type
end

#root_domainObject (readonly)

Returns the value of attribute root_domain.



2
3
4
# File 'lib/fanforce/factory/addons.rb', line 2

def root_domain
  @root_domain
end

#typeObject (readonly)

Returns the value of attribute type.



2
3
4
# File 'lib/fanforce/factory/addons.rb', line 2

def type
  @type
end

Class Method Details

.load(dir, plugin_type = nil) ⇒ Object



9
10
11
# File 'lib/fanforce/factory/addons.rb', line 9

def self.load(dir, plugin_type=nil)
  self.new(dir, plugin_type)
end

.parse_dir_name(dir_name) ⇒ Object



4
5
6
7
# File 'lib/fanforce/factory/addons.rb', line 4

def self.parse_dir_name(dir_name)
  return if dir_name !~ /^((app|plugin|widget)-(.+))\/?$/
  {_id: $3, type: $2, dir_name: $1}
end

Instance Method Details

#create_files(*filenames) ⇒ Object Also known as: create_file



37
38
39
40
41
# File 'lib/fanforce/factory/addons.rb', line 37

def create_files(*filenames)
  filenames.each do |filename|
    Fanforce::Factory::Files.method(:"create_#{filename}").call(self)
  end
end

#end_printObject



70
71
72
# File 'lib/fanforce/factory/addons.rb', line 70

def end_print
  puts 'DONE'
end

#start_printObject



66
67
68
# File 'lib/fanforce/factory/addons.rb', line 66

def start_print
  print "- #{@dir_name}... "
end

#to_hashObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/fanforce/factory/addons.rb', line 51

def to_hash
  {
      _id: @_id,
      type: @type,
      dir_name: @dir_name,
      dir_root: @dir_root,
      dir: @dir,
      plugin_type: @plugin_type,
  }
end

#to_jsonObject



62
63
64
# File 'lib/fanforce/factory/addons.rb', line 62

def to_json
  to_hash.to_json
end

#update_files(*filenames) ⇒ Object Also known as: update_file



44
45
46
47
48
# File 'lib/fanforce/factory/addons.rb', line 44

def update_files(*filenames)
  filenames.each do |filename|
    Fanforce::Factory::Files.method(:"update_#{filename}").call(self)
  end
end