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.



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

def initialize
  clear
end

Instance Attribute Details

#display_nameObject

Returns the value of attribute display_name.



32
33
34
# File 'lib/comet/models/stored_object.rb', line 32

def display_name
  @display_name
end

#end_timeObject

Returns the value of attribute end_time.



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

def end_time
  @end_time
end

#fromObject

Returns the value of attribute from.



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

def from
  @from
end

#has_attachmentsObject

Returns the value of attribute has_attachments.



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

def has_attachments
  @has_attachments
end

#item_classObject

Returns the value of attribute item_class.



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

def item_class
  @item_class
end

#modify_timeObject

Returns the value of attribute modify_time.



19
20
21
# File 'lib/comet/models/stored_object.rb', line 19

def modify_time
  @modify_time
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#received_date_timeObject

Returns the value of attribute received_date_time.



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

def received_date_time
  @received_date_time
end

#recursive_bytesObject

Returns the value of attribute recursive_bytes.



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

def recursive_bytes
  @recursive_bytes
end

#recursive_count_knownObject

Returns the value of attribute recursive_count_known.



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

def recursive_count_known
  @recursive_count_known
end

#recursive_filesObject

Returns the value of attribute recursive_files.



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

def recursive_files
  @recursive_files
end

#recursive_foldersObject

Returns the value of attribute recursive_folders.



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

def recursive_folders
  @recursive_folders
end

#sizeObject

Returns the value of attribute size.



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

def size
  @size
end

#start_timeObject

Returns the value of attribute start_time.



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

def start_time
  @start_time
end

#subtreeObject

Returns the value of attribute subtree.



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

def subtree
  @subtree
end

#toObject

Returns the value of attribute to.



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

def to
  @to
end

#typeObject

One of the STOREDOBJECTTYPE_… constant values



23
24
25
# File 'lib/comet/models/stored_object.rb', line 23

def type
  @type
end

#unknown_json_fieldsObject

Returns the value of attribute unknown_json_fields.



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

def unknown_json_fields
  @unknown_json_fields
end

Instance Method Details

#clearObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/comet/models/stored_object.rb', line 74

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)


101
102
103
104
105
106
107
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
# File 'lib/comet/models/stored_object.rb', line 101

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)


94
95
96
97
98
# File 'lib/comet/models/stored_object.rb', line 94

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



227
228
229
# File 'lib/comet/models/stored_object.rb', line 227

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



177
178
179
180
181
182
183
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
# File 'lib/comet/models/stored_object.rb', line 177

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



232
233
234
# File 'lib/comet/models/stored_object.rb', line 232

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