Class: Place::User

Inherits:
Ohm::Model
  • Object
show all
Defined in:
lib/place/user.rb

Overview

A User is an account under Polarion

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.rules ⇒ Object

Returns the value of attribute rules.



34
35
36
# File 'lib/place/user.rb', line 34

def rules
  @rules
end

Class Method Details

.collect_all(base_url) ⇒ Object

Collect all users (name, url) under a given repository url



24
25
26
27
28
29
30
31
32
# File 'lib/place/user.rb', line 24

def self.collect_all(base_url)
  Dir.glob(base_url + '/.polarion/user-management/users/**/user.xml').each do |filename|
 User.create(
:name => File.dirname(filename).split(/\//).last,
:url  => filename
 )
 Place.logger.info("collected user at #{filename}")
  end
end

.find_by_name(name) ⇒ Object

Find a user by the given name, returns nil if not present



73
74
75
76
# File 'lib/place/user.rb', line 73

def self.find_by_name(name)
  users = self.find(:name => name.to_s)
 users.nil? ? nil : users[0]
end

Instance Method Details

#retrieve ⇒ Object

Retrieve a specific user data (based on name and url only)



42
43
44
45
46
47
48
49
50
51
# File 'lib/place/user.rb', line 42

def retrieve
  content = IO.readlines(url).join('')
  doc = Nokogiri::XML(content)
  self.class.rules.each_pair do |k,v|
 tmp = doc.xpath(v)
 self.send("#{k}=", tmp[0].content)  unless tmp[0].nil?   
  end
  Place.logger.info("retrieved user at #{self.name}")
  self.save
end

#retrieve_watches ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/place/user.rb', line 53

def retrieve_watches
  content = IO.readlines(url).join('')
  doc = Nokogiri::XML(content)
  doc.xpath('//user/field[@id="watches"]/list//item').each do |wa|
 prj, wid = wa.text.split('$')
 if Project.all.map{|p| p.name}.include?(prj)
   wi = WorkItem.find_by_wid(wid)
unless wi.nil?
  wi.watches << User.find_by_name(name)
  wi.save
  self.watches << wi
  self.save
end
 end
  end
  Place.logger.info("retrieved watches for user #{self.name}")
  self
end