redmine_rest 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac3d0294a5bcc3ee1ce3fc8ff6f9c2236379280d
4
- data.tar.gz: 26fa8199cbabbadcb4c78e109bf9662d2b082307
3
+ metadata.gz: 60f9d21ded72e8820f98bef43db42e9f07ee830f
4
+ data.tar.gz: 21c765be9944e3e68ece1cd98625e891d04dd5ef
5
5
  SHA512:
6
- metadata.gz: 28dcb1ab6e507c794361c0d0bc06d0469925c9e93230217353a457074d5edca73486dd4172db2ffa671d5ae459a33dc08bd64b934404201929f18ccf06ab3432
7
- data.tar.gz: 1e64494ef73ea5e3fe78a4442bf299320f5ce9235151f8f93982295f0a2dc5d5d6d3904c2078d6ad077ca31b3bf5c2514fd12c08747b74c8eb7cd8b95fe464b0
6
+ metadata.gz: c22d9098f4ead35819fdfbb8489b68c531b1fa9e3d78511c11b9d001c0513d27d82e4af2ec178e4e3907cad558117e75ca1320a6b33217ba0c3c9abb2fb4c41a
7
+ data.tar.gz: a2ce1f62f121fd1ed2256435a2bb3bccb04f185ecafc40c35a470869aa16cdd60617aa5be0580df50d2ef3031853e0d3336d94cdaeccd5e1ed7b27eee5db622e
@@ -5,7 +5,7 @@ module RedmineRest
5
5
  # Namespace for models + some self-methods
6
6
  #
7
7
  module Models
8
- LIST = [Issue, User, Project, IssueStatus, TimeEntry].freeze
8
+ LIST = [Issue, User, Project, IssueStatus, TimeEntry, Relation].freeze
9
9
 
10
10
  def self.configure_models(params)
11
11
  ModelConfigurator.new.configure_models(params)
@@ -3,6 +3,7 @@ require 'active_resource'
3
3
  require_relative 'user'
4
4
  require_relative 'project'
5
5
  require_relative 'version'
6
+ require_relative 'relation'
6
7
  require_relative 'collections/issue'
7
8
 
8
9
  module RedmineRest
@@ -18,6 +19,40 @@ module RedmineRest
18
19
  has_one :assigned_to, class_name: User
19
20
  has_one :project, class_name: Project
20
21
  has_one :version, class_name: Version
22
+ has_one :parent, class_name: Issue
23
+ has_many :children, class_name: Issue
24
+ has_many :watchers, class_name: User
25
+ has_many :relations, class_name: Relation
26
+
27
+ #
28
+ # Adds journals, relations, children and watchers to request.
29
+ #
30
+ # Be careful, even if issue has watchers, it won't be loaded,
31
+ # because REST API can load them only after v2.3.0 (see Redmine docs)
32
+ #
33
+ def self.find(what, options = {})
34
+ options[:params] = {} unless options[:params]
35
+ params = options[:params]
36
+
37
+ if params[:include]
38
+ params[:include] += ',journals,relations,children,watchers'
39
+ else # doubling is not bad
40
+ params[:include] = 'journals,relations,children,watchers'
41
+ end
42
+
43
+ super(what, options)
44
+ end
45
+
46
+ #
47
+ # Methods for necessery attributes.
48
+ #
49
+ # I guess it's equal to `.<attribute>?`
50
+ #
51
+ [:author, :assigned_to, :project, :version, :children, :watchers, :relations, :parent].each do |attr|
52
+ define_method(attr) do
53
+ attributes[attr]
54
+ end
55
+ end
21
56
  end
22
57
  end
23
58
  end
@@ -0,0 +1,49 @@
1
+ require 'active_resource'
2
+
3
+ module RedmineRest
4
+ module Models
5
+ #
6
+ # Model of issue relations
7
+ #
8
+ class Relation < ActiveResource::Base
9
+ TYPES = %w(relates duplicates duplicated blocks blocked precedes follows copied_to copied_from).freeze
10
+
11
+ self.format = :xml
12
+
13
+ validate :validate_relation_type,
14
+ :validate_issue_id,
15
+ :validate_issue_to_id
16
+
17
+ def self.set_prefix
18
+ self.prefix = '/issues/:issue_id'
19
+ end
20
+
21
+ set_prefix
22
+
23
+ def self.find(what, options = {})
24
+ if what == :all
25
+ super
26
+ else
27
+ self.prefix = '/'
28
+ result = super
29
+ set_prefix
30
+ result
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def validate_relation_type
37
+ errors.add(:relation_type, 'Wrong relation type') unless relation_type? && TYPES.include?(relation_type)
38
+ end
39
+
40
+ def validate_issue_id
41
+ errors.add(:issue_id, 'Issue ID required') unless issue_id?
42
+ end
43
+
44
+ def validate_issue_to_id
45
+ errors.add(:issue_to_id, 'Issue ID required') unless issue_to_id?
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,3 +1,3 @@
1
1
  module RedmineRest
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redmine_rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitriy Non
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-04 00:00:00.000000000 Z
11
+ date: 2016-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -102,6 +102,7 @@ files:
102
102
  - lib/redmine_rest/models/issue.rb
103
103
  - lib/redmine_rest/models/issue_status.rb
104
104
  - lib/redmine_rest/models/project.rb
105
+ - lib/redmine_rest/models/relation.rb
105
106
  - lib/redmine_rest/models/time_entry.rb
106
107
  - lib/redmine_rest/models/user.rb
107
108
  - lib/redmine_rest/models/version.rb