Class: Charyf::Extension

Inherits:
Object show all
Includes:
Initializable
Defined in:
lib/charyf/utils/extension.rb,
lib/charyf/utils/extension/configurable.rb,
lib/charyf/utils/extension/configuration.rb

Direct Known Subclasses

AppEngine

Defined Under Namespace

Modules: Configurable Classes: Configuration

Constant Summary collapse

ABSTRACT =
%w(Charyf::Extension Charyf::AppEngine Charyf::Application)

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Initializable

included, #initializers, #run_initializers

Constructor Details

#initializeExtension

End of self



86
87
88
89
90
# File 'lib/charyf/utils/extension.rb', line 86

def initialize #:nodoc:
  if self.class.abstract?
    raise "#{self.class.name} is abstract, you cannot instantiate it directly."
  end
end

Class Method Details

.abstract?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/charyf/utils/extension.rb', line 15

def abstract?
  ABSTRACT.include?(name)
end

.extension_name(name = nil) ⇒ Object



39
40
41
42
# File 'lib/charyf/utils/extension.rb', line 39

def extension_name(name = nil)
  @extension_name = name.to_s if name
  @extension_name ||= generate_extension_name(self.name)
end

.generators(&blk) ⇒ Object



29
30
31
# File 'lib/charyf/utils/extension.rb', line 29

def generators(&blk)
  register_block_for(:generators, &blk)
end

.inherited(base) ⇒ Object



23
24
25
26
27
# File 'lib/charyf/utils/extension.rb', line 23

def inherited(base)
  unless base.abstract?
    subclasses << base
  end
end

.instanceObject

Since Charyf::Extension cannot be instantiated, any methods that call instance are intended to be called only on subclasses of a Extension.



35
36
37
# File 'lib/charyf/utils/extension.rb', line 35

def instance
  @instance ||= new
end

.subclassesObject



19
20
21
# File 'lib/charyf/utils/extension.rb', line 19

def subclasses
  @subclasses ||= []
end

Instance Method Details

#configObject

This is used to create the config object on Extensions, an instance of Extension::Configuration, that is used by Extensions and Application to store related configuration.



107
108
109
# File 'lib/charyf/utils/extension.rb', line 107

def config
  @config ||= Charyf::Extension::Configuration.new
end

#configure(&block) ⇒ Object

:nodoc:



96
97
98
# File 'lib/charyf/utils/extension.rb', line 96

def configure(&block) #:nodoc:
  instance_eval(&block)
end

#extension_name(name) ⇒ Object



92
93
94
# File 'lib/charyf/utils/extension.rb', line 92

def extension_name(name)
  self.class.extension_name(name)
end

#extension_namespaceObject

:nodoc:



100
101
102
# File 'lib/charyf/utils/extension.rb', line 100

def extension_namespace #:nodoc:
  @extension_namespace ||= self.class.parents.detect { |n| n.respond_to?(:extension_namespace) }
end