Class: ViewAssets::PathInfo

Inherits:
String
  • Object
show all
Defined in:
lib/view_assets/path_info.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ PathInfo

Returns a new instance of PathInfo.



9
10
11
# File 'lib/view_assets/path_info.rb', line 9

def initialize(path)
  replace path
end

Instance Method Details

#==(pi) ⇒ Object



3
4
5
6
7
# File 'lib/view_assets/path_info.rb', line 3

def ==(pi)
  pi = PathInfo.new(pi) unless pi.kind_of?(PathInfo)

  self.rel.to_s == pi.rel.to_s
end

#absObject

alter path string

'lib.js'

>

'/path/to/app/public/:type/file.js'


21
22
23
24
25
26
# File 'lib/view_assets/path_info.rb', line 21

def abs
  return self if abs?

  # PathInfo.new("#{root}/#{with_ext? ? self : "#{self}.#{ext}" }")
  PathInfo.new("#{root}/#{self}")
end

#abs!Object



28
29
30
# File 'lib/view_assets/path_info.rb', line 28

def abs!
  replace abs
end

#abs?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/view_assets/path_info.rb', line 13

def abs?
  !match(/^#{root}/).nil?
end

#app?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/view_assets/path_info.rb', line 67

def app?
  rel.match(/^app\/(#{JS_PATH}|#{CSS_PATH})/)
end

#basenameObject



36
37
38
# File 'lib/view_assets/path_info.rb', line 36

def basename
  PathInfo.new(with_ext? ? chomp(File.extname(self)) : self)
end

#depthObject

PathInfo.new(‘lib/javascripts/file.js’).depth # => 0 PathInfo.new(‘app/javascripts/controller/action/file.js’).depth # => 2 PathInfo.new(‘/path/to/my/app/public/lib/javascripts/file.js’).depth # => 0



74
75
76
# File 'lib/view_assets/path_info.rb', line 74

def depth
  rel.count("/") - 2
end

#lib?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/view_assets/path_info.rb', line 59

def lib?
  rel.match(/^lib\/(#{JS_PATH}|#{CSS_PATH})/)
end

#relObject

alter path string

 '/path/to/app/:dir/assets/:asset_type/file.js'
=>
 'file.js'


44
45
46
47
48
# File 'lib/view_assets/path_info.rb', line 44

def rel
  return self unless abs?

  PathInfo.new(gsub(/^#{root}\//, ''))
end

#rel!Object



50
51
52
53
# File 'lib/view_assets/path_info.rb', line 50

def rel!
  replace rel
  self
end

#rootObject



55
56
57
# File 'lib/view_assets/path_info.rb', line 55

def root
  "#{Rails.public_path}"
end

#vendor?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/view_assets/path_info.rb', line 63

def vendor?
  rel.match(/^vendor\/(#{JS_PATH}|#{CSS_PATH})/)
end

#with_ext?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/view_assets/path_info.rb', line 32

def with_ext?
  !!match(/\.(#{JS_EXT}|#{CSS_EXT})$/)
end