Module: Gzr::Folder
- Included in:
- Commands::Folder::Cat, Commands::Folder::Create, Commands::Folder::Export, Commands::Folder::Ls, Commands::Folder::Rm, Commands::Folder::Top, Commands::Folder::Tree
- Defined in:
- lib/gzr/modules/folder.rb
Class Method Summary collapse
Instance Method Summary collapse
- #all_folders(fields = nil) ⇒ Object
- #create_folder(name, parent_id) ⇒ Object
- #delete_folder(folder_id) ⇒ Object
- #process_args(args) ⇒ Object
- #query_folder(id, fields = nil) ⇒ Object
- #query_folder_children(folder_id, fields = nil) ⇒ Object
- #search_folders(name, fields = nil) ⇒ Object
Class Method Details
Instance Method Details
#all_folders(fields = nil) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/gzr/modules/folder.rb', line 112 def all_folders(fields=nil) begin req = {} req[:fields] = fields if fields @sdk.all_folders(req).collect { |e| e.to_attrs } rescue LookerSDK::Error => e say_error "Error querying all_folders(#{JSON.pretty_generate(req)})" say_error e raise end end |
#create_folder(name, parent_id) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gzr/modules/folder.rb', line 33 def create_folder(name, parent_id) begin req = {:name => name, :parent_id => parent_id} @sdk.create_folder(req).to_attrs rescue LookerSDK::Error => e say_error "Error creating folder(#{JSON.pretty_generate(req)})" say_error e raise end end |
#delete_folder(folder_id) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/gzr/modules/folder.rb', line 138 def delete_folder(folder_id) begin @sdk.delete_folder(folder_id) rescue LookerSDK::NotFound say_error "folder #{folder_id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error deleting folder #{folder_id}" say_error e raise end end |
#process_args(args) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/gzr/modules/folder.rb', line 72 def process_args(args) folder_ids = [] begin user = query_me("home_folder_id") folder_ids << user[:home_folder_id] end unless args && args.length > 0 && !(args[0].nil?) if args[0] == 'lookml' folder_ids << 'lookml' elsif args[0] =~ /^[0-9]+$/ then folder_ids << args[0].to_i elsif args[0] == "~" then user = query_me("personal_folder_id") folder_ids << user[:personal_folder_id] elsif args[0] =~ /^~[0-9]+$/ then user = query_user(args[0].sub('~',''), "personal_folder_id") folder_ids << user[:personal_folder_id] elsif args[0] =~ /^~.+@.+$/ then search_results = search_users( { :email=>args[0].sub('~','') },"personal_folder_id" ) folder_ids += search_results.map { |r| r[:personal_folder_id] } elsif args[0] =~ /^~.+$/ then first_name, last_name = args[0].sub('~','').split(' ') search_results = search_users( { :first_name=>first_name, :last_name=>last_name },"personal_folder_id" ) folder_ids += search_results.map { |r| r[:personal_folder_id] } else search_results = search_folders(args[0],"id") folder_ids += search_results.map { |r| r[:id] } # The built in Shared folder is only availabe by # searching for Home. https://github.com/looker/helltool/issues/34994 if args[0] == 'Shared' then search_results = search_folders('Home',"id,is_shared_root") folder_ids += search_results.select { |r| r[:is_shared_root] }.map { |r| r[:id] } end end if args && args.length > 0 && !args[0].nil? return folder_ids end |
#query_folder(id, fields = nil) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/gzr/modules/folder.rb', line 58 def query_folder(id,fields=nil) begin req = {} req[:fields] = fields if fields @sdk.folder(id, req).to_attrs rescue LookerSDK::NotFound return nil rescue LookerSDK::Error => e say_error "Error querying folder(#{id},#{JSON.pretty_generate(req)})" say_error e raise end end |
#query_folder_children(folder_id, fields = nil) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/gzr/modules/folder.rb', line 124 def query_folder_children(folder_id, fields=nil) req = {} req[:fields] = fields if fields begin @sdk.folder_children(folder_id, req).collect { |e| e.to_attrs } rescue LookerSDK::NotFound return [] rescue LookerSDK::Error => e say_error "Error querying folder_children(#{folder_id}, #{JSON.pretty_generate(req)})" say_error e raise end end |
#search_folders(name, fields = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gzr/modules/folder.rb', line 44 def search_folders(name,fields=nil) begin req = {:name => name} req[:fields] = fields if fields @sdk.search_folders(req).collect { |e| e.to_attrs } rescue LookerSDK::NotFound => e [] rescue LookerSDK::Error => e say_error "Error querying search_folders(#{JSON.pretty_generate(req)})" say_error e raise end end |