gitdb 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 415b324df37bb5e094057579249db2c48bb0688c
4
- data.tar.gz: 14b33e1f14ff4f2042c4c241d74789973ee9428f
3
+ metadata.gz: fd555baba7939ba328863a24472a914e7d9eb436
4
+ data.tar.gz: d99302d2a081c812e8ab8757016cfd1acc79f24d
5
5
  SHA512:
6
- metadata.gz: 4dbb35666c3a91878196ef67f6a4be2e5d3c70ad20260c3b86e5e1f3713b184a8a0e7b499bb9334c83429efefaa4ac546cc3cad2b2d3b62e5cc8322961ba9cc0
7
- data.tar.gz: 06b3e24be21830a88f773e2867e7170cb9a42b89881f59a5e1a11ead45a09c01e8423463e9319d4b8e7a4daaf1c6039109bddc575e59c47789cd754e068bb5a0
6
+ metadata.gz: 06cf2a433f5c1734784a91cdf2190618cce47ddf4d9186e19cc42a6b779ee045c72ae29f973ed003e28eeaf6204e59da825c7358c520589e3ed0b8ae2af0d034
7
+ data.tar.gz: 906d0588f6c7206b39bbdac91e70da37f0f938b9c62f238de946a8b18194a483b509c0fc85bd8a4b8413985af3be82e5329990dfcbe29ef745b1f87f88d603b9
data/README.md CHANGED
@@ -30,19 +30,19 @@ Or install it yourself as:
30
30
 
31
31
  + class method: `exist?(gid)`
32
32
 
33
- ##### instance: `Gitdb::Contacts.new(uid)`
33
+ ##### instance: `Gitdb::Contacts.new(user_id)`
34
34
 
35
35
  + property: `repo`
36
- + method: `exist?(gid)`
37
- + method: `create(gid)`
38
- + method: `access(gid)`
36
+ + method: `exist?(contacts_id)`
37
+ + method: `create(contacts_name)`
38
+ + method: `access(contacts_id)`
39
39
  + method: `getmeta`
40
40
  + method: `setmeta(Hash)`
41
41
  + method: `get_all_cards`
42
- + method: `get_card_by_id(id)`
42
+ + method: `get_card_by_id(card_id)`
43
43
  + method: `read_change_history`
44
- + method: `revert_to(sha, authorhash, message)`
45
- + method: `make_a_commit(optionhash)`
44
+ + method: `revert_to(sha, {})`
45
+ + method: `make_a_commit({})`
46
46
 
47
47
  #### Class: `Gitdb::Card`
48
48
 
@@ -50,8 +50,8 @@ Or install it yourself as:
50
50
 
51
51
  ##### instance: `Gitdb::Card.new(repo)`
52
52
 
53
- + method: `create(uid)`
54
- + method: `access(id)`
53
+ + method: `create(user_id)`
54
+ + method: `access(card_id)`
55
55
  + method: `format_card(id, uid)`
56
56
  + method: `getdata`
57
57
  + method: `setdata(Hash)`
data/lib/gitdb/Card.rb CHANGED
@@ -3,7 +3,7 @@ module Gitdb
3
3
  class Card
4
4
 
5
5
  # 线程锁
6
- @@lock = false
6
+ @@lock = Mutex.new
7
7
 
8
8
  def initialize repo
9
9
  @repo = repo
@@ -39,25 +39,19 @@ module Gitdb
39
39
  end
40
40
 
41
41
  def create uid
42
- # 等待资源可用
43
- loop do
44
- break unless @@lock
45
- end
46
- # 锁定资源
47
- @@lock = true
48
-
49
- # 生成唯一的名片id
50
- while exist?(@id = Gitil::generate_code(4))
51
- end
52
- # 记录名片创建者id
53
- @uid = uid
54
- # 用默认格式初始化名片可读内容
55
- @content = format_card @id, @uid
56
- # 添加到暂存区
57
- add_to_stage @id, JSON.pretty_generate(@content)
58
42
 
59
- # 释放资源
60
- @@lock = false
43
+ # 同步信号量
44
+ @@lock.synchronize {
45
+ # 生成唯一的名片id
46
+ while exist?(@id = Gitil::generate_code(4))
47
+ end
48
+ # 记录名片创建者id
49
+ @uid = uid
50
+ # 用默认格式初始化名片可读内容
51
+ @content = format_card @id, @uid
52
+ # 添加到暂存区
53
+ add_to_stage @id, JSON.pretty_generate(@content)
54
+ }
61
55
 
62
56
  # 返回Card实例
63
57
  self
@@ -77,26 +71,6 @@ module Gitdb
77
71
  nil
78
72
  end
79
73
  end
80
-
81
- def self::getdata repo, id
82
- Card.new(repo).access(id).getdata
83
- end
84
-
85
- def self::setdata repo, id, hash
86
- Card.new(repo).access(id).setdata hash
87
- end
88
-
89
- def self::getmeta repo, id
90
- Card.new(repo).access(id).getmeta
91
- end
92
-
93
- def self::setmeta repo, id, hash
94
- Card.new(repo).access(id).setmeta hash
95
- end
96
-
97
- def self::delete repo, id
98
- Card.new(repo).access(id).delete
99
- end
100
74
 
101
75
  def getdata
102
76
  data = @content.clone
@@ -3,7 +3,7 @@ module Gitdb
3
3
  class Contacts
4
4
 
5
5
  # 线程锁
6
- @@lock = false
6
+ @@lock = Mutex.new
7
7
 
8
8
  attr_accessor 'repo'
9
9
 
@@ -20,20 +20,16 @@ module Gitdb
20
20
  end
21
21
 
22
22
  def create name
23
- # 等待资源可用
24
- loop do
25
- break unless @@lock
26
- end
27
- # 锁定资源
28
- @@lock = true
29
23
 
30
- # 生成联系人的唯一编码
31
- while exist?(@gid = Gitil::generate_code(4))
32
- end
33
- # 创建并打开git仓库
34
- @repo = Rugged::Repository.init_at "#{STORAGE_PATH}/#{@gid}"
35
- # 释放资源
36
- @@lock = false
24
+ # 同步信号量
25
+ @@lock.synchronize {
26
+ # 生成联系人的唯一编码
27
+ while exist?(@gid = Gitil::generate_code(4))
28
+ end
29
+ # 创建并打开git仓库
30
+ @repo = Rugged::Repository.init_at "#{STORAGE_PATH}/#{@gid}"
31
+ }
32
+
37
33
  # 设置元信息
38
34
  setmeta :name => name, :gid => @gid, :owner => @uid
39
35
  # 读取最后一次提交指向的tree的数据到暂存区
data/lib/gitdb/util.rb CHANGED
@@ -5,7 +5,7 @@ module Gitil
5
5
  end
6
6
 
7
7
  def self::data_keys_of_card
8
- ["firstname", "lastname", "mobile", "phone", "email", "birthday", "address", "im"]
8
+ ["firstname", "lastname", "mobile", "phone", "email", "birthday", "address", "im", "note"]
9
9
  end
10
10
 
11
11
  def self::meta_keys_of_card
data/lib/gitdb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gitdb
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/gitdb.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "json"
2
2
  require "rugged"
3
+ require "thread"
3
4
  require "gitdb/util"
4
5
  require "gitdb/version"
5
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ran