Class: Geminabox::GemStore

Inherits:
Object
  • Object
show all
Defined in:
lib/geminabox/gem_store.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gem, overwrite = false) ⇒ GemStore

Returns a new instance of GemStore.



13
14
15
16
# File 'lib/geminabox/gem_store.rb', line 13

def initialize(gem, overwrite = false)
  @gem = gem
  @overwrite = overwrite && overwrite == 'true'
end

Instance Attribute Details

#gemObject

Returns the value of attribute gem.



6
7
8
# File 'lib/geminabox/gem_store.rb', line 6

def gem
  @gem
end

#overwriteObject

Returns the value of attribute overwrite.



6
7
8
# File 'lib/geminabox/gem_store.rb', line 6

def overwrite
  @overwrite
end

Class Method Details

.create(gem, overwrite = false) ⇒ Object



8
9
10
11
# File 'lib/geminabox/gem_store.rb', line 8

def self.create(gem, overwrite = false)
  gem_store = new(gem, overwrite)
  gem_store.save
end

Instance Method Details

#check_replacement_statusObject



37
38
39
40
41
42
43
44
45
# File 'lib/geminabox/gem_store.rb', line 37

def check_replacement_status
  if !overwrite and Geminabox::Server.disallow_replace? and File.exist?(gem.dest_filename)
    if existing_file_digest != gem.hexdigest
      raise GemStoreError.new(409, "Updating an existing gem is not permitted.\nYou should either delete the existing version, or change your version number.")
    else
      raise GemStoreError.new(200, "Ignoring upload, you uploaded the same thing previously.\nPlease use -o to overwrite.")
    end
  end
end

#ensure_gem_validObject

Raises:



47
48
49
# File 'lib/geminabox/gem_store.rb', line 47

def ensure_gem_valid
  raise GemStoreError.new(400, "Cannot process gem") unless gem.valid?
end

#prepare_data_foldersObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/geminabox/gem_store.rb', line 25

def prepare_data_folders
  ensure_existing_data_folder_compatible
  begin
    FileUtils.mkdir_p(File.join(Geminabox.data, "gems"))
  rescue
    raise GemStoreError.new(
      500,
      "Could not create #{File.expand_path(Geminabox.data)}."
    )
  end
end

#saveObject



18
19
20
21
22
23
# File 'lib/geminabox/gem_store.rb', line 18

def save
  ensure_gem_valid
  prepare_data_folders
  check_replacement_status
  write_and_index
end