Sha256: 0020eae22e2e0afa425a7b80a24fecc90b75db125af081cc446cb4a2d272f2e5

Contents?: true

Size: 1.62 KB

Versions: 5

Compression:

Stored size: 1.62 KB

Contents

module RailsSettings
  module Extend
    extend ActiveSupport::Concern
    
    included do 
      scope :with_settings, :joins => "JOIN settings ON (settings.thing_id = #{self.table_name}.#{self.primary_key} AND
                                       settings.thing_type = '#{self.base_class.name}')",
                            :select => "DISTINCT #{self.table_name}.*" 

      scope :with_settings_for, lambda { |var| { :joins => "JOIN settings ON (settings.thing_id = #{self.table_name}.#{self.primary_key} AND
                                                             settings.thing_type = '#{self.base_class.name}') AND settings.var = '#{var}'" } }
                                                               
      scope :without_settings, :joins => "LEFT JOIN settings ON (settings.thing_id = #{self.table_name}.#{self.primary_key} AND
                                                                 settings.thing_type = '#{self.base_class.name}')",
                               :conditions => 'settings.id IS NULL'
                                     
      scope :without_settings_for, lambda { |var| { :joins => "LEFT JOIN settings ON (settings.thing_id = #{self.table_name}.#{self.primary_key} AND
                                                                                      settings.thing_type = '#{self.base_class.name}') AND
                                                                                      settings.var = '#{var}'",
                                                    :conditions => 'settings.id IS NULL' } }
    end
    
    def settings
      ScopedSettings.for_thing(self)
    end
  end
end


Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rails-settings-cached-0.2.4 lib/rails-settings/extend.rb
rails-settings-cached-0.2.3 lib/rails-settings/extend.rb
rails-settings-cached-0.2.2 lib/rails-settings/extend.rb
rails-settings-cached-0.2.1 lib/rails-settings/extend.rb
rails-settings-cached-0.2.0 lib/rails-settings/extend.rb