Sha256: 97333795e66a106f9591ed2a33c67f9f0143ea7ff79e62dd639aa28603ca7207

Contents?: true

Size: 545 Bytes

Versions: 8

Compression:

Stored size: 545 Bytes

Contents

module Hancock::BooleanField
  extend ActiveSupport::Concern
  module ClassMethods
    def boolean_field(name, default = true)
      if default.is_a?(Hash)
        default = default[:default]
      end
      
      if Hancock.mongoid?
        field name, type: Mongoid::Boolean, default: default
      end
      scope name, -> { where(name => true) }

      if name == 'active'
        scope :inactive,  -> { where(active: false) }
      elsif name == 'enabled'
        scope :disabled,  -> { where(enabled: false) }
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hancock_cms-1.0.1 app/models/concerns/hancock/boolean_field.rb
hancock_cms-2.0.0.2 app/models/concerns/hancock/boolean_field.rb
hancock_cms-1.0.0.4 app/models/concerns/hancock/boolean_field.rb
hancock_cms-1.0.0.3 app/models/concerns/hancock/boolean_field.rb
hancock_cms-2.0.0.1 app/models/concerns/hancock/boolean_field.rb
hancock_cms-1.0.0.2 app/models/concerns/hancock/boolean_field.rb
hancock_cms-2.0.0 app/models/concerns/hancock/boolean_field.rb
hancock_cms-1.0.0 app/models/concerns/hancock/boolean_field.rb