Class: Tumugi::Plugin::GoogleDriveFolderTarget

Inherits:
Target
  • Object
show all
Defined in:
lib/tumugi/plugin/target/google_drive_folder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(folder_id: nil, name:, parents: nil, fs: nil) ⇒ GoogleDriveFolderTarget

Returns a new instance of GoogleDriveFolderTarget.



12
13
14
15
16
17
# File 'lib/tumugi/plugin/target/google_drive_folder.rb', line 12

def initialize(folder_id: nil, name:, parents: nil, fs: nil)
  @fs = fs unless fs.nil?
  @folder_id = folder_id
  @name = name
  @parents = parents
end

Instance Attribute Details

#folder_idObject (readonly)

Returns the value of attribute folder_id.



10
11
12
# File 'lib/tumugi/plugin/target/google_drive_folder.rb', line 10

def folder_id
  @folder_id
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/tumugi/plugin/target/google_drive_folder.rb', line 10

def name
  @name
end

#parentsObject (readonly)

Returns the value of attribute parents.



10
11
12
# File 'lib/tumugi/plugin/target/google_drive_folder.rb', line 10

def parents
  @parents
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/tumugi/plugin/target/google_drive_folder.rb', line 23

def exist?
  if folder_id
    fs.exist?(folder_id)
  else
    !find_by_name(name).nil?
  end
end

#fsObject



19
20
21
# File 'lib/tumugi/plugin/target/google_drive_folder.rb', line 19

def fs
  @fs ||= Tumugi::Plugin::GoogleDrive::FileSystem.new(Tumugi.config.section('google_drive'))
end

#mkdirObject



31
32
33
34
35
# File 'lib/tumugi/plugin/target/google_drive_folder.rb', line 31

def mkdir
  fid = folder_id || fs.generate_file_id
  fs.mkdir(name, folder_id: fid, parents: parents)
  @folder_id = fid
end

#to_sObject



37
38
39
40
41
# File 'lib/tumugi/plugin/target/google_drive_folder.rb', line 37

def to_s
  s = "folder_id: #{folder_id}, name: #{name}"
  s += ", parents: #{parents}" if parents
  s
end

#urlObject



43
44
45
46
47
# File 'lib/tumugi/plugin/target/google_drive_folder.rb', line 43

def url
  return nil if folder_id.nil?
  folder = fs.(folder_id)
  folder.web_view_link
end