squared 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fad15a8296b3ab7fec1ff1ac0bbe1f92b65b3bd263e8f9ea38cd62e1a8e3460e
4
- data.tar.gz: 1ab92094b8d239572ac66a42014aafcca6585f86af1159060715e322d8138503
3
+ metadata.gz: 60e2da1ce8ec4439d4180db0c0f806d9984046ef5f12b34008563edd7b40b938
4
+ data.tar.gz: 6eb7ef1c8273d10747cb79c1a113dae53210cebd167969f4a1546a9fc07162f0
5
5
  SHA512:
6
- metadata.gz: f4b7ecd7671596c8da581f567e43a4968ec7ea2f060a75d92b4369d19d3e1638e2f2c91b70e3c0205bbc77ccd309341d5dbb47c1c774eead07f5c71a0bf13684
7
- data.tar.gz: 1c88e0dabe3ef47f17527c604440775fdf5984a5389ad6e6e8ec4a9c8ade34a4c59423bdf0f1277e6ffb88a8484d774da3029f814cc37526b92f1d737257e18b
6
+ metadata.gz: 75f989753670bd5854a8dccc6a3bf8d3d7397d2a373a50d46eaa7add861ff8d1f24cffb1c9ac00d48756d89abb50728c35368beb62649b3d704f3d7b059b449a
7
+ data.tar.gz: 6387222860eb65bd57cd14ba86b77b39d47a64d5a03940a5b6f6ac0ccea6368f0ab8df0a1886d5f6e6eec83f89887397b72f57a647a4ad06efa632020c1a5938
data/README.ruby.md CHANGED
@@ -32,14 +32,15 @@ Projects from any accessible folder can be added either relative to `REPO_ROOT`
32
32
 
33
33
  ```ruby
34
34
  require "squared"
35
+ require "squared/workspace/repo" # Repo (optional)
35
36
 
36
37
  # REPO_ROOT = /workspaces
37
38
  # REPO_HOME = /workspaces/squared
38
39
  # rake = /workspaces/squared/Rakefile
39
40
 
40
- Repo::Workspace
41
+ Workspace::Application
41
42
  .new("squared") # REPO_HOME
42
- .repo("https://github.com/anpham6/squared-repo", "nightly", run: 'build') # Optional
43
+ .repo("https://github.com/anpham6/squared-repo", "nightly", run: "build") # Repo (optional)
43
44
  .run("rake install", ref: :ruby)
44
45
  .clean("rake clean", group: "default") # depend test doc
45
46
  .clean(["build/"], group: "app")
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Squared
4
+ module Common
5
+ VAR = {
6
+ project: {},
7
+ colors: {
8
+ black: '30',
9
+ red: '31',
10
+ green: '32',
11
+ yellow: '33',
12
+ blue: '34',
13
+ magenta: '35',
14
+ cyan: '36',
15
+ white: '37',
16
+ black!: '40',
17
+ red!: '41',
18
+ green!: '42',
19
+ yellow!: '43',
20
+ blue!: '44',
21
+ magenta!: '45',
22
+ cyan!: '46',
23
+ white!: '47'
24
+ },
25
+ theme: {
26
+ workspace: {},
27
+ project: {},
28
+ viewer: {
29
+ banner: %i[blue bold],
30
+ key: %i[bold],
31
+ value: %i[green],
32
+ string: %i[yellow],
33
+ hash: %i[green black!],
34
+ array: %i[blue black!],
35
+ number: %i[magenta],
36
+ undefined: %i[red italic]
37
+ },
38
+ logger: {
39
+ unknown: %i[cyan],
40
+ fatal: %i[white bold red!],
41
+ error: %i[red bold],
42
+ warn: %i[yellow bold],
43
+ info: %i[blue],
44
+ debug: %i[green]
45
+ }
46
+ }
47
+ }.compare_by_identity
48
+ private_constant :VAR
49
+
50
+ private
51
+
52
+ def __get__(key)
53
+ VAR[key.is_a?(::String) ? key.to_sym : key]
54
+ end
55
+
56
+ def __set__(key, val)
57
+ return if VAR.frozen?
58
+
59
+ VAR[key.is_a?(::String) ? key.to_sym : key] = val
60
+ end
61
+
62
+ def env(key, equals: nil, ignore: nil, default: nil, **)
63
+ ret = ENV.fetch(key, '')
64
+ return ret == equals.to_s unless equals.nil?
65
+
66
+ ret.empty? || (ignore && as_a(ignore).any? { |val| ret == val.to_s }) ? default : ret
67
+ end
68
+
69
+ def message(*args, hint: nil)
70
+ args.reject(&:empty?).join(' => ') + (hint ? " (#{hint})" : '')
71
+ end
72
+
73
+ def as_a(obj, flat: nil)
74
+ if obj.nil?
75
+ []
76
+ elsif !obj.is_a?(::Array)
77
+ [obj]
78
+ elsif flat
79
+ obj.flatten(flat == true ? nil : flat)
80
+ else
81
+ obj
82
+ end
83
+ end
84
+
85
+ def finalize!
86
+ VAR.each_value(&:freeze)
87
+ VAR[:theme].each_value(&:freeze)
88
+ VAR.freeze
89
+ end
90
+ end
91
+ end
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'logger'
4
+
5
+ require_relative 'base'
6
+
3
7
  module Squared
4
8
  module Common
5
9
  module Format
@@ -33,6 +37,8 @@ module Squared
33
37
  block_given? ? yield(self) : self
34
38
  end
35
39
 
40
+ private
41
+
36
42
  def emphasize(val, title: nil, cols: nil, sub: nil, pipe: nil)
37
43
  n = 0
38
44
  if title
@@ -166,6 +172,10 @@ module Squared
166
172
  end
167
173
  end
168
174
 
175
+ def raise_error(*args, hint: nil, kind: ArgumentError)
176
+ raise kind, message(*args, hint: hint)
177
+ end
178
+
169
179
  def log_title(level, color: true)
170
180
  level = if level.is_a?(::Numeric)
171
181
  case level
@@ -186,13 +196,12 @@ module Squared
186
196
  level.to_s.downcase.to_sym
187
197
  end
188
198
  theme = __get__(:theme)[:logger]
189
- val = theme[level] || theme[level = :unknown]
190
- level = +level.to_s.upcase
191
- case level
199
+ styles = theme[level] || theme[level = :unknown]
200
+ case (ret = +level.to_s.upcase)
192
201
  when 'WARN', 'ERROR', 'FATAL'
193
- level += '!'
202
+ ret += '!'
194
203
  end
195
- color ? sub_style(level, *val) : level
204
+ color ? sub_style(ret, *styles) : ret
196
205
  end
197
206
 
198
207
  def log_message(level, *args, subject: nil, hint: nil, color: true)
@@ -1,24 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'shellwords'
4
+ require 'rake'
5
+
3
6
  module Squared
4
7
  module Common
5
8
  module Shell
9
+ private
10
+
6
11
  def shell_escape(val, quote: false)
7
12
  return (quote ? shell_quote(val, force: false) : val) if ::Rake::Win32.windows?
8
13
 
9
- require 'shellwords'
10
14
  Shellwords.escape(val)
11
15
  end
12
16
 
13
17
  def shell_quote(val, force: true)
14
18
  ret = val.to_s.strip
15
- return ret if (!force && !ret.include?(' ')) || ret.match?(/(?:^|=)(["']).+\1$/m)
19
+ return ret if (!force && !ret.include?(' ')) || ret =~ /(?:^|=)(["']).+\1$/m
16
20
 
17
21
  ::Rake::Win32.windows? ? "\"#{double_quote(ret)}\"" : "'#{single_quote(ret)}'"
18
22
  end
19
23
 
20
24
  def fill_option(val)
21
- return "-#{val}" if val.size == 1 || val.match?(/^[a-z]\d+$/i)
25
+ return "-#{val}" if val.size == 1 || val =~ /^[a-z]\d+$/i
22
26
 
23
27
  val = "--#{val}" unless val.start_with?('-')
24
28
  shell_escape(val).sub('\\=', '=')
@@ -36,10 +40,6 @@ module Squared
36
40
  val.split(/\s*(?<!\\)#{char}\s*/)
37
41
  end
38
42
 
39
- def trailing_slash(val)
40
- val.to_s.chomp(::File::SEPARATOR) + ::File::SEPARATOR
41
- end
42
-
43
43
  def sanitize_args(*opts)
44
44
  opts.map { |val| val.include?(' ') ? shell_quote(val) : shell_escape(val) }.join(' ')
45
45
  end
@@ -1,12 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'pathname'
4
+ require 'fileutils'
4
5
 
5
6
  module Squared
6
7
  module Common
7
8
  module System
9
+ private
10
+
8
11
  def shell(*cmd, **kwargs)
9
- if /^2\.[0-5]\./.match?(RUBY_VERSION)
12
+ if RUBY_VERSION =~ /^2\.[0-5]\./
10
13
  exception = kwargs.delete(:exception)
11
14
  ret = system(*cmd, **kwargs)
12
15
  raise $?.to_s if !ret && exception
@@ -1,13 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rake'
4
+
3
5
  module Squared
4
6
  module Common
5
7
  module Task
8
+ private
9
+
6
10
  def collect_args(args, *keys)
7
11
  ret = []
8
12
  return ret unless args.is_a?(::Rake::TaskArguments)
9
13
 
10
- keys.each { |key| ret << args[key] if args[key] }
14
+ keys.each { |key| ret << args.fetch(key) if args.key?(key) }
11
15
  ret += args.extras
12
16
  end
13
17
 
@@ -1,86 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'pathname'
4
- require 'logger'
5
4
  require 'rake'
6
5
 
7
- module Squared
8
- module Common
9
- VAR = {
10
- project: {},
11
- colors: {
12
- black: '30',
13
- red: '31',
14
- green: '32',
15
- yellow: '33',
16
- blue: '34',
17
- magenta: '35',
18
- cyan: '36',
19
- white: '37',
20
- black!: '40',
21
- red!: '41',
22
- green!: '42',
23
- yellow!: '43',
24
- blue!: '44',
25
- magenta!: '45',
26
- cyan!: '46',
27
- white!: '47'
28
- },
29
- theme: {
30
- workspace: {},
31
- project: {},
32
- viewer: {
33
- banner: %i[blue bold],
34
- key: %i[bold],
35
- value: %i[green],
36
- string: %i[yellow],
37
- hash: %i[green black!],
38
- array: %i[blue black!],
39
- number: %i[magenta],
40
- undefined: %i[red italic]
41
- },
42
- logger: {
43
- unknown: %i[cyan],
44
- fatal: %i[white bold red!],
45
- error: %i[red bold],
46
- warn: %i[yellow bold],
47
- info: %i[blue],
48
- debug: %i[green]
49
- }
50
- }
51
- }.compare_by_identity
52
- private_constant :VAR
53
-
54
- def __get__(key)
55
- VAR[key.is_a?(::String) ? key.to_sym : key]
56
- end
57
-
58
- def __set__(key, val)
59
- return if VAR.frozen?
60
-
61
- VAR[key.is_a?(::String) ? key.to_sym : key] = val
62
- end
63
-
64
- def finalize!
65
- VAR.each_value(&:freeze)
66
- VAR[:theme].each_value(&:freeze)
67
- VAR.freeze
68
- end
69
-
70
- def message(*args, hint: nil)
71
- args.reject(&:empty?).join(' => ') + (hint ? " (#{hint})" : '')
72
- end
73
-
74
- def as_a(obj, flat: nil)
75
- return [] if obj.nil?
76
- return [obj] unless obj.is_a?(::Array)
77
- return obj unless flat
78
-
79
- obj.flatten(flat == true ? nil : flat)
80
- end
81
- end
82
- end
83
-
6
+ require_relative 'common/base'
84
7
  require_relative 'common/class'
85
8
  require_relative 'common/format'
86
9
  require_relative 'common/shell'
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'json'
4
4
 
5
+ require_relative 'common'
6
+
5
7
  module Squared
6
8
  module Config
7
9
  class Viewer
@@ -63,14 +65,14 @@ module Squared
63
65
  namespace view do
64
66
  if @mime['json'] && (exist? || !::Rake::Task.task_defined?("#{name}:#{view}:json"))
65
67
  desc format_desc(view, %w[json])
66
- task :json, [:keys] do |_, args|
68
+ task 'json', [:keys] do |_, args|
67
69
  read_keys(JSON, 'json', *params.(args))
68
70
  end
69
71
  end
70
72
 
71
73
  if @mime['yaml'] && (exist? || !::Rake::Task.task_defined?("#{name}:#{view}:yaml"))
72
74
  desc format_desc(view, %w[yaml yml])
73
- task :yaml, [:keys] do |_, args|
75
+ task 'yaml', [:keys] do |_, args|
74
76
  require 'yaml'
75
77
  read_keys(YAML, 'yaml', *params.(args), ext: %w[yml yaml])
76
78
  end
@@ -161,7 +163,7 @@ module Squared
161
163
 
162
164
  def read_keys(reader, type, file, keys, ext: [type])
163
165
  if (mime = mime_type(file)) && base_path(file).exist?
164
- raise ArgumentError, message(file, mime, hint: 'invalid') unless ext.include?(mime)
166
+ raise_error(file, mime, hint: 'invalid') unless ext.include?(mime)
165
167
  else
166
168
  if ext.include?(mime)
167
169
  alt = file
@@ -172,9 +174,7 @@ module Squared
172
174
  alt = base_path("#{main}.{#{ext.join(',')}}")
173
175
  file = Dir[alt].first
174
176
  end
175
- unless file
176
- raise ArgumentError, message(reader.name, "#{File.basename(alt, '.*')}.#{ext.first}", hint: 'not found')
177
- end
177
+ raise_error(reader.name, "#{File.basename(alt, '.*')}.#{ext.first}", hint: 'not found') unless file
178
178
  end
179
179
  project&.log&.info "#{Viewer}(#{type}) => #{file} {#{keys.join(', ')}}"
180
180
  doc = if reader.respond_to?(:load_file)
@@ -284,7 +284,7 @@ module Squared
284
284
  end
285
285
 
286
286
  def warning?
287
- project ? project.warning : true
287
+ project && defined?(project.warning) == 'method' ? project.warning : true
288
288
  end
289
289
  end
290
290
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Squared
4
- VERSION = '0.0.5'
4
+ VERSION = '0.0.6'
5
5
  end