Class: Sphere::Package::Base
- Inherits:
-
Object
- Object
- Sphere::Package::Base
- Defined in:
- lib/sphere/package/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #compile(options = {}) ⇒ Object
- #file ⇒ Object
-
#initialize(name, sources) ⇒ Base
constructor
A new instance of Base.
- #out_of_date? ⇒ Boolean
- #public_file_name ⇒ Object
- #source_files ⇒ Object
- #source_urls ⇒ Object
- #sources ⇒ Object
Constructor Details
#initialize(name, sources) ⇒ Base
Returns a new instance of Base.
11 12 13 14 |
# File 'lib/sphere/package/base.rb', line 11 def initialize(name, sources) @name = name @sources = sources end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/sphere/package/base.rb', line 9 def name @name end |
Class Method Details
.extension ⇒ Object
5 6 7 |
# File 'lib/sphere/package/base.rb', line 5 def self.extension raise "Abstract Method" end |
Instance Method Details
#compile(options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sphere/package/base.rb', line 28 def compile( = {}) unless out_of_date? STDOUT.puts "unchanged #{public_file_name}" if [:verbose] == true return unless [:force] == true end STDOUT.puts "\e[32m compile #{public_file_name}\e[0m" if [:verbose] == true content = "" .each do |source| content << open(source).read end content = compress(content) if Sphere.config.compress? FileUtils.mkdir_p(File.dirname(file)) file.open('w') {|f| f.write(content) } end |
#file ⇒ Object
16 17 18 |
# File 'lib/sphere/package/base.rb', line 16 def file @file ||= Sphere.config.asset_root.join("#{name}.#{self.class.extension}") end |
#out_of_date? ⇒ Boolean
24 25 26 |
# File 'lib/sphere/package/base.rb', line 24 def out_of_date? !file.exist? || mtime > file.mtime end |
#public_file_name ⇒ Object
20 21 22 |
# File 'lib/sphere/package/base.rb', line 20 def public_file_name file.to_s.sub "#{Sphere.config.public_path}/", '' end |
#source_files ⇒ Object
51 52 53 |
# File 'lib/sphere/package/base.rb', line 51 def source_files - source_urls end |
#source_urls ⇒ Object
55 56 57 |
# File 'lib/sphere/package/base.rb', line 55 def source_urls .select {|s| url?(s) } end |
#sources ⇒ Object
45 46 47 48 49 |
# File 'lib/sphere/package/base.rb', line 45 def sources @sources.map do |source| url?(source) ? source : relative_paths(source) end.flatten end |