Class: Tadpole::SectionProviders::SectionProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/tadpole/providers/section_provider.rb

Constant Summary collapse

EXTENSIONS =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.options.respond_to?(meth)
    owner.options[meth]
  elsif owner.respond_to?(meth)
    owner.send(meth, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



14
15
16
# File 'lib/tadpole/providers/section_provider.rb', line 14

def content
  @content
end

#full_pathObject

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

#ownerObject

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)

Returns:

  • (Boolean)


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.

Returns:

  • (String, nil)

    The full pathname



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

#inspectObject



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

This method is abstract.

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/tadpole/providers/section_provider.rb', line 40

def render(locals = {}, &block) 
  raise NotImplementedError, "abstract class"
end