v3: last_build can be nil, active should always be a boolean

This commit is contained in:
Konstantin Haase 2015-01-27 17:03:36 +01:00
parent 737a31ad23
commit 592320ac4c

View File

@ -1,10 +1,10 @@
module Travis::API::V3
module Renderer::Repository
DIRECT_ATTRIBUTES = %i[id name slug description github_language active private]
DIRECT_ATTRIBUTES = %i[id name slug description github_language private]
extend self
def render(repository)
{ :@type => 'repository'.freeze, **direct_attributes(repository), **nested_resources(repository) }
{ :@type => 'repository'.freeze, active: !!repository.active, **direct_attributes(repository), **nested_resources(repository) }
end
def direct_attributes(repository)
@ -18,15 +18,20 @@ module Travis::API::V3
:id => repository.owner_id,
:login => repository.owner_name
},
last_build: {
:@type => 'build'.freeze,
:id => repository.last_build_id,
:number => repository.last_build_number,
:state => repository.last_build_state.to_s,
:duration => repository.last_build_duration,
:started_at => Renderer.format_date(repository.last_build_started_at),
:finished_at => Renderer.format_date(repository.last_build_finished_at),
}
last_build: last_build(repository)
}
end
def last_build(repository)
return nil unless repository.last_build_id
{
:@type => 'build'.freeze,
:id => repository.last_build_id,
:number => repository.last_build_number,
:state => repository.last_build_state.to_s,
:duration => repository.last_build_duration,
:started_at => Renderer.format_date(repository.last_build_started_at),
:finished_at => Renderer.format_date(repository.last_build_finished_at),
}
end
end