Class: DropboxApi::Metadata::Base
- Inherits:
-
Object
- Object
- DropboxApi::Metadata::Base
- Defined in:
- lib/dropbox_api/metadata/base.rb
Direct Known Subclasses
AddFileMemberResult, AddMember, BasicAccount, Deleted, File, FileLink, FileMemberAction, Folder, FolderLink, FolderSharingInfo, LinkPermissions, Member, MemberPermission, Name, ParentFolderAccessInfo, SharedFolder, SharedFolderPolicy, SpaceAllocation, SpaceUsage, Symbol, Team, TeamMemberInfo, WriteMode
Class Attribute Summary collapse
-
.fields ⇒ Object
readonly
Returns the value of attribute fields.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(metadata) ⇒ Base
constructor
Takes in a hash containing all the attributes required to initialize the object.
- #serialized_field(field_name) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(metadata) ⇒ Base
Takes in a hash containing all the attributes required to initialize the object.
Each hash entry should have a key which identifies a field and its value, so a valid call would be something like this:
DropboxApi::Metadata::File.new({
"name" => "a.jpg",
"path_lower" => "/a.jpg",
"path_display" => "/a.jpg",
"id" => "id:evvfE6q6cK0AAAAAAAAB2w",
"client_modified" => "2016-10-19T17:17:34Z",
"server_modified" => "2016-10-19T17:17:34Z",
"rev" => "28924061bdd",
"size" => 396317
})
33 34 35 36 37 |
# File 'lib/dropbox_api/metadata/base.rb', line 33 def initialize() self.class.fields.keys.each do |field_name| self[field_name] = [field_name.to_s] end end |
Class Attribute Details
.fields ⇒ Object (readonly)
Returns the value of attribute fields.
4 5 6 |
# File 'lib/dropbox_api/metadata/base.rb', line 4 def fields @fields end |
Class Method Details
.field(name, type, *options) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/dropbox_api/metadata/base.rb', line 6 def field(name, type, *) @fields ||= {} @fields[name] = DropboxApi::Metadata::Field.new(type, ) attr_reader name end |
Instance Method Details
#serialized_field(field_name) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dropbox_api/metadata/base.rb', line 45 def serialized_field(field_name) value = send field_name case value when Time value.utc.strftime("%FT%TZ") when DropboxApi::Metadata::Base value.to_hash else value end end |
#to_hash ⇒ Object
39 40 41 42 43 |
# File 'lib/dropbox_api/metadata/base.rb', line 39 def to_hash Hash[self.class.fields.keys.map do |field_name| [field_name.to_s, serialized_field(field_name)] end.select { |k, v| !v.nil? }] end |