Class: Comet::StoredObject

Inherits:
Object
  • Object
show all
Defined in:
lib/comet/models/stored_object.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStoredObject

Returns a new instance of StoredObject.



77
78
79
# File 'lib/comet/models/stored_object.rb', line 77

def initialize
  clear
end

Instance Attribute Details

#display_nameObject

Returns the value of attribute display_name.



37
38
39
# File 'lib/comet/models/stored_object.rb', line 37

def display_name
  @display_name
end

#end_timeObject

Unix timestamp in seconds



60
61
62
# File 'lib/comet/models/stored_object.rb', line 60

def end_time
  @end_time
end

#fromObject

Returns the value of attribute from.



43
44
45
# File 'lib/comet/models/stored_object.rb', line 43

def from
  @from
end

#has_attachmentsObject

Returns the value of attribute has_attachments.



52
53
54
# File 'lib/comet/models/stored_object.rb', line 52

def has_attachments
  @has_attachments
end

#item_classObject

Returns the value of attribute item_class.



40
41
42
# File 'lib/comet/models/stored_object.rb', line 40

def item_class
  @item_class
end

#modify_timeObject

Unix timestamp in seconds



21
22
23
# File 'lib/comet/models/stored_object.rb', line 21

def modify_time
  @modify_time
end

#nameObject

The name of the stored object. It is unique within this directory tree.



17
18
19
# File 'lib/comet/models/stored_object.rb', line 17

def name
  @name
end

#received_date_timeObject

Returns the value of attribute received_date_time.



49
50
51
# File 'lib/comet/models/stored_object.rb', line 49

def received_date_time
  @received_date_time
end

#recursive_bytesObject

Returns the value of attribute recursive_bytes.



69
70
71
# File 'lib/comet/models/stored_object.rb', line 69

def recursive_bytes
  @recursive_bytes
end

#recursive_count_knownObject

Returns the value of attribute recursive_count_known.



63
64
65
# File 'lib/comet/models/stored_object.rb', line 63

def recursive_count_known
  @recursive_count_known
end

#recursive_filesObject

Returns the value of attribute recursive_files.



66
67
68
# File 'lib/comet/models/stored_object.rb', line 66

def recursive_files
  @recursive_files
end

#recursive_foldersObject

Returns the value of attribute recursive_folders.



72
73
74
# File 'lib/comet/models/stored_object.rb', line 72

def recursive_folders
  @recursive_folders
end

#sizeObject

Bytes



34
35
36
# File 'lib/comet/models/stored_object.rb', line 34

def size
  @size
end

#start_timeObject

Unix timestamp in seconds



56
57
58
# File 'lib/comet/models/stored_object.rb', line 56

def start_time
  @start_time
end

#subtreeObject

If this StoredObject represents a directory, this value can be used to recursively select the directory contents.



30
31
32
# File 'lib/comet/models/stored_object.rb', line 30

def subtree
  @subtree
end

#toObject

Returns the value of attribute to.



46
47
48
# File 'lib/comet/models/stored_object.rb', line 46

def to
  @to
end

#typeObject

One of the STOREDOBJECTTYPE_… constant values



25
26
27
# File 'lib/comet/models/stored_object.rb', line 25

def type
  @type
end

#unknown_json_fieldsObject

Returns the value of attribute unknown_json_fields.



75
76
77
# File 'lib/comet/models/stored_object.rb', line 75

def unknown_json_fields
  @unknown_json_fields
end

Instance Method Details

#clearObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/comet/models/stored_object.rb', line 81

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) ⇒ Object

Parameters:

  • obj (Hash)

    The complete object as a Ruby hash

Raises:

  • (TypeError)


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/comet/models/stored_object.rb', line 108

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) ⇒ Object

Parameters:

  • json_string (String)

    The complete object in JSON format

Raises:

  • (TypeError)


101
102
103
104
105
# File 'lib/comet/models/stored_object.rb', line 101

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_hHash

Returns The complete object as a Ruby hash.

Returns:

  • (Hash)

    The complete object as a Ruby hash



234
235
236
# File 'lib/comet/models/stored_object.rb', line 234

def to_h
  to_hash
end

#to_hashHash

Returns The complete object as a Ruby hash.

Returns:

  • (Hash)

    The complete object as a Ruby hash



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/comet/models/stored_object.rb', line 184

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 = {}) ⇒ String

Returns The complete object as a JSON string.

Returns:

  • (String)

    The complete object as a JSON string



239
240
241
# File 'lib/comet/models/stored_object.rb', line 239

def to_json(options = {})
  to_hash.to_json(options)
end