Module: Ironfan::CookbookRequirements

Extended by:
Gorillib::Concern
Included in:
Dsl
Defined in:
lib/ironfan/cookbook_requirements.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#_cookbook_reqsObject


41
42
43
44
45
46
47
48
# File 'lib/ironfan/cookbook_requirements.rb', line 41

def _cookbook_reqs
  [
   *shallow_cookbook_reqs,
   *child_cookbook_reqs
  ].group_by(&:name).values.map do |group|
    group.inject{ |result, req| join_req(result, req) }
  end
end

#childrenObject


33
34
35
# File 'lib/ironfan/cookbook_requirements.rb', line 33

def children
  []
end

#cookbook_req(name, constraint) ⇒ Object


29
30
31
# File 'lib/ironfan/cookbook_requirements.rb', line 29

def cookbook_req(name, constraint)
  (@cookbook_reqs ||= []) << self.class.new_req(name, constraint)
end

#cookbook_reqsObject


37
38
39
# File 'lib/ironfan/cookbook_requirements.rb', line 37

def cookbook_reqs
  Hash[_cookbook_reqs.map{ |x| [x.name, x.constraint] }]
end

#join_req(req1, req2) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ironfan/cookbook_requirements.rb', line 6

def join_req(req1, req2)
  # order requirements by operation: =, >=, ~>
  req1, req2       = (req1.constraint < req2.constraint) ? [req1, req2] : [req2, req1]
  cn1, cn2         = [req1.constraint, req2.constraint]
  vers1, vers2     = [cn1.split.last, cn2.split.last]
  vers1_c, vers2_c = [vers1.split('.'), vers2.split('.')]
  op1, op2         = [req1, req2].map{ |x| x.constraint.split.first }

  if    op1 == '='  && op2 == '='
    join_eq_eq(req1, req2)
  elsif op1 == '>=' && op2 == '>='
    join_geq_geq(req1, req2)
  elsif op1 == '~>' && op2 == '~>'
    join_agt_agt(req1, req2)
  elsif op1 == '='  && op2 == '>='
    join_eq_gte(req1, req2)
  elsif op1 == '='  && op2 == '~>'
    join_eq_agt(req1, req2)
  elsif op1 == '>=' && op2 == '~>'
    join_gte_agt(req1, req2)
  end
end