Class: Geminabox::GemStore
- Inherits:
-
Object
- Object
- Geminabox::GemStore
- Defined in:
- lib/geminabox/gem_store.rb
Instance Attribute Summary collapse
-
#gem ⇒ Object
Returns the value of attribute gem.
-
#overwrite ⇒ Object
Returns the value of attribute overwrite.
Class Method Summary collapse
Instance Method Summary collapse
- #check_replacement_status ⇒ Object
- #ensure_gem_valid ⇒ Object
-
#initialize(gem, overwrite = false) ⇒ GemStore
constructor
A new instance of GemStore.
- #prepare_data_folders ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(gem, overwrite = false) ⇒ GemStore
Returns a new instance of GemStore.
11 12 13 14 |
# File 'lib/geminabox/gem_store.rb', line 11 def initialize(gem, overwrite = false) @gem = gem @overwrite = overwrite && overwrite == 'true' end |
Instance Attribute Details
#gem ⇒ Object
Returns the value of attribute gem.
4 5 6 |
# File 'lib/geminabox/gem_store.rb', line 4 def gem @gem end |
#overwrite ⇒ Object
Returns the value of attribute overwrite.
4 5 6 |
# File 'lib/geminabox/gem_store.rb', line 4 def overwrite @overwrite end |
Class Method Details
.create(gem, overwrite = false) ⇒ Object
6 7 8 9 |
# File 'lib/geminabox/gem_store.rb', line 6 def self.create(gem, overwrite = false) gem_store = new(gem, overwrite) gem_store.save end |
Instance Method Details
#check_replacement_status ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/geminabox/gem_store.rb', line 35 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 ovewrite.") end end end |
#ensure_gem_valid ⇒ Object
45 46 47 |
# File 'lib/geminabox/gem_store.rb', line 45 def ensure_gem_valid raise GemStoreError.new(400, "Cannot process gem") unless gem.valid? end |
#prepare_data_folders ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/geminabox/gem_store.rb', line 23 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.(Geminabox.data)}." ) end end |
#save ⇒ Object
16 17 18 19 20 21 |
# File 'lib/geminabox/gem_store.rb', line 16 def save ensure_gem_valid prepare_data_folders check_replacement_status write_and_index end |