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
2 3 4 |
# File 'lib/dpl/provider/examples.rb', line 2 def const @const end |
Instance Method Details
#cmds ⇒ Object
3 4 5 |
# File 'lib/dpl/provider/examples.rb', line 3 def cmds examples.map(&:cmd).join("\n") end |
#configs ⇒ Object
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 |
#examples ⇒ Object
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 |
#full ⇒ Object
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_config ⇒ Object
7 8 9 |
# File 'lib/dpl/provider/examples.rb', line 7 def full_config full.config end |
#many ⇒ Object
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 |
#required ⇒ Object
23 24 25 26 |
# File 'lib/dpl/provider/examples.rb', line 23 def required opts = required_opts example(opts) end |
#required_opts ⇒ Object
76 77 78 |
# File 'lib/dpl/provider/examples.rb', line 76 def required_opts const.opts.select(&:required?) end |
#requireds ⇒ Object
19 20 21 |
# File 'lib/dpl/provider/examples.rb', line 19 def requireds requireds_opts.map { |opts| example(opts) } end |
#requireds_opts ⇒ Object
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 |