Class: Bgem::Output::Ext

Inherits:
Object
  • Object
show all
Defined in:
lib/bgem.rb

Defined Under Namespace

Modules: Common, StandardHooks

Class Method Summary collapse

Class Method Details

.file_extensionsObject



152
153
154
# File 'lib/bgem.rb', line 152

def self.file_extensions
  Exts.constants.map &:downcase
end

.new(file_extension:, type:, name:, dir:, code:) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/bgem.rb', line 156

def self.new file_extension:, type:, name:, dir:, code:
  parent_constant = Exts.const_get file_extension.upcase

  type ||= if parent_constant.respond_to? :default
             parent_constant.default
           else
             'default'
           end
  constant_name = type.capitalize

  if parent_constant.const_defined? constant_name
    child_constant = parent_constant.const_get constant_name
  else
    fail "Don't know what to do with '#{type}'. #{parent_constant}::#{constant_name} is not defined."
  end

  child_constant.new file_extension: file_extension, type: type, name: name, dir: dir, code: code
end