Class: Gluttonberg::Setting
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Gluttonberg::Setting
- Defined in:
- app/models/gluttonberg/setting.rb
Class Method Summary collapse
- .generate_common_settings ⇒ Object
- .generate_or_update_settings(settings = {}) ⇒ Object
- .get_setting(key) ⇒ Object
- .has_deletable_settings? ⇒ Boolean
- .update_settings(settings = {}) ⇒ Object
Instance Method Summary collapse
- #destroy_cache ⇒ Object
- #dropdown_required? ⇒ Boolean
- #parsed_values_list_for_dropdown ⇒ Object
- #update_settings_in_config ⇒ Object
- #user_friendly_name ⇒ Object
Class Method Details
.generate_common_settings ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/gluttonberg/setting.rb', line 24 def self.generate_common_settings settings = { :title => [ "" , 0, "Website Title"], :keywords => ["" , 1, "Please separate keywords with a comma."], :description => ["" ,2 , "The Description will appear in search engine's result list."], :fb_icon => ["" , 3 , "Facebook Icon for the website"], :google_analytics => ["", 4, "Google Analytics ID"], :comment_notification => ["No" , 5 , "Enable comment notification" , "Yes;No" ], :number_of_revisions => ["10" , 6 , "Number of revisions to maintain for versioned contents."], :library_number_of_recent_assets => ["15" , 7 , "Number of recent assets in asset library."], :number_of_per_page_items => ["20" , 8 , "Number of per page items for any paginated content."], :enable_WYSIWYG => ["Yes" , 9 , "Enable WYSIWYG on textareas" , "Yes;No" ], :backend_logo => ["" , 10 , "Logo for backend" ] , :restrict_site_access => ["" , 11 , "If this setting is provided then user needs to enter password to access public site."] , :from_email => ["" , 12 , "This email address is used for 'from' email address for all emails sent through system."], :video_assets => ["" , 13 , "FFMPEG settings" , "Enable;Disable"], :s3_key_id => ["" , 14 , "S3 Key ID"], :s3_access_key => ["" , 15 , "S3 Access Key"], :s3_server_url => ["" , 16 , "S3 Server URL"], :s3_bucket => ["" , 17 , "S3 Bucket Name"], :audio_assets => ["" , 18 , "Audio settings" , "Enable;Disable"], :comment_blacklist => ["" , 19 , "When a comment contains any of these words in its comment, Author Name, Author website, Author e-mail, it will be marked as spam. It will match inside words, so \"able\" will match \"comparable\". Please separate words with a comma."], :comment_email_as_spam => ["Yes" , 20 , "Do you want to mark those comments as spam which only contains emails and urls?" , "Yes;No" ], :comment_number_of_emails_allowed => ["2" , 21 , "How many email addresses should a comment include to be marked as spam?" ], :comment_number_of_urls_allowed => ["2" , 21 , "How many URLs should a comment include to be marked as spam?" ] } self.generate_or_update_settings(settings) end |
.generate_or_update_settings(settings = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/models/gluttonberg/setting.rb', line 8 def self.generate_or_update_settings(settings={}) settings.each do |key , val | obj = self.find(:first , :conditions => {:name => key }) if obj.blank? obj = self.new(:name=> key , :value => val[0] , :row => val[1] , :delete_able => false , :help => val[2] , :values_list => val[3]) obj.save! else obj.update_attributes(:name=> key , :row => val[1] , :delete_able => false , :help => val[2]) end end end |
.get_setting(key) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/models/gluttonberg/setting.rb', line 67 def self.get_setting(key) if Gluttonberg::Setting.table_exists? data = nil begin data = Rails.cache.read("setting_#{key}") rescue end if data.blank? setting = Setting.find(:first , :conditions => { :name => key }) data = ( (!setting.blank? && !setting.value.blank?) ? setting.value : "" ) Rails.cache.write("setting_#{key}" , (data.blank? ? "~" : data)) data elsif data == "~" # empty setting "" else data end end end |
.has_deletable_settings? ⇒ Boolean
53 54 55 |
# File 'app/models/gluttonberg/setting.rb', line 53 def self.has_deletable_settings? self.where(:delete_able => true).count > 0 end |
.update_settings(settings = {}) ⇒ Object
87 88 89 90 91 92 93 |
# File 'app/models/gluttonberg/setting.rb', line 87 def self.update_settings(settings={}) settings.each do |key , val | obj = self.where(:name=> key).first obj.value = val obj.save! end end |
Instance Method Details
#destroy_cache ⇒ Object
104 105 106 |
# File 'app/models/gluttonberg/setting.rb', line 104 def destroy_cache Rails.cache.write("setting_#{self.name}" , "") end |
#dropdown_required? ⇒ Boolean
57 58 59 |
# File 'app/models/gluttonberg/setting.rb', line 57 def dropdown_required? !values_list.blank? end |
#parsed_values_list_for_dropdown ⇒ Object
61 62 63 64 65 |
# File 'app/models/gluttonberg/setting.rb', line 61 def parsed_values_list_for_dropdown unless values_list.blank? values_list.split(";") end end |
#update_settings_in_config ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'app/models/gluttonberg/setting.rb', line 95 def update_settings_in_config begin setting = self Rails.cache.write("setting_#{setting.name}" , setting.value) rescue => e Rails.logger.info e end end |
#user_friendly_name ⇒ Object
20 21 22 |
# File 'app/models/gluttonberg/setting.rb', line 20 def user_friendly_name name.titlecase end |