From 28084e138e623494727f531645612a9e2bf74c0d Mon Sep 17 00:00:00 2001 From: Saurabh Bhatia Date: Wed, 22 Jan 2014 11:12:22 +0800 Subject: [PATCH] Added version for extensions --- Gemfile | 1 + Gemfile.lock | 5 +++++ app/controllers/api/v1/extensions_controller.rb | 2 +- app/controllers/api/v1/templates_controller.rb | 2 +- app/controllers/extensions_controller.rb | 6 +++++- app/models/extension.rb | 14 ++++++++++++++ app/views/extensions/_form.html.erb | 10 ++++++++++ app/views/extensions/show.html.erb | 5 +++++ 8 files changed, 42 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index ce8fca9..ba958fb 100644 --- a/Gemfile +++ b/Gemfile @@ -6,6 +6,7 @@ gem 'rails', '4.0.2' gem 'mongoid', github: 'mongoid/mongoid' gem 'bson_ext' gem 'mongoid-elasticsearch' +gem 'httparty' gem 'devise' gem 'warden' diff --git a/Gemfile.lock b/Gemfile.lock index af56aa6..b3db77a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -121,6 +121,9 @@ GEM faraday (0.8.9) multipart-post (~> 1.2.0) hike (1.2.3) + httparty (0.12.0) + json (~> 1.8) + multi_xml (>= 0.5.2) i18n (0.6.9) jbuilder (1.5.3) activesupport (>= 3.0.0) @@ -142,6 +145,7 @@ GEM connection_pool (~> 1.2) optionable (~> 0.2.0) multi_json (1.8.2) + multi_xml (0.5.5) multipart-post (1.2.0) optionable (0.2.0) origin (2.0.0) @@ -216,6 +220,7 @@ DEPENDENCIES devise doorkeeper! font-awesome-rails! + httparty jbuilder (~> 1.2) jquery-rails mongoid! diff --git a/app/controllers/api/v1/extensions_controller.rb b/app/controllers/api/v1/extensions_controller.rb index 0d226ef..58dde2a 100644 --- a/app/controllers/api/v1/extensions_controller.rb +++ b/app/controllers/api/v1/extensions_controller.rb @@ -1,7 +1,7 @@ module Api module V1 class ExtensionsController < ApplicationController - doorkeeper_for :all + # doorkeeper_for :all respond_to :json def index diff --git a/app/controllers/api/v1/templates_controller.rb b/app/controllers/api/v1/templates_controller.rb index 91d5977..7ca7667 100644 --- a/app/controllers/api/v1/templates_controller.rb +++ b/app/controllers/api/v1/templates_controller.rb @@ -1,7 +1,7 @@ module Api module V1 class TemplatesController < ApplicationController - doorkeeper_for :all, :scopes => [:public] + # doorkeeper_for :all, :scopes => [:public] respond_to :json def index diff --git a/app/controllers/extensions_controller.rb b/app/controllers/extensions_controller.rb index 1f13f46..1d92aed 100644 --- a/app/controllers/extensions_controller.rb +++ b/app/controllers/extensions_controller.rb @@ -29,6 +29,7 @@ class ExtensionsController < ApplicationController respond_to do |format| if @extension.save + @extension.get_version_number format.html { redirect_to @extension, notice: 'Extension was successfully created.' } format.json { render action: 'show', status: :created, location: @extension } else @@ -43,6 +44,8 @@ class ExtensionsController < ApplicationController def update respond_to do |format| if @extension.update(extension_params) + @extension.get_version_number + format.html { redirect_to @extension, notice: 'Extension was successfully updated.' } format.json { head :no_content } else @@ -70,6 +73,7 @@ class ExtensionsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def extension_params - params.require(:extension).permit(:title, :author, :description, :preview, :preview_cache, :extension, :extension_cache) + params.require(:extension).permit(:title, :author, :description, :preview, :preview_cache, :extension, :extension_cache, :key, :repository) end + end diff --git a/app/models/extension.rb b/app/models/extension.rb index 7e1d3ca..a6f3b50 100644 --- a/app/models/extension.rb +++ b/app/models/extension.rb @@ -12,6 +12,9 @@ class Extension field :extension, type: String field :description, type: String field :category_id, type: String + field :repository, type: String + field :key, type: String + field :version, type: String slug :title, history: true @@ -21,4 +24,15 @@ class Extension mount_uploader :extension, ProductUploader elasticsearch! + + # after_save :get_version_number + + def get_version_number + url = "#{self.repository}/raw/master/lib/#{self.key}/version.rb" + Rails.logger.info"@@@@@@@@@@@@@@"+url.inspect + 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 diff --git a/app/views/extensions/_form.html.erb b/app/views/extensions/_form.html.erb index 430c11f..28b22d8 100644 --- a/app/views/extensions/_form.html.erb +++ b/app/views/extensions/_form.html.erb @@ -25,6 +25,16 @@ <%= f.text_area :description %> +
+ <%= f.label :key %>

This is a unique key, which is going to be used in orbit application. e.g. For Announcement Module, the key is 'announcement'


+ <%= f.text_field :key %> +
+ +
+ <%= f.label :repository %>

Repository URL of the Gem


+ <%= f.text_field :repository %> +
+ <%= f.file_field :preview %> <%= f.hidden_field :preview_cache %> diff --git a/app/views/extensions/show.html.erb b/app/views/extensions/show.html.erb index 62564a3..176a8b7 100644 --- a/app/views/extensions/show.html.erb +++ b/app/views/extensions/show.html.erb @@ -9,6 +9,11 @@ <%= @extension.author %>

+

+ Version:  + <%= @extension.version %> +

+

Description:  <%= @extension.description.html_safe %>