redmine_rest 0.5.2 → 0.6.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: 47cace2287f24338aefe30d5a70f510d3ac4720b
4
- data.tar.gz: bc42629a5bdba3e5a222ce5dade6b8d29782bb9f
3
+ metadata.gz: c650caea3e5f25a8dd23a954d48a9c12e0837c4d
4
+ data.tar.gz: c7e03f5bb55417b07afca18e2cb45dce898b17b6
5
5
  SHA512:
6
- metadata.gz: b79646ee24677762a75bf20314b98e82406f7652b84b2b3b9c6fec2854eadaf88c9e523c12922c1ca436bde2670bb52f3c429c85c1dd56c86bbaa2e682ab2d2a
7
- data.tar.gz: 2e5799a39d574563b4e2a5732e53e14e61a5eb8a98ad1f869c3b7a017fbc7669ebfbd1b3cbe6f0e1a8128bf838d35f32d0488565071633700c23ae5db4ecfda8
6
+ metadata.gz: 9a67c5f368edab616da3de28b6f0a0bdce2fce1d0a66f253f856d43993c75b654c7f36f7b1bfa05a29e504a8a2868fb3f992ee976102e0d16b9fb49eb01c0e2f
7
+ data.tar.gz: 7f5745029e7de897d4bb84864563d127e254edd97f64583a7689f06ccefe22676acddd27b3051ab306ff349398390eff304532aa55054e4a8f38a5380a5290f9
@@ -0,0 +1,18 @@
1
+ require 'active_resource'
2
+ require 'unicode'
3
+
4
+ module RedmineRest
5
+ module Models
6
+ module Collections
7
+ #
8
+ # Base class for most custom collections
9
+ #
10
+ class Base < ActiveResource::Collection
11
+ def filter_by_name_substring(str)
12
+ str = Unicode.downcase(str)
13
+ self.class.new @elements.find_all { |e| Unicode.downcase(e.name).include? str }
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ require 'active_resource'
2
+
3
+ require_relative 'collections/base'
4
+
5
+ module RedmineRest
6
+ module Models
7
+ #
8
+ # Group model. Right now it cant work with user lists (add, delete and so on)
9
+ #
10
+ class Group < ActiveResource::Base
11
+ self.format = :xml
12
+ self.collection_parser = Collections::Base
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ require 'active_resource'
2
+
3
+ require_relative 'collections/base'
4
+
5
+ module RedmineRest
6
+ module Models
7
+ #
8
+ # issue priority model
9
+ #
10
+ class IssuePriority < ActiveResource::Base
11
+ self.format = :xml
12
+ self.collection_parser = Collections::Base
13
+ self.prefix = '/enumerations/'
14
+
15
+ def self.find(*args)
16
+ fail('Issue priorities can be loaded as :all only') unless args.size == 1 && args.first == :all
17
+ super
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,6 +1,6 @@
1
1
  require 'active_resource'
2
2
 
3
- require_relative 'collections/issue_status'
3
+ require_relative 'collections/base'
4
4
 
5
5
  module RedmineRest
6
6
  module Models
@@ -9,13 +9,11 @@ module RedmineRest
9
9
  #
10
10
  class IssueStatus < ActiveResource::Base
11
11
  self.format = :xml
12
- self.collection_parser = Collections::IssueStatus
12
+ self.collection_parser = Collections::Base
13
13
 
14
14
  def self.find(*args)
15
15
  fail('Issue statuses can be loaded as :all only') unless args.size == 1 && args.first == :all
16
-
17
- return @statuses if @statuses
18
- @statuses = super
16
+ super
19
17
  end
20
18
  end
21
19
  end
@@ -0,0 +1,29 @@
1
+ require 'active_resource'
2
+
3
+ require_relative 'collections/base'
4
+ require_relative 'user'
5
+ require_relative 'group'
6
+
7
+ module RedmineRest
8
+ module Models
9
+ #
10
+ # Membership model
11
+ #
12
+ class Membership < ActiveResource::Base
13
+ self.format = :xml
14
+ self.collection_parser = Collections::Base
15
+ self.prefix = '/projects/:project_id/'
16
+
17
+ has_one :user, class_name: User
18
+ has_one :group, class_name: Group
19
+
20
+ #
21
+ # Overrides parent method.
22
+ # When we want to fetch one membership, we need not to use prefix
23
+ #
24
+ def self.element_path(id, _prefix_options = {}, query_options = nil)
25
+ "/memberships/#{URI.parser.escape id.to_s}#{format_extension}#{query_string(query_options)}"
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,6 +1,9 @@
1
1
  require 'active_resource'
2
2
 
3
- require_relative 'collections/project'
3
+ require_relative 'tracker'
4
+ require_relative 'collections/base'
5
+ require_relative 'version'
6
+ require_relative 'membership'
4
7
 
5
8
  module RedmineRest
6
9
  module Models
@@ -9,7 +12,42 @@ module RedmineRest
9
12
  #
10
13
  class Project < ActiveResource::Base
11
14
  self.format = :xml
12
- self.collection_parser = Collections::Project
15
+ self.collection_parser = Collections::Base
16
+
17
+ has_many :trackers, class_name: Tracker
18
+
19
+ #
20
+ # Adds trackers to request.
21
+ #
22
+ def self.find(scope, options = {})
23
+ options[:params] = {} unless options[:params]
24
+ params = options[:params]
25
+
26
+ if params[:include]
27
+ params[:include] += ',trackers'
28
+ else # doubling is not bad
29
+ params[:include] = 'trackers'
30
+ end
31
+
32
+ super(scope, options)
33
+ end
34
+
35
+ def versions
36
+ Version.all params: { project_id: id }
37
+ end
38
+
39
+ def memberships
40
+ Membership.all params: { project_id: id }
41
+ end
42
+
43
+ def members(options = {})
44
+ users = memberships
45
+ .map { |m| m.user? ? m.user : m.group.reload.users }
46
+ .flatten
47
+ users.map(&:reload) if options[:reload]
48
+
49
+ Collections::Base.new(users)
50
+ end
13
51
  end
14
52
  end
15
53
  end
@@ -9,26 +9,18 @@ module RedmineRest
9
9
  TYPES = %w(relates duplicates duplicated blocks blocked precedes follows copied_to copied_from).freeze
10
10
 
11
11
  self.format = :xml
12
+ self.prefix = '/issues/:issue_id/'
12
13
 
13
14
  validate :validate_relation_type,
14
15
  :validate_issue_id,
15
16
  :validate_issue_to_id
16
17
 
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
18
+ #
19
+ # Overrides parent method.
20
+ # When we want to fetch one relation, we need not to use prefix
21
+ #
22
+ def self.element_path(id, _prefix_options = {}, query_options = nil)
23
+ "/relations/#{URI.parser.escape id.to_s}#{format_extension}#{query_string(query_options)}"
32
24
  end
33
25
 
34
26
  private
@@ -0,0 +1,21 @@
1
+ require 'active_resource'
2
+
3
+ require_relative 'collections/base'
4
+
5
+ module RedmineRest
6
+ module Models
7
+ #
8
+ # time entry activity model
9
+ #
10
+ class TimeEntryActivity < ActiveResource::Base
11
+ self.format = :xml
12
+ self.collection_parser = Collections::Base
13
+ self.prefix = '/enumerations/'
14
+
15
+ def self.find(*args)
16
+ fail('Issue priorities can be loaded as :all only') unless args.size == 1 && args.first == :all
17
+ super
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,6 +1,6 @@
1
1
  require 'active_resource'
2
2
 
3
- require_relative 'collections/tracker'
3
+ require_relative 'collections/base'
4
4
 
5
5
  module RedmineRest
6
6
  module Models
@@ -9,13 +9,11 @@ module RedmineRest
9
9
  #
10
10
  class Tracker < ActiveResource::Base
11
11
  self.format = :xml
12
- self.collection_parser = Collections::Tracker
12
+ self.collection_parser = Collections::Base
13
13
 
14
14
  def self.find(*args)
15
15
  fail('Trackers can be loaded as :all only') unless args.size == 1 && args.first == :all
16
-
17
- return @trackers if @trackers
18
- @trackers = super
16
+ super
19
17
  end
20
18
  end
21
19
  end
@@ -1,6 +1,6 @@
1
1
  require 'active_resource'
2
2
 
3
- require_relative 'collections/version'
3
+ require_relative 'collections/base'
4
4
 
5
5
  module RedmineRest
6
6
  module Models
@@ -9,7 +9,16 @@ module RedmineRest
9
9
  #
10
10
  class Version < ActiveResource::Base
11
11
  self.format = :xml
12
- self.collection_parser = Collections::Version
12
+ self.collection_parser = Collections::Base
13
+ self.prefix = '/projects/:project_id/'
14
+
15
+ #
16
+ # Overrides parent method.
17
+ # When we want to fetch one version, we need not to use prefix
18
+ #
19
+ def self.element_path(id, _prefix_options = {}, query_options = nil)
20
+ "/versions/#{URI.parser.escape id.to_s}#{format_extension}#{query_string(query_options)}"
21
+ end
13
22
  end
14
23
  end
15
24
  end
@@ -1,11 +1,29 @@
1
+ require 'active_resource'
2
+
1
3
  Dir[File.expand_path('../models/*.rb', __FILE__)].each { |f| require f }
2
4
 
5
+ module ActiveResource
6
+ #
7
+ # some monkey-patching
8
+ #
9
+ class Base
10
+ def self.find_by_id(id)
11
+ find(id)
12
+ rescue ActiveResource::ResourceNotFound
13
+ nil
14
+ end
15
+ end
16
+ end
17
+
3
18
  module RedmineRest
4
19
  #
5
20
  # Namespace for models + some self-methods
6
21
  #
7
22
  module Models
8
- LIST = [Issue, User, Project, IssueStatus, TimeEntry, Tracker, Relation].freeze
23
+ LIST = constants
24
+ .map { |symbol| const_get(symbol) }
25
+ .find_all { |const| const.is_a?(Class) && const < ActiveResource::Base }
26
+ .freeze
9
27
 
10
28
  def self.configure_models(params)
11
29
  ModelConfigurator.new.configure_models(params)
@@ -1,3 +1,3 @@
1
1
  module RedmineRest
2
- VERSION = '0.5.2'.freeze
2
+ VERSION = '0.6.0'.freeze
3
3
  end
data/lib/redmine_rest.rb CHANGED
@@ -1,3 +1,2 @@
1
1
  require 'redmine_rest/version'
2
- Dir[File.expand_path('../redmine_rest/helpers/**/*.rb', __FILE__)].each { |f| require f }
3
2
  require 'redmine_rest/models'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redmine_rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitriy Non
@@ -111,18 +111,18 @@ files:
111
111
  - bin/console
112
112
  - bin/setup
113
113
  - lib/redmine_rest.rb
114
- - lib/redmine_rest/helpers/collection.rb
115
114
  - lib/redmine_rest/models.rb
115
+ - lib/redmine_rest/models/collections/base.rb
116
116
  - lib/redmine_rest/models/collections/issue.rb
117
- - lib/redmine_rest/models/collections/issue_status.rb
118
- - lib/redmine_rest/models/collections/project.rb
119
- - lib/redmine_rest/models/collections/tracker.rb
120
- - lib/redmine_rest/models/collections/version.rb
117
+ - lib/redmine_rest/models/group.rb
121
118
  - lib/redmine_rest/models/issue.rb
119
+ - lib/redmine_rest/models/issue_priority.rb
122
120
  - lib/redmine_rest/models/issue_status.rb
121
+ - lib/redmine_rest/models/membership.rb
123
122
  - lib/redmine_rest/models/project.rb
124
123
  - lib/redmine_rest/models/relation.rb
125
124
  - lib/redmine_rest/models/time_entry.rb
125
+ - lib/redmine_rest/models/time_entry_activity.rb
126
126
  - lib/redmine_rest/models/tracker.rb
127
127
  - lib/redmine_rest/models/user.rb
128
128
  - lib/redmine_rest/models/version.rb
@@ -1,16 +0,0 @@
1
- require 'active_resource'
2
- require 'unicode'
3
-
4
- module RedmineRest
5
- module Helpers
6
- #
7
- # some methods for ActiveResource collections
8
- #
9
- module Collection
10
- def filter_by_name_substring(str)
11
- str = Unicode.downcase(str)
12
- self.class.new @elements.find_all { |e| Unicode.downcase(e.name).include? str }
13
- end
14
- end
15
- end
16
- end
@@ -1,14 +0,0 @@
1
- require 'active_resource'
2
-
3
- module RedmineRest
4
- module Models
5
- module Collections
6
- #
7
- # Methods for status collections
8
- #
9
- class IssueStatus < ActiveResource::Collection
10
- include Helpers::Collection
11
- end
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- require 'active_resource'
2
-
3
- module RedmineRest
4
- module Models
5
- module Collections
6
- #
7
- # Methods for project collections
8
- #
9
- class Project < ActiveResource::Collection
10
- include Helpers::Collection
11
- end
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- require 'active_resource'
2
-
3
- module RedmineRest
4
- module Models
5
- module Collections
6
- #
7
- # Methods for tracker collections
8
- #
9
- class Tracker < ActiveResource::Collection
10
- include Helpers::Collection
11
- end
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- require 'active_resource'
2
-
3
- module RedmineRest
4
- module Models
5
- module Collections
6
- #
7
- # Methods for version collections
8
- #
9
- class Version < ActiveResource::Collection
10
- include Helpers::Collection
11
- end
12
- end
13
- end
14
- end