Class: Gistim::Create

Inherits:
Object
  • Object
show all
Defined in:
lib/gistim/create.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description: nil, alias_name: nil) ⇒ Create

Returns a new instance of Create.



3
4
5
6
# File 'lib/gistim/create.rb', line 3

def initialize(description: nil, alias_name: nil)
  @alias_name = alias_name
  @description = description
end

Instance Attribute Details

#alias_nameObject (readonly)

Returns the value of attribute alias_name.



8
9
10
# File 'lib/gistim/create.rb', line 8

def alias_name
  @alias_name
end

#urlObject (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/gistim/create.rb', line 8

def url
  @url
end

Instance Method Details

#descriptionObject



28
29
30
# File 'lib/gistim/create.rb', line 28

def description
  @description ||= '# Hello Gist!'
end

#directoryObject



40
41
42
# File 'lib/gistim/create.rb', line 40

def directory
  "#{Gistim::Command.home}/#{name}"
end

#hashObject



24
25
26
# File 'lib/gistim/create.rb', line 24

def hash
  url.nil? ? nil : url.chomp.gsub(/\A.+\//, '')
end

#hash_file_pathObject



32
33
34
# File 'lib/gistim/create.rb', line 32

def hash_file_path
  "#{directory}/.hash"
end

#implementObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gistim/create.rb', line 10

def implement
  File.write(initialize_file_path, description)

  @url = create_empty
  clone

  File.write(url_file_path, url)
  File.write(hash_file_path, hash)

  File.delete(initialize_file_path)

  self
end

#nameObject



44
45
46
# File 'lib/gistim/create.rb', line 44

def name
  alias_name || hash
end

#url_file_pathObject



36
37
38
# File 'lib/gistim/create.rb', line 36

def url_file_path
  "#{directory}/.url"
end