class PersonalPluginField include Mongoid::Document include Mongoid::Timestamps include OrbitModel::Status include MemberHelper field :author_name, :type => String, :default => "",:localize => true field :title, :type => String, :default => "",:localize => true field :module_name, :type => String, :default => "" field :primary_modal_name, :type => String, :default => "" field :related_modal_name, :type => Array, :default => [] field :primary_modal_fields, :type => Array, :default => [] field :related_modal_fields, :type => Array, :default => [] #ex: [[],[]] field :backend_fields, :type => Hash, :default => {} field :frontend_fields, :type => Hash, :default => {} field :log_text, :type => String, :default => "" before_save :check_plugin_exist def get_all_gem_plugins extention_files = ["downloaded_extensions.rb","built_in_extensions.rb"] gem_plugins = extention_files.map{|f| (File.read(f).scan(/\n\s*gem\s*["'](.*)["']\s*,/).flatten rescue [])}.flatten end def check_plugin_exist gem_plugins = get_all_gem_plugins can_install = !gem_plugins.include?(self.module_name) can_install = (self.class.where(:module_name=>self.module_name,:id.ne=>self.id).count == 0 rescue false) if !can_install return can_install end end