Refactor: replace "render :json = graph.to_json" to view template(show.json.erb).

Because model shouldn't know about view logic.
This commit is contained in:
Sato Hiroyuki 2013-03-06 20:31:28 +09:00
parent 9dc46eee8e
commit 2f7f46b256
5 changed files with 39 additions and 38 deletions

View file

@ -4,7 +4,7 @@ module Graph
class Commit
include ActionView::Helpers::TagHelper
attr_accessor :time, :spaces, :refs, :parent_spaces, :icon
attr_accessor :time, :spaces, :refs, :parent_spaces
def initialize(commit)
@_commit = commit
@ -17,26 +17,6 @@ module Graph
@_commit.send(m, *args, &block)
end
def to_graph_hash
h = {}
h[:parents] = self.parents.collect do |p|
[p.id,0,0]
end
h[:author] = {
name: author.name,
email: author.email,
icon: icon
}
h[:time] = time
h[:space] = spaces.first
h[:parent_spaces] = parent_spaces
h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil?
h[:id] = sha
h[:date] = date
h[:message] = message
h
end
def add_refs(ref_cache, repo)
if ref_cache.empty?
repo.refs.each do |ref|

View file

@ -19,13 +19,6 @@ module Graph
@days = index_commits
end
def to_json(*args)
{
days: @days.compact.map { |d| [d.day, d.strftime("%b")] },
commits: @commits.map(&:to_graph_hash)
}.to_json(*args)
end
protected
# Get commits from repository