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



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

def const
  @const
end

Instance Method Details

#cmdsObject



5
6
7
# File 'lib/dpl/provider/examples.rb', line 5

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

#configsObject



13
14
15
# File 'lib/dpl/provider/examples.rb', line 13

def configs
  examples.map(&:config)
end

#example(opts) ⇒ Object



67
68
69
70
71
72
# File 'lib/dpl/provider/examples.rb', line 67

def example(opts)
  return unless opts.any?

  opts = required_opts.concat(opts).uniq.compact
  Example.new(const, opts)
end

#examplesObject



17
18
19
# File 'lib/dpl/provider/examples.rb', line 17

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

#filter(opts) ⇒ Object



46
47
48
49
# File 'lib/dpl/provider/examples.rb', line 46

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

#fullObject



40
41
42
43
44
# File 'lib/dpl/provider/examples.rb', line 40

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

#full_configObject



9
10
11
# File 'lib/dpl/provider/examples.rb', line 9

def full_config
  full.config
end

#manyObject



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

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



51
52
53
54
# File 'lib/dpl/provider/examples.rb', line 51

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

#requiredObject



25
26
27
28
# File 'lib/dpl/provider/examples.rb', line 25

def required
  opts = required_opts
  example(opts)
end

#required_optsObject



79
80
81
# File 'lib/dpl/provider/examples.rb', line 79

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

#requiredsObject



21
22
23
# File 'lib/dpl/provider/examples.rb', line 21

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

#requireds_optsObject



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

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

#with_required(opts) ⇒ Object



56
57
58
59
60
# File 'lib/dpl/provider/examples.rb', line 56

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

#without_required(opts) ⇒ Object



62
63
64
65
# File 'lib/dpl/provider/examples.rb', line 62

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