lense 0.1.42 → 0.1.43

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/lense.rb +46 -6
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9e978b74147cbbcf5d6c8c6019c397b82a7b8a6
4
- data.tar.gz: 40b26a3185024a18098e5d689d5da6c2b956c58d
3
+ metadata.gz: f42192d4855d217e54d3dfc54dc0de59450e7b42
4
+ data.tar.gz: 410af56c080571b1c261b431239121cb90822bc6
5
5
  SHA512:
6
- metadata.gz: 7ea2f716dc8fa01f8864d8a7a270ca12e33b83f3a216a01392477bacb9c19136e34390f989efefa2d0a66a948a34646e923a2b03d9e672689c062ce3eb22e9f2
7
- data.tar.gz: 996ba02669125f8f1a43c2eff232b1b013d7e3021d47751188e88d272dc2191f0063a12f1d0541c44f9e0040d486dd9f572a005ed1d629a179c04bcd47ee221e
6
+ metadata.gz: ea1a22f30d4addf2799d89b2beee9ff20da740814fb2391e7f5f70f8a911d41f2011c438f049207c4097bb3b7a62814bd0972cd5ff521d2746c9dcecc8b9fb07
7
+ data.tar.gz: 30299fc6253c6effab8171832d0cdfb4fdf7aa4274519c983f68707f5855721e1e9b7fa0f56bc3ee9ca00015b47be3ad76c4778c6a55b585d975c658e7ed4c0d
data/lib/lense.rb CHANGED
@@ -6,7 +6,7 @@ require 'sqlite3'
6
6
  class LENSE
7
7
  attr_reader :config, :current_course, :lense_file_hash
8
8
 
9
- VERSION = '0.1.42'
9
+ VERSION = '0.1.43'
10
10
  LENSE_DIR = File.join(ENV['HOME'],'.lense')
11
11
  COURSES_DIR = File.join(LENSE_DIR,'courses')
12
12
  CURRENT_COURSE_FILE = File.join(LENSE_DIR,'current_course')
@@ -28,7 +28,7 @@ class LENSE
28
28
 
29
29
  @current_course = File.read(CURRENT_COURSE_FILE).strip()
30
30
  @current_course = '> NOT SET <' if @current_course.empty?
31
- @lense_file_hash = Digest::SHA256.hexdigest(File.read(LENSE_FILE)) if File.file?(LENSE_FILE)
31
+ @lense_file_hash = hash_file(LENSE_FILE) if File.file?(LENSE_FILE)
32
32
  @DB = SQLite3::Database.new File.join(LOCAL_LENSE_DIR,'db') if File.file? File.join(LOCAL_LENSE_DIR,'db')
33
33
  end
34
34
 
@@ -153,6 +153,39 @@ class LENSE
153
153
  def commit(msg)
154
154
  # check that we have items in staging
155
155
  rows = @DB.execute 'select path from staging;'
156
+ rows.map! do |r|
157
+ path = r[0]
158
+ {
159
+ path: path,
160
+ hash: hash_file(path)
161
+ }
162
+ end
163
+
164
+ files = rows.select do |file|
165
+ dependency = get_dependency(file[:path])
166
+ dependency.nil? || dependency.file_hash != file[:hash]
167
+ end
168
+
169
+ combined_hash = files.map {|f| f[:hash]}.join ''
170
+ commit_hash = Digest::SHA256.hexdigest "#{DateTime.now.to_s}#{combined_hash}"
171
+ @DB.execute 'insert into commits (dependency_id,hash,created_at) values (?,?,?);',[dependency_id,commit_hash,DateTime.now.to_s]
172
+ commit_id = @DB.last_insert_row_id
173
+
174
+ files.each do |file|
175
+ @DB.transaction
176
+ dependency = get_dependency(file[:path])
177
+ if dependency.nil?
178
+ @DB.execute 'insert into dependencies (path,added_at) values (?,?);',[file[:path],DateTime.now.to_s]
179
+ dependency_id = @DB.last_insert_row_id
180
+ else
181
+ dependency_id = dependency.id
182
+ end
183
+ @DB.execute 'insert into revisions (commit_id,dependency_id,hash,created_at) values (?,?,?,?);',[commit_id,dependency_id,file[:hash],DateTime.now.to_s]
184
+ @DB.commit
185
+ end
186
+ @DB.transaction
187
+ @DB.execute 'truncate staging;'
188
+ @DB.commit
156
189
  # add new files to dependancies
157
190
  # create a hash for the commit and add to commits
158
191
  # for all dependancies add current hashes to revisions
@@ -165,7 +198,7 @@ class LENSE
165
198
  if dependency.nil?
166
199
  should_stage = true
167
200
  else
168
- current_hash = Digest::SHA256.hexdigest(File.read(file))
201
+ current_hash = hash_file(file)
169
202
  # is it modified?
170
203
  if dependency.file_hash == current_hash
171
204
  say "Not Staging because we've seen this file"
@@ -177,9 +210,13 @@ class LENSE
177
210
  end
178
211
 
179
212
  if should_stage
180
- @DB.transaction
181
- @DB.execute "insert into staging (path) values (?);", file
182
- @DB.commit
213
+ begin
214
+ @DB.transaction
215
+ @DB.execute "insert into staging (path) values (?);", file
216
+ @DB.commit
217
+ rescue
218
+ say "File already staged!"
219
+ end
183
220
  end
184
221
  end
185
222
  end
@@ -196,6 +233,9 @@ class LENSE
196
233
  end
197
234
 
198
235
  private
236
+ def hash_file(file)
237
+ Digest::SHA256.hexdigest(File.read(file))
238
+ end
199
239
  def get_dependency(file)
200
240
  rows = @DB.execute("
201
241
  select d.id, d.path, d.added_at, r.hash, r.created_at, c.hash
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lense
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.42
4
+ version: 0.1.43
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Zubieta