Sha256: 6d3197b6086a1dc535e90f69cc61c21c782afd9e5e984f3ae340ea521097adb4

Contents?: true

Size: 1.02 KB

Versions: 15

Compression:

Stored size: 1.02 KB

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

    # Test the presence of an attribute
    #
    # See {Typecasting::BooleanTypecaster.call} for more details.
    #
    # @example Query an attribute
    #   person.query_attribute(:name)
    #
    def query_attribute(name)
      if respond_to?("#{name}?")
        send("#{name}?")
      else
        raise ::ActiveRemote::UnknownAttributeError, "unknown attribute: #{name}"
      end
    end

  private

    def attribute?(name)
      ::ActiveRemote::Typecasting::BooleanTypecaster.call(read_attribute(name))
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
active_remote-3.3.3 lib/active_remote/query_attributes.rb
active_remote-3.3.2 lib/active_remote/query_attributes.rb
active_remote-3.3.1 lib/active_remote/query_attributes.rb
active_remote-3.3.0 lib/active_remote/query_attributes.rb
active_remote-3.2.2 lib/active_remote/query_attributes.rb
active_remote-3.2.1 lib/active_remote/query_attributes.rb
active_remote-3.2.0 lib/active_remote/query_attributes.rb
active_remote-3.2.0.pre lib/active_remote/query_attributes.rb
active_remote-3.1.3 lib/active_remote/query_attributes.rb
active_remote-3.1.2 lib/active_remote/query_attributes.rb
active_remote-3.1.2.pre lib/active_remote/query_attributes.rb
active_remote-3.1.1 lib/active_remote/query_attributes.rb
active_remote-3.1.0 lib/active_remote/query_attributes.rb
active_remote-3.0.0 lib/active_remote/query_attributes.rb
active_remote-3.0.0.pre1 lib/active_remote/query_attributes.rb