Class: Dpl::Examples
- Inherits:
-
Struct
- Object
- Struct
- Dpl::Examples
- Defined in:
- lib/dpl/provider/examples.rb
Instance Attribute Summary collapse
-
#const ⇒ Object
Returns the value of attribute const.
Instance Method Summary collapse
- #cmds ⇒ Object
- #configs ⇒ Object
- #example(opts) ⇒ Object
- #examples ⇒ Object
- #filter(opts) ⇒ Object
- #full ⇒ Object
- #full_config ⇒ Object
- #many ⇒ Object
- #order(opts) ⇒ Object
- #required ⇒ Object
- #required_opts ⇒ Object
- #requireds ⇒ Object
- #requireds_opts ⇒ Object
- #with_required(opts) ⇒ Object
- #without_required(opts) ⇒ Object
Instance Attribute Details
#const ⇒ Object
Returns the value of attribute const
4 5 6 |
# File 'lib/dpl/provider/examples.rb', line 4 def const @const end |
Instance Method Details
#cmds ⇒ Object
5 6 7 |
# File 'lib/dpl/provider/examples.rb', line 5 def cmds examples.map(&:cmd).join("\n") end |
#configs ⇒ Object
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 |
#examples ⇒ Object
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 |
#full ⇒ Object
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_config ⇒ Object
9 10 11 |
# File 'lib/dpl/provider/examples.rb', line 9 def full_config full.config end |
#many ⇒ Object
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 |
#required ⇒ Object
25 26 27 28 |
# File 'lib/dpl/provider/examples.rb', line 25 def required opts = required_opts example(opts) end |
#required_opts ⇒ Object
79 80 81 |
# File 'lib/dpl/provider/examples.rb', line 79 def required_opts const.opts.select(&:required?) end |
#requireds ⇒ Object
21 22 23 |
# File 'lib/dpl/provider/examples.rb', line 21 def requireds requireds_opts.map { |opts| example(opts) } end |
#requireds_opts ⇒ Object
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 |