Skip to content

Commit

Permalink
Merge pull request #2634 from opf/feature/remove_unneccessary_checks
Browse files Browse the repository at this point in the history
[API] Remove unnecessary nil checks for embedded resources
  • Loading branch information
myabc committed Feb 27, 2015
2 parents 5f17041 + 3f910e8 commit 231f01e
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions lib/api/v3/work_packages/work_package_representer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,24 +257,20 @@ class WorkPackageRepresenter < ::API::Decorators::Single
property :author,
embedded: true,
class: ::User,
decorator: ::API::V3::Users::UserRepresenter,
if: -> (*) { !author.nil? }
decorator: ::API::V3::Users::UserRepresenter
property :responsible,
embedded: true,
class: ::User,
decorator: ::API::V3::Users::UserRepresenter,
if: -> (*) { !responsible.nil? }
decorator: ::API::V3::Users::UserRepresenter
property :assigned_to,
as: :assignee,
embedded: true,
class: ::User,
decorator: ::API::V3::Users::UserRepresenter,
if: -> (*) { !assigned_to.nil? }
decorator: ::API::V3::Users::UserRepresenter
property :category,
embedded: true,
class: ::Category,
decorator: ::API::V3::Categories::CategoryRepresenter,
if: -> (*) { !category.nil? }
decorator: ::API::V3::Categories::CategoryRepresenter
property :priority,
embedded: true,
class: ::IssuePriority,
Expand All @@ -284,8 +280,7 @@ class WorkPackageRepresenter < ::API::Decorators::Single

property :version,
embedded: true,
exec_context: :decorator,
if: ->(*) { represented.fixed_version.present? }
exec_context: :decorator
property :project,
embedded: true,
class: ::Project,
Expand Down Expand Up @@ -335,7 +330,9 @@ def relations
end

def version
Versions::VersionRepresenter.new(represented.fixed_version, current_user: current_user)
if represented.fixed_version.present?
Versions::VersionRepresenter.new(represented.fixed_version, current_user: current_user)
end
end

def custom_properties
Expand Down

0 comments on commit 231f01e

Please sign in to comment.