Sha256: 84893d259ca616e35e59e687947eab8451575862c6ef795dee9278df5176d7a7

Contents?: true

Size: 823 Bytes

Versions: 17

Compression:

Stored size: 823 Bytes

Contents

require "active_support/concern"
require "active_support/core_ext/object/blank"

module ActiveRemote
  # QueryAttributes provides instance methods for querying attributes.
  #
  # @example Usage
  #   class Person < ::ActiveRemote::Base
  #     attribute :name
  #   end
  #
  #   person = Person.new
  #   person.name? #=> false
  #   person.name = "Chris Griego"
  #   person.name? #=> true
  #
  module QueryAttributes
    extend ::ActiveSupport::Concern

    included do
      attribute_method_suffix "?"
    end

    def query_attribute(attr_name)
      value = self[attr_name]

      case value
      when true        then true
      when false, nil  then false
      else
        value.present?
      end
    end

  private

    def attribute?(attribute_name)
      query_attribute(attribute_name)
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
active_remote-6.0.3 lib/active_remote/query_attributes.rb
active_remote-6.1.2 lib/active_remote/query_attributes.rb
active_remote-7.0.0 lib/active_remote/query_attributes.rb
active_remote-6.1.1 lib/active_remote/query_attributes.rb
active_remote-6.1.0 lib/active_remote/query_attributes.rb
active_remote-6.0.2 lib/active_remote/query_attributes.rb
active_remote-6.0.1 lib/active_remote/query_attributes.rb
active_remote-6.0.0.beta lib/active_remote/query_attributes.rb
active_remote-5.2.0 lib/active_remote/query_attributes.rb
active_remote-5.2.0.beta lib/active_remote/query_attributes.rb
active_remote-5.2.0.alpha lib/active_remote/query_attributes.rb
active_remote-5.0.1 lib/active_remote/query_attributes.rb
active_remote-5.1.1 lib/active_remote/query_attributes.rb
active_remote-5.1.0 lib/active_remote/query_attributes.rb
active_remote-5.0.0 lib/active_remote/query_attributes.rb
active_remote-5.1.0.rc1 lib/active_remote/query_attributes.rb
active_remote-5.0.0.rc1 lib/active_remote/query_attributes.rb