Class: Dpl::Support::Gems::Parse
- Inherits:
-
Struct
- Object
- Struct
- Dpl::Support::Gems::Parse
- Defined in:
- lib/dpl/support/gems.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
Instance Method Summary collapse
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code
28 29 30 |
# File 'lib/dpl/support/gems.rb', line 28 def code @code end |
Instance Method Details
#gems ⇒ Object
29 30 31 32 |
# File 'lib/dpl/support/gems.rb', line 29 def gems return [] unless sexp walk(*sexp).flatten.each_slice(3).to_a end |
#sexp ⇒ Object
67 68 69 |
# File 'lib/dpl/support/gems.rb', line 67 def sexp Ripper.sexp(code) end |
#walk(key, *nodes) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/dpl/support/gems.rb', line 34 def walk(key, *nodes) case key when :program nodes[0].map { |node| walk(*node) }.compact when :module walk(*nodes[1]) when :class walk(*nodes[2]) when :bodystmt nodes[0].map { |node| walk(*node) }.compact when :command walk(*nodes[1]) if nodes[0][1] == 'gem' when :args_add_block args = nodes[0].map { |node| walk(*node) } opts = args.last.is_a?(Hash) ? args.pop : {} name, version = *args [name, version, opts] when :bare_assoc_hash walk(*nodes[0][0]) when :assoc_new [nodes.map { |node| walk(*node) }].to_h when :@label nodes.first.sub(':', '').to_sym when :string_literal walk(*nodes[0]) when :string_content nodes[0][1] # when :void_stmt # else # raise key.to_s end end |