orbit-4-2/app/controllers/admin/module_store_controller.rb

41 lines
1.0 KiB
Ruby
Raw Normal View History

class Admin::ModuleStoreController < OrbitBackendController
@@store = STORE_CONFIG[:store_settings]["url"]
def index
@extensions = get_extensions
end
def show
@extension = get_extension(params[:id]) rescue nil
end
def download
#get extension related values
extension = get_extension(params[:id]) rescue nil
2014-01-23 10:27:24 +00:00
extension_name = extension["key"].to_s
git_repository_url = extension["git_url"]
version = extension["version"]
module_installed = File.read("downloaded_extensions.rb").include?(extension["key"])
if module_installed.eql?(false)
@download_link = "gem '#{extension_name}', '#{version}', :git => '#{git_repository_url}'"
File.open("downloaded_extensions.rb", 'a') do |file|
file.puts @download_link
end
end
2014-01-23 10:27:24 +00:00
%w(bundle install)
site_restart
redirect_to admin_module_store_path
end
protected
def get_extensions
JSON.parse(open("#{@@store}/api/extensions").read)
end
def get_extension(id)
JSON.parse(open("#{@@store}/api/extensions/#{id}").read)
end
end