Class: Yutani::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/yutani/reference.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = '.', t, n, a) ⇒ Reference

Returns a new instance of Reference.



8
9
10
11
12
13
# File 'lib/yutani/reference.rb', line 8

def initialize(path='.', t, n, a)
  @path       = path
  @t          = t
  @n          = n
  @a          = a
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/yutani/reference.rb', line 6

def path
  @path
end

Instance Method Details

#attrObject



29
30
31
# File 'lib/yutani/reference.rb', line 29

def attr
  @a
end

#find_matching_resources_in_module!(mod) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/yutani/reference.rb', line 33

def find_matching_resources_in_module!(mod)
  resolutions = []
  # we currently support strings for t n and a, and regex
  # for n only
  mod.resources.each do |resource|
    if resource.resource_type == self.resource_type.to_sym
      case self.resource_name
      when Regexp
        if resource.resource_name =~ self.resource_name
          resolutions.push(resource)
        end
      when Symbol
        if resource.resource_name == self.resource_name.to_sym
          resolutions.push(resource)
        end
      else
        raise "unsupported class #{self.resource_name.class}"
      end
    end
  end

  resolutions
end

#relative_path(source_mod) ⇒ Object



15
16
17
18
19
# File 'lib/yutani/reference.rb', line 15

def relative_path(source_mod)
  source_path = Pathname.new(source_mod.path)
  target_path = Pathname.new(@path)
  target_path.relative_path_from(source_path).to_s
end

#resource_nameObject



25
26
27
# File 'lib/yutani/reference.rb', line 25

def resource_name
  @n
end

#resource_typeObject



21
22
23
# File 'lib/yutani/reference.rb', line 21

def resource_type
  @t
end