Class: BacklogJp::Project

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/backlog_jp/project.rb

Defined Under Namespace

Modules: Common Classes: Component, Issue, IssueType, Version

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

#==, #changed?, #changed_attributes, #eql?, included, #save

Constructor Details

#initialize(id, url, created_on, updated_on, name, key, use_parent_child_issue, text_formatting_rule, archived, use_chart) ⇒ Project

Returns a new instance of Project.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/backlog_jp/project.rb', line 7

def initialize id, url, created_on, updated_on, name, key, use_parent_child_issue, text_formatting_rule, archived, use_chart
  @id                     = id
  @url                    = url
  @created_on             = DateTime.parse created_on if created_on
  @updated_on             = DateTime.parse updated_on if updated_on
  @name                   = name
  @key                    = key
  @use_parent_child_issue = use_parent_child_issue
  @text_formatting_rule   = text_formatting_rule
  @archived               = archived
  @use_chart              = use_chart
end

Class Method Details

.[](arg) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/backlog_jp/project.rb', line 60

def [] arg
  case arg
  when Integer        then find_by  id: arg
  when String, Symbol then find_by key: arg.to_s
  else fail ArgumentError, "Give a Integer (for id), String or Symbol (for key)."
  end
end

.allObject

Returns all projects as a array.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/backlog_jp/project.rb', line 22

def all
  array_response = begin
    BacklogJp.client.admin_get_projects
  rescue
    BacklogJp.client.get_projects
  end

  array_response.map do |project|
    new_from_response project
  end
end

.create(attributes = {}) ⇒ Object



68
69
70
# File 'lib/backlog_jp/project.rb', line 68

def create attributes = {}
  cud_seed :admin_add_project, %i[key name], attributes
end

.delete(attributes = {}) ⇒ Object



76
77
78
79
# File 'lib/backlog_jp/project.rb', line 76

def delete attributes = {}
  require_attribute attributes, :id
  new_from_response BacklogJp.client.admin_delete_project attributes[:id]
end

.distinct(*attributes) ⇒ Object

Returns a array of specified attribute from all projects.



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/backlog_jp/project.rb', line 35

def distinct *attributes
  fail ArgumentError, "Specify at least one attribute." if attributes.empty?

  all.map do |item|
    if attributes.size == 1
      item.send attributes.first
    else
      attributes.map do |attribute|
        item.send attribute
      end
    end
  end
end

.find_by(attributes = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/backlog_jp/project.rb', line 49

def find_by attributes = {}
  new_from_response BacklogJp.client.get_project case attributes.keys
  when ->(k){k.include? :id}
    attributes[:id]
  when ->(k){k.include? :key}
    attributes[:key].to_s
  else
    fail ArgumentError, "Give a hash with :id (Integer) or :key (Symbol or String) as a key."
  end
end

.update(attributes = {}) ⇒ Object



72
73
74
# File 'lib/backlog_jp/project.rb', line 72

def update attributes = {}
  cud_seed :admin_update_project, %i[id], attributes
end

Instance Method Details

#add_component(attributes) ⇒ Object Also known as: add_category, create_component, create_category



91
92
93
94
# File 'lib/backlog_jp/project.rb', line 91

def add_component attributes
  attributes[:project_id] = id
  self.class::Component.create attributes
end

#add_issue_type(attributes) ⇒ Object Also known as: create_issue_type



119
120
121
122
# File 'lib/backlog_jp/project.rb', line 119

def add_issue_type attributes
  attributes[:project_id] = id
  self.class::IssueType.create attributes
end

#add_version(attributes) ⇒ Object Also known as: add_milestone, create_version, create_milestone



106
107
108
109
# File 'lib/backlog_jp/project.rb', line 106

def add_version attributes
  attributes[:project_id] = id
  self.class::Version.create attributes
end

#componentsObject Also known as: categories



85
86
87
# File 'lib/backlog_jp/project.rb', line 85

def components
  self.class::Component.find_by project_id: id
end

#issue_typesObject



115
116
117
# File 'lib/backlog_jp/project.rb', line 115

def issue_types
  self.class::IssueType.find_by project_id: id
end

#issues(attributes = {}) ⇒ Object



126
127
128
129
# File 'lib/backlog_jp/project.rb', line 126

def issues attributes = {}
  attributes.merge project_id: id
  self.class::Issue.find_by attributes
end

#versionsObject Also known as: milestones



100
101
102
# File 'lib/backlog_jp/project.rb', line 100

def versions
  self.class::Version.find_by project_id: id
end