Class: Dpl::Examples

Inherits:
Struct
  • Object
show all
Defined in:
lib/dpl/provider/examples.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#constObject

Returns the value of attribute const

Returns:

  • (Object)

    the current value of const



2
3
4
# File 'lib/dpl/provider/examples.rb', line 2

def const
  @const
end

Instance Method Details

#cmdsObject



3
4
5
# File 'lib/dpl/provider/examples.rb', line 3

def cmds
  examples.map(&:cmd).join("\n")
end

#configsObject



11
12
13
# File 'lib/dpl/provider/examples.rb', line 11

def configs
  examples.map(&:config)
end

#example(opts) ⇒ Object



65
66
67
68
69
# File 'lib/dpl/provider/examples.rb', line 65

def example(opts)
  return unless opts.any?
  opts = required_opts.concat(opts).uniq.compact
  Example.new(const, opts)
end

#examplesObject



15
16
17
# File 'lib/dpl/provider/examples.rb', line 15

def examples
  [requireds, required, many].flatten.compact.uniq
end

#filter(opts) ⇒ Object



44
45
46
47
# File 'lib/dpl/provider/examples.rb', line 44

def filter(opts)
  opts = opts.reject(&:internal?)
  opts.reject { |opt| opt.name == :help }
end

#fullObject



38
39
40
41
42
# File 'lib/dpl/provider/examples.rb', line 38

def full
  opts = const.opts.opts
  opts = filter(opts)
  example(opts)
end

#full_configObject



7
8
9
# File 'lib/dpl/provider/examples.rb', line 7

def full_config
  full.config
end

#manyObject



28
29
30
31
32
33
34
35
36
# File 'lib/dpl/provider/examples.rb', line 28

def many
  opts = const.opts.opts
  opts = order(opts)
  opts = without_required(opts)
  opts = with_required(opts)
  opts = filter(opts)
  opts = opts[0, 5]
  example(opts)
end

#order(opts) ⇒ Object



49
50
51
52
# File 'lib/dpl/provider/examples.rb', line 49

def order(opts)
  cmmn = const.superclass.opts.opts
  opts - cmmn + cmmn
end

#requiredObject



23
24
25
26
# File 'lib/dpl/provider/examples.rb', line 23

def required
  opts = required_opts
  example(opts)
end

#required_optsObject



76
77
78
# File 'lib/dpl/provider/examples.rb', line 76

def required_opts
  const.opts.select(&:required?)
end

#requiredsObject



19
20
21
# File 'lib/dpl/provider/examples.rb', line 19

def requireds
  requireds_opts.map { |opts| example(opts) }
end

#requireds_optsObject



71
72
73
74
# File 'lib/dpl/provider/examples.rb', line 71

def requireds_opts
  opts = const.required.flatten(1)
  opts.map { |keys| Array(keys).map { |key| const.opts[key] } }
end

#with_required(opts) ⇒ Object



54
55
56
57
58
# File 'lib/dpl/provider/examples.rb', line 54

def with_required(opts)
  requireds = requireds_opts.first || []
  opts = requireds + required_opts + opts
  opts.uniq
end

#without_required(opts) ⇒ Object



60
61
62
63
# File 'lib/dpl/provider/examples.rb', line 60

def without_required(opts)
  opts = opts - const.required.flatten.map { |key| const.opts[key] }
  opts - required_opts.map(&:opts)
end