Module: Gzr::Model

Included in:
Commands::Model::Cat, Commands::Model::Import, Commands::Model::Ls
Defined in:
lib/gzr/modules/model.rb,
lib/gzr/modules/model/set.rb

Defined Under Namespace

Modules: Set

Instance Method Summary collapse

Instance Method Details

#cat_model(model_name) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/gzr/modules/model.rb', line 47

def cat_model(model_name)
  begin
    @sdk.lookml_model(model_name)&.to_attrs
  rescue LookerSDK::NotFound => e
    return nil
  rescue LookerSDK::Error => e
    say_error "Error getting lookml_model(#{model_name})"
    say_error e
    raise
  end
end

#create_model(body) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/gzr/modules/model.rb', line 65

def create_model(body)
  begin
    @sdk.create_lookml_model(body)&.to_attrs
  rescue LookerSDK::Error => e
    say_error "Error running create_lookml_model(#{JSON.pretty_generate(body)})"
    say_error e
    raise
  end
end

#query_all_lookml_models(fields = nil, progress = false) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gzr/modules/model.rb', line 26

def query_all_lookml_models(fields=nil, progress=false)
  data = []
  begin
    req = Hash.new
    req[:fields] = fields if fields
    req[:limit] = 16
    loop do
      puts "fetching #{req[:limit]} offset #{req[:offset] || 0}" if progress
      page = @sdk.all_lookml_models(req).collect { |m| m.to_attrs }
      data+=page
      break unless page.length == req[:limit]
      req[:offset] = (req[:offset] || 0) + req[:limit]
    end
  rescue LookerSDK::Error => e
    say_error "Error querying all_lookml_models(#{JSON.pretty_generate(req)})"
    say_error e
    raise
  end
  data
end

#trim_model(data) ⇒ Object



59
60
61
62
63
# File 'lib/gzr/modules/model.rb', line 59

def trim_model(data)
  data.select do |k,v|
    keys_to_keep('create_lookml_model').include? k
  end
end

#update_model(model_name, body) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/gzr/modules/model.rb', line 75

def update_model(model_name,body)
  begin
    @sdk.update_lookml_model(model_name,body)&.to_attrs
  rescue LookerSDK::Error => e
    say_error "Error running update_lookml_model(#{model_name},#{JSON.pretty_generate(body)})"
    say_error e
    raise
  end
end