personal_plugin_generator/app/models/personal_plugin_field.rb

28 lines
1.3 KiB
Ruby
Raw Normal View History

2021-02-27 04:19:24 +00:00
class PersonalPluginField
include Mongoid::Document
include Mongoid::Timestamps
include OrbitModel::Status
include MemberHelper
2021-03-01 15:44:52 +00:00
field :author_name, :type => String, :default => "",:localize => true
2021-02-27 04:19:24 +00:00
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 => {}
2021-03-03 12:24:10 +00:00
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
2021-02-27 04:19:24 +00:00
end