red-amber-view 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb5e2459c607b9309c170cc4c430daac7ad37072cb26d847d1978d5b5e0eae79
4
- data.tar.gz: b138596f32935e9a3260c7bd09be8ef3a9f536e9d86951d5809894ea848063e4
3
+ metadata.gz: a906d4762fac64e4671e16728430d97f709001fce8429521d6d4e4d7fb92bbd7
4
+ data.tar.gz: 650d56a3a69a61a49bd9b21597734ac819df1e4e7fde91b07bcbd898cd7acc9b
5
5
  SHA512:
6
- metadata.gz: 063342bee50e06fca844511043d2097e7a069325ba262fd555a94bd86efd56e00ec54c174ca83eeb59b6be18c3e34af67abd6f5c82508fda715322e1fd38dccb
7
- data.tar.gz: eb1192290089a706c3e639d9e8cb8d2cf6d393c7999f85dae2b5cb48c1f62663424b42dde05a92517d9dca16c8b0320ce72774292d78b5db4a77965a5d58a93e
6
+ metadata.gz: d029ceb987981f0df229915706daacec55151a2366318bbba8866fed1c772e0abaf917db55296a6e38a308563d2bd241dff9f94505ba7e8afbd51b2699ef817a
7
+ data.tar.gz: e184c90a5b65880b0d3294e9ab8afbda61c442143eb07e468b8be4348ac042bd4ce4ac55f91c23e8d0a9aa7cb646a0f5c1ad3655d9b0739c5d5c240b8cbf041b
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # RedAmber View
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/red-amber-view.svg)](https://badge.fury.io/rb/red-amber-view)
4
+ [![test](https://github.com/kojix2/red-amber-view/actions/workflows/ci.yml/badge.svg)](https://github.com/kojix2/red-amber-view/actions/workflows/ci.yml)
5
+ [![Gitter Chat](https://badges.gitter.im/red-data-tools/en.svg)](https://gitter.im/red-data-tools/en)
6
+
3
7
  R's `View()` for [RedAmber](https://github.com/heronshoes/red_amber).
4
8
 
5
9
  ## Installation
@@ -3,13 +3,13 @@
3
3
  require 'libui'
4
4
  require 'arrow'
5
5
 
6
- WINDOW_TITLE = 'RedAmber View'
6
+ WINDOW_TITLE = ARGV[1]
7
7
  WINDOW_WIDTH = 600
8
8
  WINDOW_HEIGHT = 400
9
9
 
10
10
  ARROW_PATH = ARGV[0]
11
- rm_arrow_file = proc { File.exist?(ARROW_PATH) && File.delete(ARROW_PATH) }
12
- at_exit(&rm_arrow_file)
11
+ arrow_table = Arrow::Table.load(ARROW_PATH)
12
+ File.unlink(ARROW_PATH)
13
13
 
14
14
  LibUI.init
15
15
 
@@ -18,7 +18,6 @@ main_window = LibUI.new_window(WINDOW_TITLE, WINDOW_WIDTH, WINDOW_HEIGHT, 1)
18
18
  hbox = LibUI.new_horizontal_box
19
19
  LibUI.window_set_child(main_window, hbox)
20
20
 
21
- arrow_table = Arrow::Table.load(ARROW_PATH)
22
21
  ncol = arrow_table.n_columns
23
22
  nrow = arrow_table.n_rows
24
23
 
@@ -59,7 +58,6 @@ LibUI.box_append(hbox, table, 1)
59
58
  LibUI.control_show(main_window)
60
59
 
61
60
  LibUI.window_on_closing(main_window) do
62
- rm_arrow_file.call
63
61
  LibUI.control_destroy(main_window)
64
62
  LibUI.free_table_model(model)
65
63
  LibUI.quit
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RedAmber
4
4
  module View
5
- VERSION = '0.0.0'
5
+ VERSION = '0.0.1'
6
6
  end
7
7
  end
@@ -7,17 +7,45 @@ module RedAmber
7
7
  module View
8
8
  DataFrame.include(self)
9
9
 
10
- def view
11
- require 'securerandom'
12
- rand = SecureRandom.hex(10)
13
- path = "/dev/shm/red-amber-view-#{rand}.arrow"
14
- while File.exist? path
15
- path = "/dev/shm/red-amber-view-#{rand}.arrow"
10
+ # Invokes a spreadsheet-style data viewer
11
+ # @param [String] title A title for a viewer window.
12
+ # @return [Integer] The pid of the child process.
13
+
14
+ def view(title = 'RedAmber View')
15
+ arrow_path = nil
16
+
17
+ # Linux
18
+ if Dir.exist?('/dev/shm')
19
+ require 'securerandom'
20
+ loop do
21
+ arrow_path = "/dev/shm/red-amber-view-#{SecureRandom.hex(8)}.arrow"
22
+ break unless File.exist? arrow_path
23
+ end
24
+ begin
25
+ save_succeeded = to_arrow.save(arrow_path)
26
+ rescue StandardError => e
27
+ warn e.message
28
+ end
16
29
  end
17
- to_arrow.save(path)
18
- arrow_table_viewer = File.expand_path('../../exe/arrow_table_view.rb', __dir__)
19
- pid = spawn("ruby #{arrow_table_viewer} #{path}")
20
- Process.detach(pid)
30
+
31
+ # When /dev/shm is not available
32
+ unless save_succeeded
33
+ require 'tempfile'
34
+ # The tempfile will be removed by the spawned process.
35
+ tf = Tempfile.create(['red-amber-view', '.arrow'])
36
+ arrow_path = tf.path
37
+ save_succeeded = to_arrow.save(arrow_path)
38
+ end
39
+
40
+ raise 'Failed to save arrow file' unless save_succeeded
41
+
42
+ spawn(RbConfig.ruby, arrow_table_viewer, arrow_path, title)
43
+ end
44
+
45
+ private
46
+
47
+ def arrow_table_viewer
48
+ File.expand_path('../../exe/arrow_table_view.rb', __dir__)
21
49
  end
22
50
  end
23
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: red-amber-view
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-03 00:00:00.000000000 Z
11
+ date: 2022-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libui