Class: Extension

Inherits:
Object
  • Object
show all
Defined in:
lib/yodel/application/extension.rb

Direct Known Subclasses

FolderExtension, GemExtension

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExtension

Returns a new instance of Extension.



4
5
6
7
8
9
10
11
# File 'lib/yodel/application/extension.rb', line 4

def initialize
  @environment    = @name.end_with?('environment')
  @migrations_dir = File.join(@lib_dir, Yodel::MIGRATIONS_DIRECTORY_NAME)
  @public_dir     = File.join(@lib_dir, Yodel::PUBLIC_DIRECTORY_NAME)
  @layouts_dir    = File.join(@lib_dir, Yodel::LAYOUTS_DIRECTORY_NAME)
  @models_dir     = File.join(@lib_dir, Yodel::MODELS_DIRECTORY_NAME)
  Yodel.extensions[@name] = self
end

Instance Attribute Details

#layouts_dirObject (readonly)

Returns the value of attribute layouts_dir.



2
3
4
# File 'lib/yodel/application/extension.rb', line 2

def layouts_dir
  @layouts_dir
end

#lib_dirObject (readonly)

Returns the value of attribute lib_dir.



2
3
4
# File 'lib/yodel/application/extension.rb', line 2

def lib_dir
  @lib_dir
end

#migrations_dirObject (readonly)

Returns the value of attribute migrations_dir.



2
3
4
# File 'lib/yodel/application/extension.rb', line 2

def migrations_dir
  @migrations_dir
end

#models_dirObject (readonly)

Returns the value of attribute models_dir.



2
3
4
# File 'lib/yodel/application/extension.rb', line 2

def models_dir
  @models_dir
end

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/yodel/application/extension.rb', line 2

def name
  @name
end

#public_dirObject (readonly)

Returns the value of attribute public_dir.



2
3
4
# File 'lib/yodel/application/extension.rb', line 2

def public_dir
  @public_dir
end

Instance Method Details

#load!Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/yodel/application/extension.rb', line 13

def load!
  unless @environment
    require_extension
    Yodel.config.public_directories << @public_dir if File.directory?(@public_dir)
    Yodel.config.layout_directories << @layouts_dir if File.directory?(@layouts_dir)
    Yodel.config.extensions << self
  end
  
  # load any models. if the init.rb file exists it will be loaded instead,
  # allowing extensions to specify the order models are loaded.
  if File.exist?(@models_dir)
    init_file = File.join(@models_dir, 'init.rb')
    if File.exist?(init_file)
      require init_file
    else
      Dir[File.join(@models_dir, '**')].sort.each do |model|
        next if model.start_with?('.')
        require File.realpath(model, @models_dir)
      end
    end
  end
end