Class: ProjectFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/airbrake/cli/project_factory.rb

Overview

Creates them from XML received.

Instance Method Summary collapse

Constructor Details

#initializeProjectFactory

Returns a new instance of ProjectFactory.



5
6
7
8
# File 'lib/airbrake/cli/project_factory.rb', line 5

def initialize
  @project = Project.new
  @projects = []
end

Instance Method Details

#check_projectObject



29
30
31
32
33
34
# File 'lib/airbrake/cli/project_factory.rb', line 29

def check_project
  if @project.valid?
    projects << @project
    @project = Project.new
  end
end

#create_projects_from_xml(xml) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/airbrake/cli/project_factory.rb', line 14

def create_projects_from_xml(xml)
  xml.split("\n").each do |line|
    /<name[^>]*>(.*)<\/name>/ =~ line
    name = $1
    project.name    = name.capitalize if name
    /<id[^>]*>(.*)<\/id>/ =~ line
    id = $1
    project.id      = id              if id
    /<api-key[^>]*>(.*)<\/api-key>/ =~ line
    api_key = $1
    project.api_key = api_key         if api_key
    check_project
  end
end

#projectObject



10
11
12
# File 'lib/airbrake/cli/project_factory.rb', line 10

def project
  @project
end

#projectsObject



36
37
38
# File 'lib/airbrake/cli/project_factory.rb', line 36

def projects
  @projects
end