Class: FakeGit::Priv::Object

Inherits:
Object
  • Object
show all
Defined in:
lib/fake_git/priv/object.rb

Defined Under Namespace

Classes: TypeError

Constant Summary collapse

ALLOWED_TYPES =
["blob", "tree", "commit", "tag", nil]
OBJ_PATH =
".fakegit/objects"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type: nil, content: nil, index: nil, path: nil, file_name: nil, message: nil, tree: nil, date: nil) ⇒ Object

Returns a new instance of Object.

Raises:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fake_git/priv/object.rb', line 8

def initialize(type: nil,
               content: nil,
               index: nil,
               path: nil,
               file_name: nil,
               message: nil,
               tree: nil,
               date: nil)
  @type = type
  @content = content
  @index = index
  @path = path
  @file_name = file_name
  @message = message
  @tree = tree
  @date = Time.now

  raise TypeError.new("#{type} must be one of #{ALLOWED_TYPES}") if !ALLOWED_TYPES.include?(@type)
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



6
7
8
# File 'lib/fake_git/priv/object.rb', line 6

def content
  @content
end

#dateObject

Returns the value of attribute date.



6
7
8
# File 'lib/fake_git/priv/object.rb', line 6

def date
  @date
end

#file_nameObject

Returns the value of attribute file_name.



6
7
8
# File 'lib/fake_git/priv/object.rb', line 6

def file_name
  @file_name
end

#indexObject

Returns the value of attribute index.



6
7
8
# File 'lib/fake_git/priv/object.rb', line 6

def index
  @index
end

#messageObject

Returns the value of attribute message.



6
7
8
# File 'lib/fake_git/priv/object.rb', line 6

def message
  @message
end

#pathObject

Returns the value of attribute path.



6
7
8
# File 'lib/fake_git/priv/object.rb', line 6

def path
  @path
end

#treeObject

Returns the value of attribute tree.



6
7
8
# File 'lib/fake_git/priv/object.rb', line 6

def tree
  @tree
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/fake_git/priv/object.rb', line 6

def type
  @type
end

Instance Method Details

#write!Object



28
29
30
31
32
# File 'lib/fake_git/priv/object.rb', line 28

def write!
  write_top_index
  write_new_index
  puts index
end