Include activerecords + in-memory sqlite3.

This commit is contained in:
Glenn Y. Rolland 2015-06-27 19:26:24 +02:00
parent c2524fc675
commit 5caa340a7a
9 changed files with 93 additions and 2 deletions

View file

@ -5,6 +5,7 @@ require 'pp'
require 'date'
require 'optparse'
require 'yaml'
require 'active_record'
require 'timecost'

6
bin/git-timecost-console.rb Executable file
View file

@ -0,0 +1,6 @@
#require 'pry'
require 'timecost'
bindings.pry

View file

@ -1,4 +1,5 @@
require 'timecost/db'
require 'timecost/commit'
require 'timecost/range'
require 'timecost/author_list'

View file

@ -1,5 +1,18 @@
ActiveRecord::Schema.define do
create_table :commits_v2 do |table|
table.column :commit, :string # ref to object
table.column :note, :string
table.column :author, :author
table.column :date, :date
table.column :range_id, :integer
end
end
module TimeCost
class CommitV2 < ActiveRecord::Base
belongs_to :ranges_v2
end
class Commit
attr_accessor :author, :commit, :date, :note

11
lib/timecost/db.rb Normal file
View file

@ -0,0 +1,11 @@
require 'active_record'
ActiveRecord::Base.logger = Logger.new(STDERR)
#ActiveRecord::Base.colorize_logging = false
ActiveRecord::Base.establish_connection(
adapter: "sqlite3",
database: ":memory:"
)

View file

@ -1,5 +1,35 @@
ActiveRecord::Schema.define do
create_table :ranges_v2 do |table|
table.column :granularity, :float
table.column :author, :string
table.column :time_start, :date
table.column :time_stop, :date
end
end
module TimeCost
class RangeV2 < ActiveRecord::Base
has_many :commits_v2
GRANULARITY_DEFAULT = 0.5
def to_s show_authors = true
val = "(%s)\t%s - %s\n" % [diff, fixed_start, @time_stop]
if show_authors then
val += "\tby %s\n" % @commits.first.author
end
@commits.each do |commit|
lines = []
lines.concat commit.note.split(/\n/)
r = lines.map{ |s| "\t %s" % s }.join "\n"
r[1] = '*'
val += r + "\n"
end
return val
end
end
class Range
attr_accessor :time_start, :time_stop, :commits, :author

View file

@ -1,5 +1,6 @@
module TimeCost
# Track = a list of range (for a given user)
class RangeList
def initialize
@ranges = []

View file

@ -21,11 +21,38 @@ describe TimeCost::Range do
end
end
# Ref ----[----]-----
# overlapping :
# A -[----]--------
# B -------[----]--
# C -[----------]--
# D ------[]-------
# non-overlapping :
# E -[]------------
# F -----------[]--
describe '.overlap?' do
it "must respond to .overlap?" do
end
it "must return false when ranges are not overlapping" do
# rangeRef = RangeV2.new
# rangeA = RangeV2.new ...
# FIXME: test rangeRef + rangeA
#
# rangeB = RangeV2.new
# FIXME: test rangeRef + rangeB
#
# rangeC = RangeV2.new
# FIXME: test rangeRef + rangeC
#
# rangeD = RangeV2.new
# FIXME: test rangeRef + rangeD
#
# rangeE = RangeV2.new
# FIXME: test rangeRef + rangeE
#
# rangeF = RangeV2.new
# FIXME: test rangeRef + rangeF
end
it "must return true when ranges are overlapping" do

View file

@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]
spec.add_runtime_dependency "activerecord", "~> 4.0"
spec.add_runtime_dependency "sqlite3"
spec.add_development_dependency "bundler", "~> 1.6"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "minitest", "~> 4.7.5"