Module: Gzr::Model::Set
- Included in:
- Commands::Model::Set::Cat, Commands::Model::Set::Delete, Commands::Model::Set::Import, Commands::Model::Set::Ls
- Defined in:
- lib/gzr/modules/model/set.rb
Instance Method Summary collapse
- #all_model_sets(fields = nil) ⇒ Object
- #cat_model_set(set_id, fields = nil) ⇒ Object
- #create_model_set(data) ⇒ Object
- #delete_model_set(model_set_id) ⇒ Object
- #search_model_sets(fields: nil, sorts: nil, id: nil, name: nil, all_access: nil, built_in: nil, filter_or: nil) ⇒ Object
- #trim_model_set(data) ⇒ Object
- #update_model_set(model_set_id, data) ⇒ Object
Instance Method Details
#all_model_sets(fields = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gzr/modules/model/set.rb', line 28 def all_model_sets(fields=nil) req = {} req[:fields] = fields if fields begin @sdk.all_model_sets(req).collect { |s| s.to_attrs } rescue LookerSDK::NotFound => e return nil rescue LookerSDK::Error => e say_error "Error querying all_model_sets(#{JSON.pretty_generate(req)})" say_error e raise end end |
#cat_model_set(set_id, fields = nil) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/gzr/modules/model/set.rb', line 42 def cat_model_set(set_id, fields=nil) req = {} req[:fields] = fields if fields begin @sdk.model_set(set_id,req)&.to_attrs rescue LookerSDK::NotFound => e return nil rescue LookerSDK::Error => e say_error "Error querying model_set(#{set_id},#{JSON.pretty_generate(req)})" say_error e raise end end |
#create_model_set(data) ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/gzr/modules/model/set.rb', line 101 def create_model_set(data) begin @sdk.create_model_set(data)&.to_attrs rescue LookerSDK::Error => e say_error "Error calling create_model_set(#{JSON.pretty_generate(data)})" say_error e raise end end |
#delete_model_set(model_set_id) ⇒ Object
111 112 113 114 115 116 117 118 119 |
# File 'lib/gzr/modules/model/set.rb', line 111 def delete_model_set(model_set_id) begin @sdk.delete_model_set(model_set_id) rescue LookerSDK::Error => e say_error "Error calling delete_model_set(#{model_set_id}})" say_error e raise end end |
#search_model_sets(fields: nil, sorts: nil, id: nil, name: nil, all_access: nil, built_in: nil, filter_or: nil) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/gzr/modules/model/set.rb', line 63 def search_model_sets(fields: nil, sorts: nil, id: nil, name: nil, all_access: nil, built_in: nil, filter_or: nil) data = [] begin req = {} req[:fields] = fields unless fields.nil? req[:sorts] = sorts unless sorts.nil? req[:id] = id unless id.nil? req[:name] = name unless name.nil? req[:all_access] = all_access unless all_access.nil? req[:built_in] = built_in unless built_in.nil? req[:filter_or] = filter_or unless filter_or.nil? req[:limit] = 64 loop do page = @sdk.search_model_sets(req).collect { |s| s.to_attrs } data+=page break unless page.length == req[:limit] req[:offset] = (req[:offset] || 0) + req[:limit] end rescue LookerSDK::NotFound => e # do nothing rescue LookerSDK::Error => e say_error "Error calling search_model_sets(#{JSON.pretty_generate(req)})" say_error e raise end data end |
#trim_model_set(data) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/gzr/modules/model/set.rb', line 56 def trim_model_set(data) trimmed = data.select do |k,v| (keys_to_keep('update_model_set') + [:id,:built_in]).include? k end trimmed end |
#update_model_set(model_set_id, data) ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/gzr/modules/model/set.rb', line 91 def update_model_set(model_set_id, data) begin @sdk.update_model_set(model_set_id, data)&.to_attrs rescue LookerSDK::Error => e say_error "Error calling update_model_set(#{model_set_id},#{JSON.pretty_generate(data)})" say_error e raise end end |