Sha256: 3f85b335950c2a007605a330a442c783bfff29168eaa9ce5166df525cccd9ab9

Contents?: true

Size: 719 Bytes

Versions: 18

Compression:

Stored size: 719 Bytes

Contents

#TODO may use mumukit slug
module WithSlug
  extend ActiveSupport::Concern

  included do
    validates_presence_of :slug
    validates_uniqueness_of :slug
  end

  def import!
    import_from_json! Mumukit::Bridge::Bibliotheca.new(Mumukit::Platform.bibliotheca_api.url).send(self.class.name.underscore, slug)
  end

  def slug_parts
    org, repo = slug.split('/')
    {organization: org, repository: repo}
  end

  module ClassMethods
    def import!(slug)
      transaction do
        item = find_or_initialize_by(slug: slug)
        item.save(validate: false)
        item.import!
      end
    end

    def by_slug_parts!(args)
      find_by!(slug: "#{args[:organization]}/#{args[:repository]}")
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
mumuki-laboratory-5.3.0 app/models/concerns/with_slug.rb
mumuki-laboratory-5.2.1 app/models/concerns/with_slug.rb
mumuki-laboratory-5.2.0 app/models/concerns/with_slug.rb
mumuki-laboratory-5.1.1 app/models/concerns/with_slug.rb
mumuki-laboratory-5.1.0 app/models/concerns/with_slug.rb
mumuki-laboratory-5.0.12 app/models/concerns/with_slug.rb
mumuki-laboratory-5.0.11 app/models/concerns/with_slug.rb
mumuki-laboratory-5.0.10 app/models/concerns/with_slug.rb
mumuki-laboratory-5.0.9 app/models/concerns/with_slug.rb
mumuki-laboratory-5.0.8 app/models/concerns/with_slug.rb
mumuki-laboratory-5.0.7 app/models/concerns/with_slug.rb
mumuki-laboratory-5.0.6 app/models/concerns/with_slug.rb
mumuki-laboratory-5.0.5 app/models/concerns/with_slug.rb
mumuki-laboratory-5.0.4 app/models/concerns/with_slug.rb
mumuki-laboratory-5.0.3 app/models/concerns/with_slug.rb
mumuki-laboratory-5.0.2 app/models/concerns/with_slug.rb
mumuki-laboratory-5.0.1 app/models/concerns/with_slug.rb
mumuki-laboratory-5.0.0 app/models/concerns/with_slug.rb