Class: PomPomPom::Pom

Inherits:
Object
  • Object
show all
Includes:
UrlBuilder
Defined in:
lib/pompompom/pom.rb

Constant Summary collapse

PROPERTIES =
[:group_id, :artifact_id, :version, :name, :description, :url, :packaging]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UrlBuilder

#append_slash, #file_url, #group_path, #jar_file_name, #jar_url, #metadata_url, #pom_url

Constructor Details

#initialize(io, defaults = {}) ⇒ Pom

Returns a new instance of Pom.



13
14
15
16
# File 'lib/pompompom/pom.rb', line 13

def initialize(io, defaults={})
  @io = io
  merge_defaults!(defaults)
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



11
12
13
# File 'lib/pompompom/pom.rb', line 11

def parent
  @parent
end

Instance Method Details

#artifact_idObject



43
44
45
# File 'lib/pompompom/pom.rb', line 43

def artifact_id
  @artifact_id || parent.artifact_id
end

#dependencies(scope = :default) ⇒ Object



27
28
29
# File 'lib/pompompom/pom.rb', line 27

def dependencies(scope = :default)
  @dependencies.fetch(scope, []).dup
end

#exclusionsObject



31
32
33
# File 'lib/pompompom/pom.rb', line 31

def exclusions
  []
end

#group_idObject



39
40
41
# File 'lib/pompompom/pom.rb', line 39

def group_id
  @group_id || parent.group_id
end

#has_parent?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/pompompom/pom.rb', line 35

def has_parent?
  !!parent
end

#merge(parent) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/pompompom/pom.rb', line 69

def merge(parent)
  defaults = Hash[*PROPERTIES.map { |p| [p, self.send(p) || parent.send(p)] }.flatten]
  defaults = defaults.merge(
    :parent => parent,
    :dependencies => @dependencies.dup,
    :dependency_management => @dependency_management.dup,
    :properties => @properties.dup
  )
  self.class.new(nil, defaults)
end

#parse!Object



18
19
20
21
22
23
24
25
# File 'lib/pompompom/pom.rb', line 18

def parse!
  doc = Hpricot.XML(@io)
  parse_properties!(doc)
  parse_meta!(doc)
  parse_parent!(doc)
  parse_dependency_management!(doc)
  parse_dependencies!(doc)
end

#propertiesObject



51
52
53
54
55
56
57
# File 'lib/pompompom/pom.rb', line 51

def properties
  if has_parent? && @parent.respond_to?(:properties)
    @parent.properties.merge(@properties)
  else
    @properties || {}
  end
end

#to_dependencyObject



59
60
61
62
63
64
65
66
67
# File 'lib/pompompom/pom.rb', line 59

def to_dependency
  Dependency.new(
    :group_id => group_id,
    :artifact_id => artifact_id, 
    :version => version, 
    :packaging => packaging,
    :dependencies => dependencies
  )
end

#to_sObject



80
81
82
# File 'lib/pompompom/pom.rb', line 80

def to_s
  to_dependency.to_s
end

#versionObject



47
48
49
# File 'lib/pompompom/pom.rb', line 47

def version
  @version || parent.version
end