class Comet::StoredObject

StoredObject is a typed class wrapper around the underlying Comet Server API data structure.

Attributes

display_name[RW]

@type [String] display_name

end_time[RW]

@type [Number] end_time

from[RW]

@type [String] from

has_attachments[RW]

@type [Boolean] has_attachments

item_class[RW]

@type [String] item_class

modify_time[RW]

@type [Number] modify_time

name[RW]

@type [String] name

received_date_time[RW]

@type [Number] received_date_time

recursive_bytes[RW]

@type [Number] recursive_bytes

recursive_count_known[RW]

@type [Boolean] recursive_count_known

recursive_files[RW]

@type [Number] recursive_files

recursive_folders[RW]

@type [Number] recursive_folders

size[RW]

@type [Number] size

start_time[RW]

@type [Number] start_time

subtree[RW]

@type [String] subtree

to[RW]

@type [String] to

type[RW]

@type [String] type

unknown_json_fields[RW]

@type [Hash] Hidden storage to preserve future properties for non-destructive roundtrip operations

Public Class Methods

new() click to toggle source
# File lib/comet/models/stored_object.rb, line 71
def initialize
  clear
end

Public Instance Methods

clear() click to toggle source
# File lib/comet/models/stored_object.rb, line 75
def clear
  @name = ''
  @modify_time = 0
  @type = ''
  @subtree = ''
  @size = 0
  @display_name = ''
  @item_class = ''
  @from = ''
  @to = ''
  @received_date_time = 0
  @start_time = 0
  @end_time = 0
  @recursive_files = 0
  @recursive_bytes = 0
  @recursive_folders = 0
  @unknown_json_fields = {}
end
from_hash(obj) click to toggle source

@param [Hash] obj The complete object as a Ruby hash

# File lib/comet/models/stored_object.rb, line 102
def from_hash(obj)
  raise TypeError, "'obj' expected Hash, got #{obj.class}" unless obj.is_a? Hash

  obj.each do |k, v|
    case k
    when 'name'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @name = v
    when 'mtime'
      raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric

      @modify_time = v
    when 'type'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @type = v
    when 'subtree'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @subtree = v
    when 'size'
      raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric

      @size = v
    when 'dname'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @display_name = v
    when 'itemClass'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @item_class = v
    when 'from'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @from = v
    when 'to'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @to = v
    when 'rtime'
      raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric

      @received_date_time = v
    when 'has_attachments'
      @has_attachments = v
    when 'stime'
      raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric

      @start_time = v
    when 'etime'
      raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric

      @end_time = v
    when 'r'
      @recursive_count_known = v
    when 'f'
      raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric

      @recursive_files = v
    when 'b'
      raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric

      @recursive_bytes = v
    when 'd'
      raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric

      @recursive_folders = v
    else
      @unknown_json_fields[k] = v
    end
  end
end
from_json(json_string) click to toggle source

@param [String] json_string The complete object in JSON format

# File lib/comet/models/stored_object.rb, line 95
def from_json(json_string)
  raise TypeError, "'json_string' expected String, got #{json_string.class}" unless json_string.is_a? String

  from_hash(JSON.parse(json_string))
end
to_h() click to toggle source

@return [Hash] The complete object as a Ruby hash

# File lib/comet/models/stored_object.rb, line 228
def to_h
  to_hash
end
to_hash() click to toggle source

@return [Hash] The complete object as a Ruby hash

# File lib/comet/models/stored_object.rb, line 178
def to_hash
  ret = {}
  ret['name'] = @name
  ret['mtime'] = @modify_time
  ret['type'] = @type
  ret['subtree'] = @subtree
  ret['size'] = @size
  unless @display_name.nil?
    ret['dname'] = @display_name
  end
  unless @item_class.nil?
    ret['itemClass'] = @item_class
  end
  unless @from.nil?
    ret['from'] = @from
  end
  unless @to.nil?
    ret['to'] = @to
  end
  unless @received_date_time.nil?
    ret['rtime'] = @received_date_time
  end
  unless @has_attachments.nil?
    ret['has_attachments'] = @has_attachments
  end
  unless @start_time.nil?
    ret['stime'] = @start_time
  end
  unless @end_time.nil?
    ret['etime'] = @end_time
  end
  unless @recursive_count_known.nil?
    ret['r'] = @recursive_count_known
  end
  unless @recursive_files.nil?
    ret['f'] = @recursive_files
  end
  unless @recursive_bytes.nil?
    ret['b'] = @recursive_bytes
  end
  unless @recursive_folders.nil?
    ret['d'] = @recursive_folders
  end
  @unknown_json_fields.each do |k, v|
    ret[k] = v
  end
  ret
end
to_json(options = {}) click to toggle source

@return [String] The complete object as a JSON string

# File lib/comet/models/stored_object.rb, line 233
def to_json(options = {})
  to_hash.to_json(options)
end