Class: Assets::Rule::Concat

Inherits:
Assets::Rule show all
Defined in:
lib/assets/rule/concat.rb

Overview

Rule that concatenates assets from other rules

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Assets::Rule

#asset, #fresh_at?, #rename

Instance Attribute Details

#mimeMime (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return mime

Returns:



21
22
23
# File 'lib/assets/rule/concat.rb', line 21

def mime
  @mime
end

#nameString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return name

Returns:

  • (String)


13
14
15
# File 'lib/assets/rule/concat.rb', line 13

def name
  @name
end

Class Method Details

.build(name, *rules) ⇒ Rule::Concat

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build concat rules

Parameters:

  • name (String)

Returns:



43
44
45
# File 'lib/assets/rule/concat.rb', line 43

def self.build(name, *rules)
  new(name, rules)
end

.detect_mime(rules) ⇒ Mime

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Detect mime type

Parameters:

  • rules (Rules)

Returns:



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/assets/rule/concat.rb', line 83

def self.detect_mime(rules)
  raise "No mime type for empty rules" if rules.empty?

  mime = rules.first.mime

  unless rules.all? { |rule| rule.mime == mime }
    raise 'Rules do not share mime type!'
  end

  mime
end

.new(name, rules) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Instantiate object

Parameters:

  • name (String)
  • rules (Enumerable<Rule>)


30
31
32
33
# File 'lib/assets/rule/concat.rb', line 30

def self.new(name, rules)
  mime = detect_mime(rules)
  super(name, mime, rules)
end

Instance Method Details

#bodyString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return body

Returns:

  • (String)


53
54
55
# File 'lib/assets/rule/concat.rb', line 53

def body
  rules.map(&:body).join
end

#updated_atTime

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return updated_at

Returns:

  • (Time)


63
64
65
66
67
68
69
70
71
72
73
# File 'lib/assets/rule/concat.rb', line 63

def updated_at
  rules = self.rules
  time = rules.first.updated_at
  rules.each do |rule|
    updated_at = rule.updated_at
    if time < updated_at
      time = updated_at
    end
  end
  time
end