39 lines
1.0 KiB
Ruby
39 lines
1.0 KiB
Ruby
class Extension
|
|
include Mongoid::Document
|
|
include Mongoid::Timestamps
|
|
include Mongoid::Slug
|
|
include Mongoid::Elasticsearch
|
|
|
|
include CategoryFilter
|
|
|
|
field :title, type: String
|
|
field :author, type: String
|
|
field :preview, type: String
|
|
field :extension, type: String
|
|
field :description, type: String
|
|
field :category_id, type: String
|
|
field :repository, type: String
|
|
field :git_url, type: String
|
|
field :key, type: String
|
|
field :version, type: String
|
|
|
|
slug :title, history: true
|
|
|
|
belongs_to :category
|
|
|
|
mount_uploader :preview, ImageUploader
|
|
mount_uploader :extension, ProductUploader
|
|
|
|
elasticsearch!
|
|
|
|
# after_save :get_version_number
|
|
|
|
def get_version_number
|
|
url = "#{self.repository}/raw/master/lib/#{self.key}/version.rb"
|
|
response = Net::HTTP.get_response(URI.parse(url)).body
|
|
data = HTTParty::Parser.new(response, 'rb').parse
|
|
version = data.gsub!(/\s+/, "").tr!('"','').gsub("module#{self.key.capitalize}VERSION=",'').gsub("end",'')
|
|
self.update(version: version)
|
|
end
|
|
end
|