Sha256: e111ded524682cb2f1f0fb09f0b1c53a80fe9fa0aa25c78abe81043d2ee627fb

Contents?: true

Size: 896 Bytes

Versions: 78

Compression:

Stored size: 896 Bytes

Contents

module CFoundry::V2
  module ModelMagic::QueryableBy
    def queryable_by(*names)
      klass = self
      singular = object_name
      plural = plural_object_name

      query = ::CFoundry::V2::QUERIES[singular]

      query.module_eval do
        names.each do |name|
          #
          # def MODEL_by_ATTRIBUTE
          #
          define_method(:"#{singular}_by_#{name}") do |*args|
            send(:"#{plural}_by_#{name}", *args).first
          end

          #
          # def MODELs_by_ATTRIBUTE
          #
          define_method(:"#{plural}_by_#{name}") do |val, *args|
            options, _ = args
            options ||= {}
            options[:query] = [name, val]

            query_target(klass).send(plural, options)
          end
        end
      end

      const_set(:Queries, query)

      ClientMethods.module_eval do
        include query
      end
    end
  end
end

Version data entries

78 entries across 78 versions & 3 rubygems

Version Path
new_cfoundry-4.9.4 lib/cfoundry/v2/model_magic/queryable_by.rb
new_cfoundry-4.9.3 lib/cfoundry/v2/model_magic/queryable_by.rb
ncfoundry-4.9.4 lib/cfoundry/v2/model_magic/queryable_by.rb
ncfoundry-4.9.3 lib/cfoundry/v2/model_magic/queryable_by.rb
ncfoundry-4.9.2 lib/cfoundry/v2/model_magic/queryable_by.rb
new_cfoundry-4.9.2 lib/cfoundry/v2/model_magic/queryable_by.rb
new_cfoundry-4.9.1 lib/cfoundry/v2/model_magic/queryable_by.rb
new_cfoundry-4.9.0 lib/cfoundry/v2/model_magic/queryable_by.rb
new_cfoundry-4.8.3 lib/cfoundry/v2/model_magic/queryable_by.rb
new_cfoundry-4.8.2 lib/cfoundry/v2/model_magic/queryable_by.rb
cfoundry-4.7.2.rc1 lib/cfoundry/v2/model_magic/queryable_by.rb
cfoundry-4.7.1 lib/cfoundry/v2/model_magic/queryable_by.rb
cfoundry-4.7.1.rc1 lib/cfoundry/v2/model_magic/queryable_by.rb
cfoundry-4.7.0 lib/cfoundry/v2/model_magic/queryable_by.rb
cfoundry-4.6.3.rc3 lib/cfoundry/v2/model_magic/queryable_by.rb
cfoundry-4.6.3.rc2 lib/cfoundry/v2/model_magic/queryable_by.rb
cfoundry-4.6.3.rc1 lib/cfoundry/v2/model_magic/queryable_by.rb
cfoundry-4.6.2 lib/cfoundry/v2/model_magic/queryable_by.rb
cfoundry-4.6.1 lib/cfoundry/v2/model_magic/queryable_by.rb
cfoundry-4.6.0 lib/cfoundry/v2/model_magic/queryable_by.rb