Class: Qor::Test::Gem

Inherits:
Object
  • Object
show all
Defined in:
lib/qor_test/gem.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, gem_option = nil) ⇒ Gem

Returns a new instance of Gem.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/qor_test/gem.rb', line 6

def initialize(node, gem_option=nil)
  self.name = node.name.to_s
  self.options = gem_option.is_a?(Array) ? gem_option : [gem_option]

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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/qor_test/gem.rb', line 4

def name
  @name
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/qor_test/gem.rb', line 4

def options
  @options
end

Class Method Details

.parse(node) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/qor_test/gem.rb', line 28

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

Instance Method Details

#to_sObject



22
23
24
25
26
# File 'lib/qor_test/gem.rb', line 22

def to_s
  result = %{gem "#{name}"}
  result += %{, #{options.map(&:inspect).join(", ")}} if options.length > 0
  result
end