Class: Dpl::Example
- Inherits:
-
Struct
- Object
- Struct
- Dpl::Example
- Defined in:
- lib/dpl/provider/examples.rb
Instance Attribute Summary collapse
-
#const ⇒ Object
Returns the value of attribute const.
-
#opts ⇒ Object
Returns the value of attribute opts.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #cmd ⇒ Object
- #compact(hash) ⇒ Object
- #config ⇒ Object
- #name ⇒ Object
- #opts_for(opts) ⇒ Object
- #str_for(opt) ⇒ Object
- #strategy ⇒ Object
- #strs_for(opts) ⇒ Object
- #value_for(opt) ⇒ Object
Instance Attribute Details
#const ⇒ Object
Returns the value of attribute const
81 82 83 |
# File 'lib/dpl/provider/examples.rb', line 81 def const @const end |
#opts ⇒ Object
Returns the value of attribute opts
81 82 83 |
# File 'lib/dpl/provider/examples.rb', line 81 def opts @opts end |
Instance Method Details
#==(other) ⇒ Object
96 97 98 |
# File 'lib/dpl/provider/examples.rb', line 96 def ==(other) const == other.const && opts == other.opts end |
#cmd ⇒ Object
92 93 94 |
# File 'lib/dpl/provider/examples.rb', line 92 def cmd "dpl #{name} #{strs_for(opts)}" end |
#compact(hash) ⇒ Object
124 125 126 |
# File 'lib/dpl/provider/examples.rb', line 124 def compact(hash) hash.reject { |_, value| value.nil? } end |
#config ⇒ Object
82 83 84 85 86 |
# File 'lib/dpl/provider/examples.rb', line 82 def config config = opts_for(opts) config = config.merge(strategy: strategy) # hmm. compact(config) end |
#name ⇒ Object
100 101 102 |
# File 'lib/dpl/provider/examples.rb', line 100 def name const.registry_key.to_s.split(':').join(' ') end |
#opts_for(opts) ⇒ Object
104 105 106 |
# File 'lib/dpl/provider/examples.rb', line 104 def opts_for(opts) opts.map { |opt| [opt.name, value_for(opt)] }.to_h end |
#str_for(opt) ⇒ Object
112 113 114 |
# File 'lib/dpl/provider/examples.rb', line 112 def str_for(opt) "--#{opt.name} #{value_for(opt)}".strip end |
#strategy ⇒ Object
88 89 90 |
# File 'lib/dpl/provider/examples.rb', line 88 def strategy const.registry_key.to_s.split(':').last if const.registry_key.to_s.include?(':') end |
#strs_for(opts) ⇒ Object
108 109 110 |
# File 'lib/dpl/provider/examples.rb', line 108 def strs_for(opts) opts.map { |opt| str_for(opt) }.join(' ') end |
#value_for(opt) ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/dpl/provider/examples.rb', line 116 def value_for(opt) return if opt.type == :flag return 1 if opt.type == :integer return opt.enum.first if opt.enum? str = opt.strs.detect { |str| str =~ /^--#{opt.name} (.*)$/ } && $1 str ? str.downcase : 'str' end |