Sha256: 4069a99daf07e489b7350055ef79ef7dcfb9746f098fbe02ac79b8054a3decc0

Contents?: true

Size: 1.21 KB

Versions: 16

Compression:

Stored size: 1.21 KB

Contents

module RailsSettings
  module Extend
    extend ActiveSupport::Concern

    included do
      scope :with_settings, lambda {
        joins("JOIN settings ON (settings.thing_id = #{table_name}.#{primary_key} AND
                                 settings.thing_type = '#{base_class.name}')")
          .select("DISTINCT #{table_name}.*")
      }

      scope :with_settings_for, lambda  { |var|
        joins("JOIN settings ON (settings.thing_id = #{table_name}.#{primary_key} AND
                                 settings.thing_type = '#{base_class.name}') AND settings.var = '#{var}'")
      }

      scope :without_settings, lambda {
        joins("LEFT JOIN settings ON (settings.thing_id = #{table_name}.#{primary_key} AND
                                      settings.thing_type = '#{base_class.name}')")
          .where('settings.id IS NULL')
      }

      scope :without_settings_for, lambda  { |var|
        where('settings.id IS NULL')
          .joins("LEFT JOIN settings ON (settings.thing_id = #{table_name}.#{primary_key} AND
                                       settings.thing_type = '#{base_class.name}') AND settings.var = '#{var}'")
      }
    end

    def settings
      ScopedSettings.for_thing(self)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rails-settings-cached-0.6.4 lib/rails-settings/extend.rb
rails-settings-cached-0.6.3 lib/rails-settings/extend.rb
rails-settings-cached-0.6.2 lib/rails-settings/extend.rb
rails-settings-cached-0.6.1 lib/rails-settings/extend.rb
rails-settings-cached-0.6.0 lib/rails-settings/extend.rb
rails-settings-cached-0.5.6 lib/rails-settings/extend.rb
rails-settings-cached-0.5.5 lib/rails-settings/extend.rb
rails-settings-cached-0.5.4 lib/rails-settings/extend.rb
rails-settings-cached-0.5.3 lib/rails-settings/extend.rb
rails-settings-cached-0.5.2 lib/rails-settings/extend.rb
rails-settings-cached-0.5.0 lib/rails-settings/extend.rb
rails-settings-cached-0.4.6 lib/rails-settings/extend.rb
rails-settings-cached-0.4.5 lib/rails-settings/extend.rb
rails-settings-cached-0.4.4 lib/rails-settings/extend.rb
rails-settings-cached-0.4.3 lib/rails-settings/extend.rb
rails-settings-cached-0.4.2 lib/rails-settings/extend.rb