2013-12-26 09:49:49 +00:00
|
|
|
class Extension
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
include Mongoid::Slug
|
2014-01-10 08:48:23 +00:00
|
|
|
include Mongoid::Elasticsearch
|
|
|
|
|
|
|
|
include CategoryFilter
|
2013-12-26 09:49:49 +00:00
|
|
|
|
|
|
|
field :title, type: String
|
|
|
|
field :author, type: String
|
|
|
|
field :extension, type: String
|
|
|
|
field :description, type: String
|
2014-01-10 08:48:23 +00:00
|
|
|
field :category_id, type: String
|
2014-01-22 03:12:22 +00:00
|
|
|
field :repository, type: String
|
2014-01-23 09:23:50 +00:00
|
|
|
field :git_url, type: String
|
2014-01-22 03:12:22 +00:00
|
|
|
field :key, type: String
|
|
|
|
field :version, type: String
|
2014-03-14 06:37:59 +00:00
|
|
|
field :price, type: Float
|
|
|
|
field :tag, type: String
|
2014-01-10 08:48:23 +00:00
|
|
|
|
2013-12-26 09:49:49 +00:00
|
|
|
slug :title, history: true
|
|
|
|
|
2014-06-30 10:26:12 +00:00
|
|
|
has_many :previews, class_name: 'Preview'
|
|
|
|
accepts_nested_attributes_for :previews, :allow_destroy => true
|
2014-01-10 08:48:23 +00:00
|
|
|
|
2014-06-30 10:26:12 +00:00
|
|
|
belongs_to :category
|
2014-03-14 06:37:59 +00:00
|
|
|
|
2013-12-26 09:49:49 +00:00
|
|
|
mount_uploader :extension, ProductUploader
|
2014-06-30 10:26:12 +00:00
|
|
|
mount_uploader :thumbnail, ImageUploader
|
|
|
|
|
2014-01-10 08:48:23 +00:00
|
|
|
|
|
|
|
elasticsearch!
|
2014-01-22 03:12:22 +00:00
|
|
|
|
|
|
|
# after_save :get_version_number
|
|
|
|
|
2014-03-14 06:37:59 +00:00
|
|
|
SORT_TYPE = %w{Popular New Preferred}
|
|
|
|
|
2014-01-22 03:12:22 +00:00
|
|
|
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
|
2014-03-14 06:37:59 +00:00
|
|
|
|
|
|
|
def self.get_categories
|
|
|
|
categories = Category.where(type: "Extension")
|
|
|
|
end
|
2013-12-26 09:49:49 +00:00
|
|
|
end
|