Class: SharepointApi::FileInfo
- Inherits:
-
Object
- Object
- SharepointApi::FileInfo
- Extended by:
- Forwardable
- Defined in:
- lib/sharepoint_api/file_info.rb
Defined Under Namespace
Classes: FileInfoError
Constant Summary collapse
- FILE_SELECT_QUERY_WITH_VERSIONS =
Get all data required to build a FileInfo object without subsequent API calls.
begin sub_query = %w[ ModifiedBy/Email ModifiedBy/LoginName ListItemAllFields/Id Versions/Id Versions/Created Versions/IsCurrentVersion Versions/CreatedBy/Email Versions/CreatedBy/LoginName Versions/Url ].join(',') "$select=Name,UpdatedAt,MajorVersion,TimeLastModified,#{sub_query}&$expand=#{sub_query}" end.freeze
- FILE_SELECT_QUERY =
Get just enough data to build a FileInfo object that suports to_h
begin sub_query = %w[ ModifiedBy/LoginName ListItemAllFields/Id ].join(',') "$select=Name,UpdatedAt,MajorVersion,TimeLastModified,Versions,#{sub_query}&$expand=#{sub_query}" end.freeze
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
-
#version_id ⇒ Object
readonly
Returns the value of attribute version_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file) ⇒ FileInfo
constructor
A new instance of FileInfo.
- #list_item_id ⇒ Object
- #to_h ⇒ Object
- #versions ⇒ Object
Constructor Details
#initialize(file) ⇒ FileInfo
46 47 48 49 50 51 |
# File 'lib/sharepoint_api/file_info.rb', line 46 def initialize(file) @version = file.major_version @version_id = SharepointApi::VersionConverter.to_ui(file.major_version) @updated_at = Time.parse(file.time_last_modified) @file = file end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
36 37 38 |
# File 'lib/sharepoint_api/file_info.rb', line 36 def file @file end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
36 37 38 |
# File 'lib/sharepoint_api/file_info.rb', line 36 def updated_at @updated_at end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
36 37 38 |
# File 'lib/sharepoint_api/file_info.rb', line 36 def version @version end |
#version_id ⇒ Object (readonly)
Returns the value of attribute version_id.
36 37 38 |
# File 'lib/sharepoint_api/file_info.rb', line 36 def version_id @version_id end |
Class Method Details
.wrap(sharepoint_file) ⇒ Object
40 41 42 43 44 |
# File 'lib/sharepoint_api/file_info.rb', line 40 def self.wrap(sharepoint_file) return nil unless sharepoint_file new(sharepoint_file) end |
Instance Method Details
#list_item_id ⇒ Object
53 54 55 |
# File 'lib/sharepoint_api/file_info.rb', line 53 def list_item_id @list_item_id ||= file.list_item_all_fields.id end |
#to_h ⇒ Object
87 88 89 |
# File 'lib/sharepoint_api/file_info.rb', line 87 def to_h { version: version, version_id: version_id, name: name, list_item_id: list_item_id } end |
#versions ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/sharepoint_api/file_info.rb', line 57 def versions return @all_versions if @all_versions @all_versions = [] modified_by = safe_modified_by(file) @all_versions << make_version_object( version_id, created_at: updated_at, current: true, creator_login: modified_by.try(:login_name), creator_email: modified_by.try(:email) ) return @all_versions unless version > 1 @all_versions += file.versions.map do |file_version| created_by = safe_created_by(file_version) make_version_object( file_version.id, created_at: Time.parse(file_version.created), current: file_version.is_current_version, creator_login: created_by.try(:login_name), creator_email: created_by.try(:email) ) end @all_versions = @all_versions.sort_by(&:number) end |