module CFoundry::V2::ModelMagic

Attributes

scoped_organization[R]
scoped_space[R]

Public Class Methods

params_from(args) click to toggle source

To query a single attribute using equality, you can use :query => [“attribute”, “value”]

To query multiple attributes, you can specify a hash of attributes to values, where the values can be:

A single value with equality
  :query => {attr1: 'value1', attr2: 'value2'}
Multiple values for an attribute
  :query => {attr1: ['value1', 'value2']}
Complex comparisons i.e ('<', '>', '<=', '>=')
  :query => {attr1: QueryValue.new(comparator: '>', value: 'VALUE')}

QueryValue can be found in CFoundry::V2::ModelMagic::QueryValueHelper You can include this module in your class to access QueryValue directly priting is handled by to_s

# File lib/cfoundry/v2/model_magic.rb, line 92
def self.params_from(args)
  options, _ = args
  options ||= {}
  options[:depth] ||= 1

  params = {}
  options.each do |k, v|
    case k
    when :depth
      params[:"inline-relations-depth"] = v
    when :query
      if v.is_a? Array
        params[:q] = v.join(":")
      else
        params[:q] = query_from_hash(v)
      end
    when :user_provided
      params[:"return_user_provided_service_instances"] = v
    else
      params[k] = v
    end
  end

  params
end
query_from_hash(query_params) click to toggle source
# File lib/cfoundry/v2/model_magic.rb, line 118
def self.query_from_hash(query_params)
  query_params.collect do |key, value|
    case value
      when Array
        qv = QueryValue.new(:comp => 'IN', :value => value)
        "#{key}#{qv}"
      when QueryValue
        "#{key}#{value}"
      when QueryMultiValue
        value.collect_values(key)
      else
        "#{key}:#{value}"
    end
  end.join(";")
end

Public Instance Methods

attributes() click to toggle source
# File lib/cfoundry/v2/model_magic.rb, line 51
def attributes
  @attributes ||= {}
end
defaults() click to toggle source
# File lib/cfoundry/v2/model_magic.rb, line 47
def defaults
  @defaults ||= {}
end
inherited(klass) click to toggle source
# File lib/cfoundry/v2/model_magic.rb, line 63
def inherited(klass)
  add_client_methods(klass)
  has_summary
end
object_name() click to toggle source
# File lib/cfoundry/v2/model_magic.rb, line 36
def object_name
  @object_name ||=
    name.split("::").last.gsub(
      /([a-z])([A-Z])/,
      '\1_\2').downcase.to_sym
end
plural_object_name() click to toggle source
# File lib/cfoundry/v2/model_magic.rb, line 43
def plural_object_name
  :"#{object_name}s"
end
scoped_to_organization(relation = :organization) click to toggle source
# File lib/cfoundry/v2/model_magic.rb, line 68
def scoped_to_organization(relation = :organization)
  @scoped_organization = relation
end
scoped_to_space(relation = :space) click to toggle source
# File lib/cfoundry/v2/model_magic.rb, line 72
def scoped_to_space(relation = :space)
  @scoped_space = relation
end
to_many_relations() click to toggle source
# File lib/cfoundry/v2/model_magic.rb, line 59
def to_many_relations
  @to_many_relations ||= {}
end
to_one_relations() click to toggle source
# File lib/cfoundry/v2/model_magic.rb, line 55
def to_one_relations
  @to_one_relations ||= {}
end