Class: Tadpole::SectionProviders::SectionProvider
- Inherits:
-
Object
- Object
- Tadpole::SectionProviders::SectionProvider
- Defined in:
- lib/tadpole/providers/section_provider.rb
Direct Known Subclasses
ERBProvider, FileProvider, HamlProvider, MarkabyProvider, TemplateProvider
Constant Summary collapse
- EXTENSIONS =
[]
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#full_path ⇒ Object
Returns the value of attribute full_path.
-
#owner ⇒ Object
Returns the value of attribute owner.
Class Method Summary collapse
-
.path_suitable?(full_path) ⇒ Boolean
Override this if you want to provide another mechanism to detect that the path is suitable for use.
-
.provides?(object, basename) ⇒ String?
You don’t need to override this method unless you need custom functionality beyond checking if a file exists under one of the possible file extensions.
Instance Method Summary collapse
-
#initialize(full_path, owner = nil) ⇒ SectionProvider
constructor
A new instance of SectionProvider.
- #inspect ⇒ Object
- #method_missing(meth, *args, &block) ⇒ Object
- #render(locals = {}, &block) ⇒ Object abstract
Constructor Details
#initialize(full_path, owner = nil) ⇒ SectionProvider
Returns a new instance of SectionProvider.
44 45 46 47 48 |
# File 'lib/tadpole/providers/section_provider.rb', line 44 def initialize(full_path, owner = nil) self.full_path = full_path self.owner = owner self.content = File.read(full_path) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/tadpole/providers/section_provider.rb', line 52 def method_missing(meth, *args, &block) if owner..respond_to?(meth) owner.[meth] elsif owner.respond_to?(meth) owner.send(meth, *args, &block) else super end end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
14 15 16 |
# File 'lib/tadpole/providers/section_provider.rb', line 14 def content @content end |
#full_path ⇒ Object
Returns the value of attribute full_path.
14 15 16 |
# File 'lib/tadpole/providers/section_provider.rb', line 14 def full_path @full_path end |
#owner ⇒ Object
Returns the value of attribute owner.
14 15 16 |
# File 'lib/tadpole/providers/section_provider.rb', line 14 def owner @owner end |
Class Method Details
.path_suitable?(full_path) ⇒ Boolean
Override this if you want to provide another mechanism to detect that the path is suitable for use. Default just checks File.file?(full_path)
35 36 37 |
# File 'lib/tadpole/providers/section_provider.rb', line 35 def self.path_suitable?(full_path) File.file?(full_path) end |
.provides?(object, basename) ⇒ String?
You don’t need to override this method unless you need custom functionality beyond checking if a file exists under one of the possible file extensions.
24 25 26 27 28 29 30 |
# File 'lib/tadpole/providers/section_provider.rb', line 24 def self.provides?(object, basename) self.const_get("EXTENSIONS").any? do |ext| path = basename + ext return path if path_suitable?(path) end nil end |
Instance Method Details
#inspect ⇒ Object
50 |
# File 'lib/tadpole/providers/section_provider.rb', line 50 def inspect; "#<%s:0x%s>" % [self.class.to_s.split('::').last, object_id.to_s(16)] end |
#render(locals = {}, &block) ⇒ Object
40 41 42 |
# File 'lib/tadpole/providers/section_provider.rb', line 40 def render(locals = {}, &block) raise NotImplementedError, "abstract class" end |