Class: ProjectFactory

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

Overview

Creates them from XML received.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProjectFactory

Returns a new instance of ProjectFactory.



7
8
9
10
# File 'lib/airbrake/cli/project_factory.rb', line 7

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

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



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

def project
  @project
end

#projectsObject (readonly)

Returns the value of attribute projects.



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

def projects
  @projects
end

Instance Method Details

#check_projectObject



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

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

#create_projects_from_xml(xml) ⇒ Object



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

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