Class: Place::Project
- Inherits:
-
Ohm::Model
- Object
- Ohm::Model
- Place::Project
- Defined in:
- lib/place/project.rb
Overview
Each project has a (name, url) from which (prefix, description) are derived
Class Attribute Summary collapse
-
.rules ⇒ Object
Returns the value of attribute rules.
Class Method Summary collapse
-
.collect_all(base_url) ⇒ Object
Collect all projects (url) under a given repository url.
-
.find_by_name(name) ⇒ Object
Find a project by a given name,
nil
if not exists. -
.find_by_prefix(prefix) ⇒ Object
Find a project by a given perfix,
nil
if not exists. -
.find_by_url(url) ⇒ Object
Find a project by a given url (ending with
/.polarion
),nil
if not exists.
Instance Method Summary collapse
-
#retrieve ⇒ Object
Retrieve a specific project (based on url only).
-
#roles ⇒ Object
Find all roles used in the project.
-
#users(with_role = nil) ⇒ Object
Find all users involved in the project, eventually with a given role.
Class Attribute Details
.rules ⇒ Object
Returns the value of attribute rules.
20 21 22 |
# File 'lib/place/project.rb', line 20 def rules @rules end |
Class Method Details
.collect_all(base_url) ⇒ Object
Collect all projects (url) under a given repository url
28 29 30 31 32 33 34 35 |
# File 'lib/place/project.rb', line 28 def self.collect_all(base_url) projects_path = base_url + '/**/.polarion' Dir.glob(projects_path).each do |filename| next if filename == base_url + '/.polarion' Project.create(:url => filename) Place.logger.info("created project with url #{filename}") end end |
.find_by_name(name) ⇒ Object
Find a project by a given name, nil
if not exists
79 80 81 82 |
# File 'lib/place/project.rb', line 79 def self.find_by_name(name) projects = self.find(:name => name) projects.nil? ? nil : projects[0] end |
.find_by_prefix(prefix) ⇒ Object
Find a project by a given perfix, nil
if not exists
85 86 87 88 |
# File 'lib/place/project.rb', line 85 def self.find_by_prefix(prefix) projects = self.find(:prefix => prefix) projects.nil? ? nil : projects[0] end |
.find_by_url(url) ⇒ Object
Find a project by a given url (ending with /.polarion
), nil
if not exists
73 74 75 76 |
# File 'lib/place/project.rb', line 73 def self.find_by_url(url) projects = self.find(:url => url) projects.nil? ? nil : projects[0] end |
Instance Method Details
#retrieve ⇒ Object
Retrieve a specific project (based on url only)
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/place/project.rb', line 38 def retrieve start_time = Time.now.to_i Dir.glob("#{url}/polarion-project.xml").each do |filename| content = IO.readlines(filename).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 end self.save Place.logger.info("saved project with name #{self.name}") retrieve_parent_roles TimePoint.collect_all(url) timepoints.all.each{|tp| tp.retrieve} if timepoints.size > 0 WorkItem.collect_all(url) workitems.all.each{|wi| wi.retrieve} if workitems.size > 0 retrieve_participations users.each do |u| # ugly way to prevent multiple (global) data retrieve :( u.retrieve if u.full_name.nil? u.retrieve_watches end self.save end |
#roles ⇒ Object
Find all roles used in the project
108 109 110 111 112 113 114 115 116 |
# File 'lib/place/project.rb', line 108 def roles tmp = {} participations.all.each do |pt| if pt.roles.size > 0 pt.roles.all.each{|r| tmp[r] = true} end end tmp.keys end |
#users(with_role = nil) ⇒ Object
Find all users involved in the project, eventually with a given role
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/place/project.rb', line 91 def users(with_role=nil) user_set = [] if participations.size > 0 participations.all.each do |pt| unless with_role.nil? role = with_role.to_s roles = pt.roles.size > 0 ? pt.roles.to_a : [] user_set << pt.user if roles.include?(role) else user_set << pt.user end end end user_set end |