Sha256: 05f7e9570fcacff5fc76dc2ba7493e2e07e388f0447fb3edbab0bf9a8e46fbde

Contents?: true

Size: 761 Bytes

Versions: 5

Compression:

Stored size: 761 Bytes

Contents

require 'active_support/concern'

module Ripple
  module AttributeMethods
    module Query
      extend ActiveSupport::Concern

      included do
        attribute_method_suffix "?"
      end

      private
      # Based on code from ActiveRecord
      def attribute?(attr_name)
        unless value = attribute(attr_name)
          false
        else
          prop = self.class.properties[attr_name]
          if prop.nil?
            if Numeric === value || value !~ /[^0-9]/
              !value.to_i.zero?
            else
              Boolean.ripple_cast(value) || value.present?
            end
          elsif prop.type <= Numeric
            !value.zero?
          else
            value.present?
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 4 rubygems

Version Path
wyngle-ripple-0.1.0 lib/ripple/attribute_methods/query.rb
better-ripple-1.0.0 lib/ripple/attribute_methods/query.rb
ripple-1.0.0.beta2 lib/ripple/attribute_methods/query.rb
seomoz-ripple-1.0.0.pre lib/ripple/attribute_methods/query.rb
ripple-1.0.0.beta lib/ripple/attribute_methods/query.rb