module-and-template-store/app/models/extension.rb

51 lines
1.2 KiB
Ruby
Raw Normal View History

class Extension
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Slug
2014-01-10 08:48:23 +00:00
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
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
slug :title, history: true
2014-01-10 08:48:23 +00:00
belongs_to :category
2014-03-14 06:37:59 +00:00
IMAGE_SIZES = {
:thumb => [100, 100]
}
mount_uploader :preview, ImageUploader
mount_uploader :extension, ProductUploader
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
end