Class: MGit::OperationProgressContext

Inherits:
Object
  • Object
show all
Defined in:
lib/m-git/foundation/operation_progress_manager.rb

Overview

本类用于缓存/加载操作中间态

Constant Summary collapse

CONTEXT_CMD =

现场信息关键字段

'cmd'
CONTEXT_OPTS =
'opts'
CONTEXT_BRANCH =
'branch'
CONTEXT_REPOS =
'repos'
CONTEXT_OTHER =
'other'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ OperationProgressContext

Returns a new instance of OperationProgressContext.



21
22
23
24
# File 'lib/m-git/foundation/operation_progress_manager.rb', line 21

def initialize(type)
  self.type = type
  self.other = {}
end

Instance Attribute Details

#branchObject

String: 仓库当前分支



17
18
19
# File 'lib/m-git/foundation/operation_progress_manager.rb', line 17

def branch
  @branch
end

#cmdObject

String: 本次执行指令,如‘merge’,‘checkout’等



15
16
17
# File 'lib/m-git/foundation/operation_progress_manager.rb', line 15

def cmd
  @cmd
end

#optsObject

String: 本次执行参数,如‘–no-ff’,‘–ff’等



16
17
18
# File 'lib/m-git/foundation/operation_progress_manager.rb', line 16

def opts
  @opts
end

#otherObject

Object: 其他信息,可自定义



19
20
21
# File 'lib/m-git/foundation/operation_progress_manager.rb', line 19

def other
  @other
end

#reposObject

[String]: 本次执行哪些仓库的名称数组



18
19
20
# File 'lib/m-git/foundation/operation_progress_manager.rb', line 18

def repos
  @repos
end

#typeObject

String: 本次进入中间态的操作类型,可自定义,如‘merge_in_progress’,‘rebase_in_progress’等。该字段用于索引缓存的中间态信息,需要唯一。



14
15
16
# File 'lib/m-git/foundation/operation_progress_manager.rb', line 14

def type
  @type
end

Instance Method Details

#deserialize(dict) ⇒ Object

反序列化

Parameters:

  • dict (Hash)

    中间态Hash



41
42
43
44
45
46
47
# File 'lib/m-git/foundation/operation_progress_manager.rb', line 41

def deserialize(dict)
  self.cmd = dict[CONTEXT_CMD]
  self.opts = dict[CONTEXT_OPTS]
  self.branch = dict[CONTEXT_BRANCH]
  self.repos = dict[CONTEXT_REPOS]
  self.other = dict[CONTEXT_OTHER]
end

#serializeObject

将中间态对象序列化为Hash



27
28
29
30
31
32
33
34
35
# File 'lib/m-git/foundation/operation_progress_manager.rb', line 27

def serialize
  return {
      CONTEXT_CMD         => self.cmd,
      CONTEXT_OPTS        => self.opts,
      CONTEXT_BRANCH      => self.branch,
      CONTEXT_REPOS       => self.repos,
      CONTEXT_OTHER       => self.other
  }
end

#validate?Boolean

校验中间态是否合法,仓库可缺省,若缺省则表示所有仓库

Returns:

  • (Boolean)

    是否合法



53
54
55
# File 'lib/m-git/foundation/operation_progress_manager.rb', line 53

def validate?
  return !self.cmd.nil? && !self.opts.nil? && !self.branch.nil?
end