class Shard::Saver
Constants
- SHA_LENGTH
Attributes
full_gist[R]
gist[R]
options[R]
ref[R]
Public Class Methods
new(shard_line_or_ref, options = {})
click to toggle source
#
Constructor #
#
# File lib/shard/saver.rb, line 23 def initialize(shard_line_or_ref, options = {}) @ref = Shard::Ref(shard_line_or_ref) @options = options end
save(shard_line, options = {})
click to toggle source
#
Class Methods #
#
# File lib/shard/saver.rb, line 34 def self.save(shard_line, options = {}) new(shard_line, options).save! end
Public Instance Methods
save!()
click to toggle source
#
Instance Methods #
#
# 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
Private Instance Methods
fetch_shard_contents()
click to toggle source
# File lib/shard/saver.rb, line 61 def fetch_shard_contents lister = Shard::Lister.new(ref.user) @gist = lister.shards[ref.name] @full_gist = Shard.api.gist gist.id end
file_contents(filename)
click to toggle source
# File lib/shard/saver.rb, line 67 def file_contents(filename) full_gist.files[filename].content end
version(length = SHA_LENGTH)
click to toggle source
# File lib/shard/saver.rb, line 82 def version(length = SHA_LENGTH) full_version = full_gist.history.first.version full_version[0...length] end
write_file(file)
click to toggle source
# File lib/shard/saver.rb, line 71 def write_file(file) path = file_path(ref, file.filename) contents = file_contents(file.filename) if options[:verbose] puts "Saving #{ file.filename }" end File.write path, contents end