Class: Assette::Reader::Base
- Inherits:
-
Object
- Object
- Assette::Reader::Base
- Defined in:
- lib/assette/reader.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Class Method Summary collapse
- .extension ⇒ Object
-
.inherited(subclass) ⇒ Object
Gets called twice currenlty, once on Class.new(Reader::Base) and once on the subclassing.
- .mime_type ⇒ Object
- .outputs ⇒ Object
- .set_extension(val = nil) ⇒ Object
- .set_outputs(val) ⇒ Object
Instance Method Summary collapse
- #compile ⇒ Object
-
#initialize(file) ⇒ Base
constructor
A new instance of Base.
- #text ⇒ Object
Constructor Details
#initialize(file) ⇒ Base
Returns a new instance of Base.
23 24 25 |
# File 'lib/assette/reader.rb', line 23 def initialize(file) @file = file end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
22 23 24 |
# File 'lib/assette/reader.rb', line 22 def file @file end |
Class Method Details
.extension ⇒ Object
49 50 51 52 53 |
# File 'lib/assette/reader.rb', line 49 def extension if m = self.inspect.match(/::(\w+)$/i) m[1].downcase end end |
.inherited(subclass) ⇒ Object
Gets called twice currenlty, once on Class.new(Reader::Base) and once on the subclassing. Gotta fix that
39 40 41 42 43 44 45 46 47 |
# File 'lib/assette/reader.rb', line 39 def inherited subclass return if subclass == Assette::Reader::Base || subclass.inspect =~ /#<Class/ if outputs Assette::Reader::OUTPUTS[outputs] |= [subclass] end subclass.set_extension end |
.mime_type ⇒ Object
86 87 88 |
# File 'lib/assette/reader.rb', line 86 def mime_type @mime_type ||= MIME::Types.type_for("test.#{extension}").first end |
.outputs ⇒ Object
55 56 57 |
# File 'lib/assette/reader.rb', line 55 def outputs end |
.set_extension(val = nil) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/assette/reader.rb', line 70 def set_extension val = nil if val raise ArgumentError, 'must set extension to a symbol' unless val.is_a?(Symbol) instance_eval <<-RUBY def extension #{val.inspect} end RUBY end if ex = extension Assette::Reader::ALL[ex] = self Assette::Reader::OUTPUT_MAP[ex] = outputs.to_s end end |
.set_outputs(val) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/assette/reader.rb', line 59 def set_outputs val raise ArgumentError, 'must set outputs to a symbol' unless val.is_a?(Symbol) instance_eval <<-RUBY def outputs #{val.inspect} end RUBY val end |
Instance Method Details
#compile ⇒ Object
31 32 33 |
# File 'lib/assette/reader.rb', line 31 def compile raise Exception, "You must implement the compile method for #{self.class.inspect}" end |
#text ⇒ Object
27 28 29 |
# File 'lib/assette/reader.rb', line 27 def text @file.text end |