Sha256: abaa5b646d6b4ff30657ad4c25238faaa008cc5f4717fd03fa84bcd9296a6bb6

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

module Qor
  module Test
    class Gem
      attr_accessor :name, :options, :gem_option

      def initialize(node, gem_option=nil)
        self.name = node.name.to_s
        self.gem_option = gem_option

        [:git, :path, :platforms].map do |type|
          if node.parent.is_node?(type)
            self.options = {type => node.parent.value}.merge(node.parent.options)
          end
        end
      end

      def to_s
        if gem_option.is_a?(Array) && gem_option.length > 0
          %{gem "#{name}", #{gem_option.map(&:inspect).join(", ")}}
        elsif !gem_option.nil? && !gem_option.is_a?(Array)
          %{gem "#{name}", #{gem_option.inspect}}
        elsif options.is_a?(Hash)
          %{gem "#{name}", #{options.inspect}}
        else
          %{gem "#{name}"}
        end
      end

      def self.parse(node)
        if node.data.is_a?(Array) && node.data[0].is_a?(Array)
          node.data.map do |gem_option|
            gem_option.map {|x| Gem.new(node, x) }
          end.flatten
        else
          Array(Gem.new(node, node.data))
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
qor_test-0.0.5 lib/qor_test/gem.rb
qor_test-0.0.4 lib/qor_test/gem.rb
qor_test-0.0.3 lib/qor_test/gem.rb
qor_test-0.0.2 lib/qor_test/gem.rb