squared 0.0.3 → 0.0.4

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: ef428776d582a23bb5560efdc5c6f6d77fa5fb1adaecca5f11500b978126283a
4
- data.tar.gz: cd8dfbae3f5162b55fd081ac65e31f0e2fca1167d4932e52ccd723f128a1a312
3
+ metadata.gz: 1795e8352e8278c8f4e26ced26ac936ce906ee8e626a9cf2ff2bf6a86412f09c
4
+ data.tar.gz: '08b8e2538b6316ffb141c15e560187222cbb18e0a37f5c74af6ed5fda87e6dc3'
5
5
  SHA512:
6
- metadata.gz: e8bf3197a021dadc3bf8d15d4f80d5064a4254359a23b9e7576babe716189e0d17564acae48e018fc64b7caddde250f53eb479cae3e4997d7a3792fe66e07d5a
7
- data.tar.gz: 312231359e1bd8f7052c91250234750ba9c41f5be1b806e852c60517d4c04e8d4ef55450d1b65fb35a946b2c6138d83bccc8280587b6c5b9832d717fa377c84a
6
+ metadata.gz: a8d6bd537e66b744edd760ead7441aad45961bdc746e9ca81f577e8183893cd6209203f2ba507b5ab608bbf3ebe7a15aeb23aa84005a76bf10d0f3b3704c403d
7
+ data.tar.gz: 9a29c720ce14050bc604c9b561c376f55437865610827075dd6a2a961ce82b22c1f4b3fd303884186f9c59b1a330ed73ce14ad16169724c3578d8d4e01388bfe
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
4
+
3
5
  module Squared
4
6
  module Config
5
7
  class Viewer
@@ -16,13 +18,14 @@ module Squared
16
18
 
17
19
  attr_reader :name, :main, :project, :theme
18
20
 
19
- def initialize(main, name = nil, project: nil, opts: {}, auto: true, common: true)
21
+ def initialize(main, name = nil, project: nil, dump: nil, opts: {}, auto: true, common: true)
20
22
  if project
21
23
  main = @project.base_path(main).to_s if (@project = __get__(:project)[project.to_sym])
22
24
  @required = true
23
25
  end
24
26
  @name = name&.to_s || @project&.name
25
27
  @ext = File.extname(main)
28
+ @dump = dump
26
29
  @mime = {}
27
30
  @theme = common ? __get__(:theme)[:viewer] : {}
28
31
  if exist?
@@ -61,7 +64,6 @@ module Squared
61
64
  if @mime['json'] && (exist? || !::Rake::Task.task_defined?("#{name}:#{view}:json"))
62
65
  desc format_desc(view, %w[json])
63
66
  task :json, [:keys] do |_, args|
64
- require 'json'
65
67
  read_keys(JSON, 'json', *params.(args))
66
68
  end
67
69
  end
@@ -79,18 +81,17 @@ module Squared
79
81
  yield self if block_given?
80
82
  end
81
83
 
82
- def add(type, gem: nil, parse: nil, ext: [], opts: {}, command: 'view', file: nil)
84
+ def add(type, gem: nil, parse: nil, ext: nil, opts: {}, command: 'view', file: nil, exist: nil)
83
85
  return self if @mime.frozen?
84
86
 
85
87
  type = type.to_s
86
88
  if parse && enabled?
87
89
  require(gem || type)
88
90
  obj = eval(parse)
89
- ext = as_a(ext)
90
- ext << type if ext.empty?
91
+ ext << type if (ext = as_a(ext)).empty?
91
92
  file = realpath if file.nil? && exist?
92
93
  namespace name do
93
- desc format_desc(command, ext)
94
+ desc format_desc(command, ext, exist: exist)
94
95
  namespace command do
95
96
  task type, [:keys] do |_, args|
96
97
  if file
@@ -128,7 +129,7 @@ module Squared
128
129
  end
129
130
  end
130
131
  name ||= file.basename.to_s.chomp(File.extname(file))
131
- add(type, gem: gem, parse: parse, ext: ext, opts: opts, command: name, file: file)
132
+ add(type, gem: gem, parse: parse, ext: ext, opts: opts, command: name, file: file, exist: true)
132
133
  end
133
134
 
134
135
  def style(name, *args)
@@ -234,16 +235,14 @@ module Squared
234
235
  $2 ? ".#{s}" : "#{s}."
235
236
  end
236
237
  end
237
- out << [key, pipe? ? nil : 'undefined']
238
+ out << [key, pipe? ? JSON.dump(nil) : 'undefined']
238
239
  else
239
- out << [key, pipe? ? val : val.inspect]
240
+ out << [key, @dump == 'json' || pipe? ? JSON.dump(val) : val.inspect]
240
241
  end
241
- pad = key.size if key.size > pad
242
+ pad = [pad, key.size].max
242
243
  end
243
244
  if pipe?
244
- require 'json'
245
- out = out.map { |item| JSON.dump(item[1]) }
246
- puts out.join("\n")
245
+ puts out.map(&:last).join("\n")
247
246
  else
248
247
  out.map { |item| "#{item[0].ljust(pad)} : #{item[1]}" }
249
248
  end
@@ -264,8 +263,8 @@ module Squared
264
263
  end
265
264
  end
266
265
 
267
- def format_desc(command, ext)
268
- message(name, command, "#{ext.first}[#{exist? ? '' : "file?=#{File.basename(main)}.#{ext.last},"}keys*]")
266
+ def format_desc(command, ext, exist: exist?)
267
+ message(name, command, "#{ext.first}[#{exist ? '' : "file?=#{File.basename(main)}.#{ext.last},"}keys*]")
269
268
  end
270
269
 
271
270
  def realpath
@@ -71,7 +71,7 @@ module Squared
71
71
  when :install
72
72
  desc format_desc(action, flag)
73
73
  task flag do
74
- install flag
74
+ depend(flag, override: true)
75
75
  end
76
76
  when :outdated
77
77
  desc format_desc(action, flag, %w[prune dry-run], req: 'opts?')
@@ -134,10 +134,10 @@ module Squared
134
134
  end
135
135
  end
136
136
 
137
- def depend(flag = nil)
138
- if @depend
137
+ def depend(flag = nil, override: false)
138
+ if @depend && !override
139
139
  super
140
- else
140
+ elsif outdated?
141
141
  frozen = flag == :frozen
142
142
  force = flag == :force
143
143
  dedupe = flag == :dedupe
@@ -59,7 +59,7 @@ module Squared
59
59
  desc options.()
60
60
  end
61
61
  task flag do |_, args|
62
- install(flag, opts: collect_args(args, :opts))
62
+ depend(flag, opts: collect_args(args, :opts), override: true)
63
63
  end
64
64
  end
65
65
  end
@@ -68,8 +68,8 @@ module Squared
68
68
  end
69
69
  end
70
70
 
71
- def depend(flag = nil, opts: [])
72
- if @depend
71
+ def depend(flag = nil, opts: [], override: false)
72
+ if @depend && !override
73
73
  super
74
74
  elsif outdated?
75
75
  case install_type
@@ -7,7 +7,7 @@ module Squared
7
7
  REF = :ruby
8
8
  GEMFILE = %w[Gemfile Gemfile.lock gem.deps.rb Isolate].freeze
9
9
  OPT_INSTALL = %w[no-cache force quiet verbose].freeze
10
- OPT_UPDATE = %w[redownload local strict conservative quiet verbose].freeze
10
+ OPT_UPDATE = %w[redownload local strict conservative group=s quiet verbose].freeze
11
11
  private_constant :REF, :GEMFILE, :OPT_INSTALL, :OPT_UPDATE
12
12
 
13
13
  class << self
@@ -80,12 +80,12 @@ module Squared
80
80
  when :'with-g', :'without-g'
81
81
  desc format_desc(action, flag, 'group+')
82
82
  task flag, [:group] do |_, args|
83
- install(flag, group: collect_args(args, :group))
83
+ depend(flag, group: collect_args(args, :group), override: true)
84
84
  end
85
85
  else
86
86
  desc format_desc(action, flag, OPT_INSTALL)
87
87
  task flag, [:opts] do |_, args|
88
- install(flag, opts: collect_args(args, :opts))
88
+ depend(flag, opts: collect_args(args, :opts), override: true)
89
89
  end
90
90
  end
91
91
  when :update
@@ -106,10 +106,10 @@ module Squared
106
106
  end
107
107
  end
108
108
 
109
- def depend(flag = nil, opts: [], group: [])
110
- if @depend
109
+ def depend(flag = nil, opts: [], group: [], override: false)
110
+ if @depend && !override
111
111
  super
112
- else
112
+ elsif outdated?
113
113
  case flag
114
114
  when :redownload, :local, :'prefer-local'
115
115
  cmd = bundle_session 'install'
@@ -248,7 +248,9 @@ module Squared
248
248
  end
249
249
 
250
250
  def outdated?
251
- GEMFILE.any? { |file| base_path(file).exist? }
251
+ return @outdated unless @outdated.nil?
252
+
253
+ @outdated = GEMFILE.any? { |file| base_path(file).exist? }
252
254
  end
253
255
 
254
256
  def dev?
@@ -261,7 +263,13 @@ module Squared
261
263
  if (val = env('BUNDLE_JOBS')).to_i > 0
262
264
  @session << "-j#{val}"
263
265
  end
264
- list.each { |flag| @session << "--#{flag}" if opts.include?(flag) }
266
+ list.each do |flag|
267
+ if opts.include?(flag)
268
+ @session << "--#{flag}"
269
+ elsif /^g(?:roup)?=(.+)$/.match(flag)
270
+ @session << "--group=#{$1}"
271
+ end
272
+ end
265
273
  end
266
274
 
267
275
  def gem_session(*cmd)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Squared
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squared
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham