Class: Gzr::Commands::Space::Export
- Inherits:
-
Gzr::Command
- Object
- Gzr::Command
- Gzr::Commands::Space::Export
- Includes:
- Dashboard, FileHelper, Look, Plan, Space
- Defined in:
- lib/gzr/commands/space/export.rb
Instance Method Summary collapse
- #execute(input: $stdin, output: $stdout) ⇒ Object
-
#initialize(space_id, options) ⇒ Export
constructor
A new instance of Export.
- #process_space(space_id, base, rel_path = nil) ⇒ Object
Methods included from FileHelper
Methods included from Plan
#create_scheduled_plan, #delete_scheduled_plan, #query_all_scheduled_plans, #query_scheduled_plan, #query_scheduled_plans_for_dashboard, #query_scheduled_plans_for_look, #run_scheduled_plan, #update_scheduled_plan, #upsert_plan_for_dashboard, #upsert_plan_for_look, #upsert_plan_for_obj, #upsert_plans_for_dashboard, #upsert_plans_for_look, #upsert_plans_for_obj
Methods included from Dashboard
#cat_dashboard, #create_dashboard, #create_dashboard_element, #create_dashboard_filter, #create_dashboard_layout, #delete_dashboard, #delete_dashboard_element, #delete_dashboard_filter, #delete_dashboard_layout, #get_dashboard_layout, #query_dashboard, #search_dashboards_by_slug, #search_dashboards_by_title, #update_dashboard, #update_dashboard_element, #update_dashboard_filter, #update_dashboard_layout, #update_dashboard_layout_component
Methods included from Look
#cat_look, #create_fetch_query, #create_look, #create_merge_result, #delete_look, #query_look, #search_looks_by_slug, #search_looks_by_title, #update_look, #upsert_look
Methods included from Space
#all_spaces, #create_space, #delete_space, included, #process_args, #query_space, #query_space_children, #search_spaces
Methods inherited from Gzr::Command
#all_color_collections, #color_collection, #color_palette_lookup!, #create_merge_query, #create_query, #default_color_collection, #field_expression, #field_names, #find_color_palette_reference, #find_vis_config_reference, #keys_to_keep, #merge_query, #pairs, #query, #render_csv, #rewrite_color_palette!, #run_inline_query, #update_color_palette!
Methods included from Session
#build_connection_hash, #login, #logout_all, #pastel, #say_error, #say_ok, #say_warning, #sufficient_version?, #with_session
Constructor Details
#initialize(space_id, options) ⇒ Export
Returns a new instance of Export.
43 44 45 46 47 |
# File 'lib/gzr/commands/space/export.rb', line 43 def initialize(space_id, ) super() @space_id = space_id @options = end |
Instance Method Details
#execute(input: $stdin, output: $stdout) ⇒ Object
49 50 51 52 53 54 55 56 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 86 |
# File 'lib/gzr/commands/space/export.rb', line 49 def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] with_session("3.1") do if @options[:tar] || @options[:tgz] || @options[:zip] then arc_path = Pathname.new(@options[:tgz] || @options[:tar] || @options[:zip]) arc_path = Pathname.new(File.(@options[:dir])) + arc_path unless arc_path.absolute? if @options[:tar] || @options[:tgz] f = File.open(arc_path.to_path, "wb") tarfile = StringIO.new(String.new,"w") unless @options[:zip] begin tw = Gem::Package::TarWriter.new(tarfile) process_space(@space_id, tw) tw.flush tarfile.rewind if @options[:tgz] gzw = Zlib::GzipWriter.new(f) gzw.write tarfile.string gzw.close else f.write tarfile.string end ensure f.close tarfile.close end else z = Zip::File.new(arc_path.to_path, Zip::File::CREATE, false, continue_on_exists_proc: true) begin process_space(@space_id, z) ensure z.close end end else process_space(@space_id, @options[:dir]) end end end |
#process_space(space_id, base, rel_path = nil) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/gzr/commands/space/export.rb', line 88 def process_space(space_id, base, rel_path = nil) space = query_space(space_id).to_attrs name = space[:name] name = "nil (#{space_id})" if name.nil? path = Pathname.new(name.gsub('/',"\u{2215}")) path = rel_path + path if rel_path write_file("Space_#{space[:id]}_#{name}.json", base, path) do |f| f.write JSON.pretty_generate(space.reject do |k,v| [:looks, :dashboards].include?(k) end) end space[:looks].each do |l| look = cat_look(l[:id]) write_file("Look_#{look[:id]}_#{look[:title]}.json", base, path) do |f| f.write JSON.pretty_generate(look) end end space[:dashboards].each do |d| data = cat_dashboard(d[:id]) write_file("Dashboard_#{data[:id]}_#{data[:title]}.json", base, path) do |f| f.write JSON.pretty_generate(data) end end space_children = query_space_children(space_id) space_children.each do |child_space| process_space(child_space[:id], base, path) end end |