Sha256: 68b676fdfafd5c137cf509a85215921903099bfc76e85ce56f7dd164bd87c8e6

Contents?: true

Size: 1.6 KB

Versions: 2

Compression:

Stored size: 1.6 KB

Contents

require 'active_resource'

require_relative 'user'
require_relative 'project'
require_relative 'version'
require_relative 'relation'
require_relative 'collections/issue'

module RedmineRest
  module Models
    #
    # issue model
    #
    class Issue < ActiveResource::Base
      self.format = :xml
      self.collection_parser = Collections::Issue

      has_one :author, class_name: User
      has_one :assigned_to, class_name: User
      has_one :project, class_name: Project
      has_one :version, class_name: Version
      has_one :parent, class_name: Issue
      has_many :children, class_name: Issue
      has_many :watchers, class_name: User
      has_many :relations, class_name: Relation

      #
      # Adds journals, relations, children and watchers to request.
      #
      # Be careful, even if issue has watchers, it won't be loaded,
      # because REST API can load them only after v2.3.0 (see Redmine docs)
      #
      def self.find(what, options = {})
        options[:params] = {} unless options[:params]
        params = options[:params]

        if params[:include]
          params[:include] += ',journals,relations,children,watchers'
        else # doubling is not bad
          params[:include] = 'journals,relations,children,watchers'
        end

        super(what, options)
      end

      #
      # Methods for necessery attributes.
      #
      # I guess it's equal to `.<attribute>?`
      #
      [:author, :assigned_to, :project, :version, :children, :watchers, :relations, :parent].each do |attr|
        define_method(attr) do
          attributes[attr]
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
redmine_rest-0.4.0 lib/redmine_rest/models/issue.rb
redmine_rest-0.3.0 lib/redmine_rest/models/issue.rb