class Saklient::Cloud::Models::Model

@private

Attributes

_client[RW]

@private @return [Saklient::Cloud::Client]

_count[RW]

@private @return [Fixnum]

_query[RW]

@private @return [QueryParams]

_total[RW]

@private @return [Fixnum]

client[R]

@return [Saklient::Cloud::Client]

count[R]

@return [Fixnum]

query[R]

@return [QueryParams]

total[R]

@return [Fixnum]

Public Class Methods

new(client) click to toggle source

@param [Saklient::Cloud::Client] client

# File lib/saklient/cloud/models/model.rb, line 129
def initialize(client)
  Saklient::Util::validate_type(client, 'Saklient::Cloud::Client')
  @_client = client
  _reset
end

Protected Instance Methods

_api_path() click to toggle source

@private @return [String]

# File lib/saklient/cloud/models/model.rb, line 104
def _api_path
  return nil
end
_class_name() click to toggle source

@private @return [String]

# File lib/saklient/cloud/models/model.rb, line 122
def _class_name
  return nil
end
_create() click to toggle source

新規リソース作成用のオブジェクトを用意します.

返り値のオブジェクトにパラメータを設定し, save() を呼ぶことで実際のリソースが作成されます.

@private @return [Saklient::Cloud::Resources::Resource] リソースオブジェクト

# File lib/saklient/cloud/models/model.rb, line 221
def _create
  return _create_resource_impl(nil)
end
_create_resource_impl(obj, wrapped = false) click to toggle source

@private @param [any] obj @param [bool] wrapped @return [Saklient::Cloud::Resources::Resource]

# File lib/saklient/cloud/models/model.rb, line 210
def _create_resource_impl(obj, wrapped = false)
  Saklient::Util::validate_type(wrapped, 'bool')
  return nil
end
_filter_by(key, value, multiple = false) click to toggle source

Web APIのフィルタリング設定を直接指定します.

@private @param [String] key キー @param [any] value 値 @param [bool] multiple valueに配列を与え, OR条件で完全一致検索する場合にtrueを指定します. 通常, valueはスカラ値であいまい検索されます. @return [Model]

# File lib/saklient/cloud/models/model.rb, line 180
def _filter_by(key, value, multiple = false)
  Saklient::Util::validate_type(key, 'String')
  Saklient::Util::validate_type(multiple, 'bool')
  filter = @_query.filter
  if multiple
    filter[key.to_sym] = [] if !(!filter.nil? && filter.key?(key.to_sym))
    values = filter[key.to_sym]
    values << value
  else
    raise Saklient::Errors::SaklientException.new('filter_duplicated', 'The same filter key can be specified only once (by calling the same method \'withFooBar\')') if !filter.nil? && filter.key?(key.to_sym)
    filter[key.to_sym] = value
  end
  return self
end
_find() click to toggle source

リソースの検索リクエストを実行し, 結果をリストで取得します.

@private @return [Array<Saklient::Cloud::Resources::Resource>] リソースオブジェクトの配列

# File lib/saklient/cloud/models/model.rb, line 244
def _find
  query = @_query.build
  _reset
  result = @_client.request('GET', _api_path, query)
  @_total = result[:Total]
  @_count = result[:Count]
  data = []
  records = result[_root_key_m.to_sym]
  for record in records
    data << _create_resource_impl(record)
  end
  return data
end
_find_one() click to toggle source

リソースの検索リクエストを実行し, 唯一のリソースを取得します.

@private @return [Saklient::Cloud::Resources::Resource] リソースオブジェクト

# File lib/saklient/cloud/models/model.rb, line 262
def _find_one
  query = @_query.build
  _reset
  result = @_client.request('GET', _api_path, query)
  @_total = result[:Total]
  @_count = result[:Count]
  return nil if @_total == 0
  records = result[_root_key_m.to_sym]
  return _create_resource_impl(records[0])
end
_get_by_id(id) click to toggle source

指定したIDを持つ唯一のリソースを取得します.

@private @param [String] id @return [Saklient::Cloud::Resources::Resource] リソースオブジェクト

# File lib/saklient/cloud/models/model.rb, line 230
def _get_by_id(id)
  Saklient::Util::validate_type(id, 'String')
  query = @_query.build
  _reset
  result = @_client.request('GET', _api_path + '/' + Saklient::Util::url_encode(id), query)
  @_total = 1
  @_count = 1
  return _create_resource_impl(result, true)
end
_limit(count) click to toggle source

次に取得するリストの上限レコード数を指定します.

@private @param [Fixnum] count 上限レコード数 @return [Model] this

# File lib/saklient/cloud/models/model.rb, line 153
def _limit(count)
  Saklient::Util::validate_type(count, 'Fixnum')
  @_query.count = count
  return self
end
_offset(offset) click to toggle source

次に取得するリストの開始オフセットを指定します.

@private @param [Fixnum] offset オフセット @return [Model] this

# File lib/saklient/cloud/models/model.rb, line 142
def _offset(offset)
  Saklient::Util::validate_type(offset, 'Fixnum')
  @_query.begin = offset
  return self
end
_reset() click to toggle source

次のリクエストのために設定されているステートをすべて破棄します.

@private @return [Model] this

# File lib/saklient/cloud/models/model.rb, line 199
def _reset
  @_query = Saklient::Cloud::Models::QueryParams.new()
  @_total = 0
  @_count = 0
  return self
end
_root_key() click to toggle source

@private @return [String]

# File lib/saklient/cloud/models/model.rb, line 110
def _root_key
  return nil
end
_root_key_m() click to toggle source

@private @return [String]

# File lib/saklient/cloud/models/model.rb, line 116
def _root_key_m
  return nil
end
_sort(column, reverse = false) click to toggle source

次に取得するリストのソートカラムを指定します.

@private @param [String] column カラム名 @param [bool] reverse @return [Model] this

# File lib/saklient/cloud/models/model.rb, line 165
def _sort(column, reverse = false)
  Saklient::Util::validate_type(column, 'String')
  Saklient::Util::validate_type(reverse, 'bool')
  op = reverse ? '-' : ''
  @_query.sort << op + column
  return self
end
_sort_by_name(reverse = false) click to toggle source

名前でソートします.

@private @todo Implement test case @param [bool] reverse @return [Model]

# File lib/saklient/cloud/models/model.rb, line 328
def _sort_by_name(reverse = false)
  Saklient::Util::validate_type(reverse, 'bool')
  return _sort('Name', reverse)
end
_with_name_like(name) click to toggle source

指定した文字列を名前に含むリソースに絞り込みます.

大文字・小文字は区別されません. 半角スペースで区切られた複数の文字列は, それらをすべて含むことが条件とみなされます.

@private @todo Implement test case @param [String] name @return [Model]

# File lib/saklient/cloud/models/model.rb, line 282
def _with_name_like(name)
  Saklient::Util::validate_type(name, 'String')
  return _filter_by('Name', name)
end
_with_tag(tag) click to toggle source

指定したタグを持つリソースに絞り込みます.

複数のタグを指定する場合は withTags() を利用してください.

@private @todo Implement test case @param [String] tag @return [Model]

# File lib/saklient/cloud/models/model.rb, line 295
def _with_tag(tag)
  Saklient::Util::validate_type(tag, 'String')
  return _filter_by('Tags.Name', [tag])
end
_with_tag_dnf(dnf) click to toggle source

指定したDNFに合致するタグを持つリソースに絞り込みます.

@private @todo Implement test case @param [Array<Array<String>>] dnf @return [Model]

# File lib/saklient/cloud/models/model.rb, line 317
def _with_tag_dnf(dnf)
  Saklient::Util::validate_type(dnf, 'Array')
  return _filter_by('Tags.Name', dnf)
end
_with_tags(tags) click to toggle source

指定したすべてのタグを持つリソースに絞り込みます.

@private @todo Implement test case @param [Array<String>] tags @return [Model]

# File lib/saklient/cloud/models/model.rb, line 306
def _with_tags(tags)
  Saklient::Util::validate_type(tags, 'Array')
  return _filter_by('Tags.Name', [tags])
end
get_client() click to toggle source

@private @return [Saklient::Cloud::Client]

# File lib/saklient/cloud/models/model.rb, line 24
def get_client
  return @_client
end
get_count() click to toggle source

@private @return [Fixnum]

# File lib/saklient/cloud/models/model.rb, line 87
def get_count
  return @_count
end
get_query() click to toggle source

@private @return [QueryParams]

# File lib/saklient/cloud/models/model.rb, line 45
def get_query
  return @_query
end
get_total() click to toggle source

@private @return [Fixnum]

# File lib/saklient/cloud/models/model.rb, line 66
def get_total
  return @_total
end