output_mode 1.5.1 → 1.5.2

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: f4492bb6d42dfd55f9f83ba7a3fd7fa9b21a2712760272cbd1d3500dafc11dd4
4
- data.tar.gz: 71068e9161e4219ab85508a6692046f2de51d19a83c685b40fa9212ac0d40c46
3
+ metadata.gz: a4518dd66cf4b3d2a7ea9ea255c3a5835a6075eea24f62620b39f62b405a625b
4
+ data.tar.gz: bdcd16455d48e576ce18ea2793613b99bef8424ce9c504aff210f1f7a62e7f2e
5
5
  SHA512:
6
- metadata.gz: 05d68669d5abbb2ac911531c8709d4d44898fcaae4fced442d5bf8ffc2d935d5c2ef8319bc2b28cb5e33fb7b033b236c57992d449b1de4c69f667b3248c8d08f
7
- data.tar.gz: c6aae6fc8496bb491b4213173c4fc7bd57499efd9f2ec1e4367f3ec46b849c6be41453f17065c44a0b687aa40c1b6d1c677fe9578ad3dea11f8a92e31722f78a
6
+ metadata.gz: d622a5d10d8e93d2787fa7fa7916e43d984af483181c52158ab747d3556196d97fa2425da9d99538bb1d4b193d14c75d1a77763a3ba2de336312666af8350409
7
+ data.tar.gz: 56f15aa86585eb8c6c7ba598d8780b597649305453162574e14b0116257a62ad2689e68daadb29328eb4c58f51a15e7737cf62650ea7f326bcf18c04c1bf2687
@@ -56,13 +56,19 @@ module OutputMode
56
56
  @callables.each(&block)
57
57
  end
58
58
 
59
- def pad_each(key = :header, *ctx)
59
+ def pad_each(*ctx, **input_opts)
60
60
  fields = self.map do |callables|
61
- field = callables.config[key]
62
- if field.respond_to?(:call) && ctx.empty?
63
- raise Error, 'Can not pad dynamic fields without a context'
64
- elsif field.respond_to?(:call)
65
- field.call(*ctx).to_s
61
+ field = callables.config[:header]
62
+ if field.respond_to?(:call)
63
+ opts = if field.parameters.include?(:keyrest)
64
+ input_opts.dup
65
+ else
66
+ keys = field.parameters
67
+ .select { |type, _| [:key, :keyreq].include?(type) }
68
+ .map { |_, k| k }
69
+ input_opts.slice(*keys)
70
+ end
71
+ opts.empty? ? field.call(*ctx) : field.call(*ctx, **opts)
66
72
  else
67
73
  field.to_s
68
74
  end
@@ -76,7 +82,7 @@ module OutputMode
76
82
  end
77
83
 
78
84
  if block_given?
79
- pads.each { |*args| yield(*args) }
85
+ pads.each { |c, opts| yield(c, **opts) }
80
86
  else
81
87
  pads.each
82
88
  end
@@ -49,10 +49,9 @@ module OutputMode
49
49
  end
50
50
 
51
51
  # Yield each selected attribute
52
- objs = callables.pad_each.map do |callable, padding:|
52
+ objs = callables.pad_each(model, **output.context).map do |callable, padding:, field:|
53
53
  value = callable.generator(output).call(model)
54
- field = callable.config[:header]
55
- [value, {field: field, padding: padding }]
54
+ [value, { field: field, padding: padding }]
56
55
  end
57
56
 
58
57
  # Runs the provided block
@@ -39,7 +39,7 @@ module OutputMode
39
39
  # @param section: Define the grouping a callable belongs to. Ignored by default
40
40
  # @param modes: Additional modes flags for the callable
41
41
  # @yieldparam model The subject the column is describing, some sort of data model
42
- def register_callable(modes: {}, header:, verbose: nil, interactive: nil, section: :other, &b)
42
+ def register_callable(modes: {}, header:, verbose: nil, interactive: nil, section: :default, &b)
43
43
  modes = modes.map { |m| [m, true] }.to_h if modes.is_a? Array
44
44
  super(modes: modes.merge(verbose: verbose, interactive: interactive),
45
45
  header: header,
@@ -25,5 +25,5 @@
25
25
  #==============================================================================
26
26
 
27
27
  module OutputMode
28
- VERSION = "1.5.1"
28
+ VERSION = "1.5.2"
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: output_mode
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - William McCumsite
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-05 00:00:00.000000000 Z
11
+ date: 2021-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-table