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.
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
#gem ⇒ Object
Returns the value of attribute gem.
6 7 8 |
# File 'lib/geminabox/gem_store.rb', line 6 def gem @gem end |
#overwrite ⇒ Object
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_status ⇒ Object
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_valid ⇒ Object
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_folders ⇒ Object
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.(Geminabox.data)}." ) end end |
#save ⇒ Object
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 |