Class: Shard::Saver

Inherits:
Object
  • Object
show all
Includes:
ShardDirectory
Defined in:
lib/shard/saver.rb

Constant Summary collapse

SHA_LENGTH =
8

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ShardDirectory

#create_shard_dir, #directory, #file_path, #find_file_path, #find_file_paths, #root_path, #shard_dir_exists?

Constructor Details

#initialize(shard_line_or_ref, options = {}) ⇒ Saver

# Constructor #

#


23
24
25
26
# File 'lib/shard/saver.rb', line 23

def initialize(shard_line_or_ref, options = {})
  @ref     = Shard::Ref(shard_line_or_ref)
  @options = options
end

Instance Attribute Details

#full_gistObject (readonly)

Returns the value of attribute full_gist.



13
14
15
# File 'lib/shard/saver.rb', line 13

def full_gist
  @full_gist
end

#gistObject (readonly)

Returns the value of attribute gist.



13
14
15
# File 'lib/shard/saver.rb', line 13

def gist
  @gist
end

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/shard/saver.rb', line 13

def options
  @options
end

#refObject (readonly)

Returns the value of attribute ref.



13
14
15
# File 'lib/shard/saver.rb', line 13

def ref
  @ref
end

Class Method Details

.save(shard_line, options = {}) ⇒ Object

# Class Methods #

#


34
35
36
# File 'lib/shard/saver.rb', line 34

def self.save(shard_line, options = {})
  new(shard_line, options).save!
end

Instance Method Details

#save!Object

# Instance Methods #

#


44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/shard/saver.rb', line 44

def save!
  return if shard_dir_exists?(ref) && options[:lazy]
  
  create_shard_dir(ref)
  fetch_shard_contents

  gist.all_files.each do |file|
    write_file(file)
  end

  if options[:verbose]
    puts "VERSION #{ version }..."
  end
end