Class: BrainDamage::View::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/brain_damage/lib/views/factory.rb

Class Method Summary collapse

Class Method Details

.create(type, field, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/generators/brain_damage/lib/views/factory.rb', line 6

def self.create(type, field, options = {})
  if options.is_a? Symbol
    subtype = options
    options = { type: options }
  else
    subtype = options[:type]
  end

  type = type.to_s
  subtype = subtype.to_s

  if File.exists?  __dir__+"/#{type.pluralize}/#{subtype}.rb"
    require_relative "#{type.pluralize}/#{subtype}"
    eval("#{type.camelize.singularize}::#{subtype.camelize}").new field, options

  else
    require_relative "#{type.pluralize}/base"
    options[:template_file] = "#{subtype.underscore}.html.haml"
    eval("#{type.camelize.singularize}::Base").new field, options
  end
end