From 5caa340a7a26fdecef9e0fc72e7a08d40e80597e Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Sat, 27 Jun 2015 19:26:24 +0200 Subject: [PATCH] Include activerecords + in-memory sqlite3. --- bin/git-timecost | 1 + bin/git-timecost-console.rb | 6 ++++++ lib/timecost.rb | 1 + lib/timecost/commit.rb | 15 ++++++++++++++- lib/timecost/db.rb | 11 +++++++++++ lib/timecost/range.rb | 32 +++++++++++++++++++++++++++++++- lib/timecost/range_list.rb | 1 + spec/range_spec.rb | 27 +++++++++++++++++++++++++++ timecost.gemspec | 1 + 9 files changed, 93 insertions(+), 2 deletions(-) create mode 100755 bin/git-timecost-console.rb create mode 100644 lib/timecost/db.rb diff --git a/bin/git-timecost b/bin/git-timecost index 5319863..44f6ec0 100755 --- a/bin/git-timecost +++ b/bin/git-timecost @@ -5,6 +5,7 @@ require 'pp' require 'date' require 'optparse' require 'yaml' +require 'active_record' require 'timecost' diff --git a/bin/git-timecost-console.rb b/bin/git-timecost-console.rb new file mode 100755 index 0000000..480f6c4 --- /dev/null +++ b/bin/git-timecost-console.rb @@ -0,0 +1,6 @@ + +#require 'pry' +require 'timecost' + +bindings.pry + diff --git a/lib/timecost.rb b/lib/timecost.rb index 3775e42..dce7e9d 100644 --- a/lib/timecost.rb +++ b/lib/timecost.rb @@ -1,4 +1,5 @@ +require 'timecost/db' require 'timecost/commit' require 'timecost/range' require 'timecost/author_list' diff --git a/lib/timecost/commit.rb b/lib/timecost/commit.rb index 27c2370..0d26d16 100644 --- a/lib/timecost/commit.rb +++ b/lib/timecost/commit.rb @@ -1,7 +1,20 @@ +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 + class Commit attr_accessor :author, :commit, :date, :note def initialize commit @commit = commit diff --git a/lib/timecost/db.rb b/lib/timecost/db.rb new file mode 100644 index 0000000..3d37e37 --- /dev/null +++ b/lib/timecost/db.rb @@ -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:" +) + diff --git a/lib/timecost/range.rb b/lib/timecost/range.rb index ed0f11e..7c11a2b 100644 --- a/lib/timecost/range.rb +++ b/lib/timecost/range.rb @@ -1,6 +1,36 @@ +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 Range + 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 GRANULARITY_DEFAULT = 0.5 diff --git a/lib/timecost/range_list.rb b/lib/timecost/range_list.rb index 9352da6..d4b51a1 100644 --- a/lib/timecost/range_list.rb +++ b/lib/timecost/range_list.rb @@ -1,5 +1,6 @@ module TimeCost + # Track = a list of range (for a given user) class RangeList def initialize @ranges = [] diff --git a/spec/range_spec.rb b/spec/range_spec.rb index 17fba79..33357e8 100644 --- a/spec/range_spec.rb +++ b/spec/range_spec.rb @@ -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 diff --git a/timecost.gemspec b/timecost.gemspec index eba291e..7119db1 100644 --- a/timecost.gemspec +++ b/timecost.gemspec @@ -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"