ruby_uml_class 0.1.0

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.
data/lib/start.rb ADDED
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ $LOAD_PATH << File.dirname(File.expand_path(__FILE__))
4
+
5
+ require "socket"
6
+ require "rack"
7
+ require "daemons"
8
+ require "fileutils"
9
+ require "kconv"
10
+ require "json"
11
+ require "facter"
12
+
13
+ # ログ出力
14
+ module Output
15
+ def self.console_and_file(output_file, stdout = true)
16
+ begin
17
+ defout = File.new(output_file, "a+")
18
+ rescue
19
+ puts $!
20
+ puts $@
21
+ return nil
22
+ end
23
+ class << defout
24
+ alias_method :write_org, :write
25
+
26
+ def initialize(stdout)
27
+ @stdout = false
28
+ end
29
+
30
+ attr_accessor :stdout
31
+
32
+ def puts(str)
33
+ STDOUT.write(str.to_s + "\n") if @stdout
34
+ self.write_org(str.to_s + "\n")
35
+ self.flush
36
+ end
37
+
38
+ def write(str)
39
+ STDOUT.write(str) if @stdout
40
+ self.write_org(str)
41
+ self.flush
42
+ end
43
+ end
44
+ $stdout = defout
45
+ $stdout.stdout = stdout
46
+ end
47
+ end
48
+
49
+ # ディレクトリ移動
50
+ dir = File.dirname(File.expand_path(__FILE__))
51
+ FileUtils.cd dir
52
+
53
+ # ディレクトリ作成
54
+ pp ARGV
55
+ if ARGV[0] == "test"
56
+ $home_dir = "./"
57
+ ARGV = []
58
+ else
59
+ $home_dir = ENV["HOME"] + "/" + dir.split("/")[-1].gsub(/-[0-9\.-]+/,"") + "/"
60
+ end
61
+ puts "home_dir=#{$home_dir}"
62
+ FileUtils.mkdir_p("#{$home_dir}/logs")
63
+ FileUtils.mkdir_p("#{$home_dir}/history")
64
+ Output.console_and_file("#{$home_dir}/logs/app.log", true)
65
+
66
+ # 空きポートを取得
67
+ def get_unused_port
68
+ s = TCPServer.open(0)
69
+ port = s.addr[1]
70
+ s.close
71
+ return port
72
+ end
73
+
74
+ # 空きポートを取得
75
+ port = get_unused_port
76
+ puts "port=#{port}"
77
+
78
+ # config.ruの編集
79
+ buf = File.binread("config.ru").toutf8
80
+ buf.gsub!(/port [0-9]+/, "port #{port}")
81
+ File.binwrite("config.ru", buf)
82
+
83
+ # main.jsの編集
84
+ buf = File.binread("js/main.js").toutf8
85
+ buf.gsub!(/localhost:[0-9]+\//, "localhost:#{port}/")
86
+ File.binwrite("js/main.js", buf)
87
+
88
+ # index.htaの編集
89
+ buf = File.binread("html/index.html").toutf8
90
+ buf.gsub!(/localhost:[0-9]+\//, "localhost:#{port}/")
91
+ File.binwrite("html/index.html", buf)
92
+
93
+ begin
94
+ Thread.start {
95
+ puts "wait start web server"
96
+ while true
97
+ begin
98
+ s = TCPSocket.open("localhost", port)
99
+ s.close
100
+ break
101
+ rescue
102
+ puts $!
103
+ sleep 0.1
104
+ end
105
+ end
106
+
107
+ puts "start browser"
108
+ json_file = "#{$home_dir}/config/browser.json"
109
+ json = JSON.parse(File.read json_file)
110
+ puts json
111
+ kernel = Facter.value(:kernel)
112
+ if kernel == "windows"
113
+ browser = json["chrome_win"]
114
+ elsif kernel == "Linux"
115
+ browser = json["chrome_linux"]
116
+ else
117
+ browser = json["chrome_win"]
118
+ end
119
+ browser += " -app=http://localhost:#{port}"
120
+ puts browser
121
+ system browser
122
+ }
123
+
124
+ # start web server
125
+ Rack::Server.start
126
+ rescue
127
+ puts $!
128
+ puts $@
129
+ exit
130
+ end
data/lib/wsserver.rb ADDED
@@ -0,0 +1,147 @@
1
+ require "./server_app_base"
2
+ require "json"
3
+ require "cgi"
4
+ require "thread"
5
+
6
+ def config_json_hash(json)
7
+ config = {}
8
+ json["setting_list"].each do |j|
9
+ config[j["name"]] = j["value"]
10
+ end
11
+ return config
12
+ end
13
+
14
+ $ws_exit_thread = nil
15
+
16
+ class WsServer < Sinatra::Base
17
+ def initialize
18
+ super
19
+ @ws_list = []
20
+ @ws_lock = Mutex.new
21
+ end
22
+
23
+ def ws_send(str)
24
+ @ws_lock.synchronize do
25
+ if @ws_list[0] != nil
26
+ @ws_list[0].send(str)
27
+ end
28
+ end
29
+ end
30
+
31
+ json_config = nil
32
+ exec_thread = nil
33
+ get "" do
34
+ if !request.websocket?
35
+ "no supported"
36
+ else
37
+ request.websocket do |ws|
38
+ ws.onopen do
39
+ puts "ws.open"
40
+ @ws_lock.synchronize do
41
+ @ws_list << ws
42
+ $app.set_ws(ws)
43
+ pp "ws=#{ws}"
44
+ end
45
+ ws_send("startup:#{$startup_file}")
46
+ puts "ws_exit_thread=#{$ws_exit_thread}"
47
+ if $ws_exit_thread != nil
48
+ puts "ws_exit_thread kill"
49
+ Thread.kill $ws_exit_thread
50
+ end
51
+ end
52
+ ws.onmessage do |msg|
53
+ puts msg
54
+ json = JSON.parse(File.read("#{$home_dir}/config/setting.json"))
55
+ json_config = config_json_hash(json)
56
+ $app.set_config(json_config)
57
+ if msg =~ /^exec:/
58
+ if exec_thread == nil
59
+ argv = msg.gsub(/^exec:/, "")
60
+ exec_thread = Thread.new {
61
+ begin
62
+ $app.start(argv.split(",")) do |out|
63
+ ws_send(out)
64
+ end
65
+ ws_send("app_end:normal")
66
+ rescue
67
+ puts $!
68
+ puts $@
69
+ puts "app_end:err"
70
+ ws_send("app_end:error")
71
+ ensure
72
+ puts "exit thread"
73
+ exec_thread = nil
74
+ end
75
+ }
76
+ else
77
+ puts "app_end:err"
78
+ ws_send("app_end:error")
79
+ end
80
+ end
81
+ if msg =~ /^stop/
82
+ if exec_thread
83
+ Thread.kill exec_thread
84
+ ws_send("app_end:stop")
85
+ $app.stop
86
+ end
87
+ end
88
+ if msg =~ /^suspend/
89
+ if exec_thread
90
+ $app.suspend
91
+ end
92
+ end
93
+ if msg =~ /^resume/
94
+ if exec_thread
95
+ $app.resume
96
+ end
97
+ end
98
+ if msg =~ /^setting:/
99
+ json_string = msg.gsub(/^setting:/, "")
100
+ begin
101
+ json = JSON.parse(json_string)
102
+ File.open("#{$home_dir}/config/setting.json", "w") do |w|
103
+ w.puts JSON.pretty_generate(json)
104
+ end
105
+ json_config = config_json_hash(json)
106
+ $app.set_config(json_config)
107
+ rescue
108
+ # jsonファイルではない
109
+ ws_send("app_end:error")
110
+ end
111
+ end
112
+ if msg =~ /^openfile:/
113
+ file = msg.gsub(/^openfile:/, "")
114
+ if file != ""
115
+ Thread.new {
116
+ system "#{json_config["editor"]} #{CGI.unescapeHTML(file)}"
117
+ }
118
+ end
119
+ end
120
+
121
+ # アプリケーション終了
122
+ if msg == "exit"
123
+ #halt
124
+ exit
125
+ end
126
+ end
127
+
128
+ # close websocket
129
+ ws.onclose do
130
+ puts "websocket closed"
131
+ @ws_lock.synchronize do
132
+ @ws_list.delete(ws)
133
+ end
134
+ puts @ws_list.size
135
+ if @ws_list.size == 0
136
+ $ws_exit_thread = Thread.start {
137
+ sleep 1
138
+ #halt
139
+ exit
140
+ }
141
+ puts "ws_exit_thread=#{$ws_exit_thread}"
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/ruby_uml_class/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ruby_uml_class"
7
+ spec.version = RubyUmlClassVer::VERSION
8
+ spec.authors = ["Masataka kuwayama"]
9
+ spec.email = ["masataka.kuwayama@gmail.com"]
10
+
11
+ spec.summary = "Create a Ruby UML class diagram."
12
+ spec.description = "Create a Ruby UML class diagram with PlangUml."
13
+ spec.homepage = "https://github.com/kuwayama1971/RubyUmlClass"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = spec.homepage
21
+ spec.metadata["changelog_uri"] = spec.homepage
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
+ end
29
+ end
30
+ spec.bindir = "bin"
31
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ # Uncomment to register a new dependency of your gem
35
+ # spec.add_dependency "example-gem", "~> 1.0"
36
+
37
+ spec.add_development_dependency "browser_app_base"
38
+ spec.add_development_dependency "rufo"
39
+
40
+ # For more information and examples about making a new gem, check out our
41
+ # guide at: https://bundler.io/guides/creating_gem.html
42
+ end
@@ -0,0 +1,4 @@
1
+ module RubyUmlClass
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_uml_class
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Masataka kuwayama
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-01-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: browser_app_base
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rufo
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Create a Ruby UML class diagram with PlangUml.
42
+ email:
43
+ - masataka.kuwayama@gmail.com
44
+ executables:
45
+ - start_ruby_uml_class.rb
46
+ - start_ruby_uml_class.rbw
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".rspec"
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/start_ruby_uml_class.rb
57
+ - bin/start_ruby_uml_class.rbw
58
+ - img/RubyUmlClass.mp4
59
+ - lib/app_load.rb
60
+ - lib/config.ru
61
+ - lib/config/browser.json
62
+ - lib/config/setting.json
63
+ - lib/create_uml_class.rb
64
+ - lib/css/index.css
65
+ - lib/history/history.json
66
+ - lib/html/index.html
67
+ - lib/js/main.js
68
+ - lib/ruby_uml_class.rb
69
+ - lib/ruby_uml_class/version.rb
70
+ - lib/server.rb
71
+ - lib/server_app_base.rb
72
+ - lib/start.rb
73
+ - lib/wsserver.rb
74
+ - ruby_uml_class.gemspec
75
+ - sig/ruby_uml_class.rbs
76
+ homepage: https://github.com/kuwayama1971/RubyUmlClass
77
+ licenses:
78
+ - MIT
79
+ metadata:
80
+ allowed_push_host: https://rubygems.org
81
+ homepage_uri: https://github.com/kuwayama1971/RubyUmlClass
82
+ source_code_uri: https://github.com/kuwayama1971/RubyUmlClass
83
+ changelog_uri: https://github.com/kuwayama1971/RubyUmlClass
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 2.6.0
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubygems_version: 3.1.2
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Create a Ruby UML class diagram.
103
+ test_files: []