Class: Rpictogrify::Theme

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

Class Method Summary collapse

Class Method Details

.find(ident) ⇒ Object



12
13
14
15
16
17
# File 'lib/rpictogrify/theme.rb', line 12

def find(ident)
  theme_name = Rpictogrify::Inflector.camelize(ident.to_s)
  Object.const_get("Rpictogrify::Themes::#{theme_name}")
rescue NameError
  raise ArgumentError.new('The ident argument must be one of themes: avataars_female, avataars_male, male_flat, monsters')
end

.register(ident, assets_path:) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rpictogrify/theme.rb', line 19

def register(ident, assets_path:)
  define_class_context = ->(binding) do
    @@assets_path = assets_path
    def assets_path
      Pathname.new(@@assets_path)
    end
  end

  theme_name  = Rpictogrify::Inflector.camelize(ident.to_s)
  theme_class = "Rpictogrify::Themes::#{theme_name}"
  if Object.const_defined?(theme_class)
    Object.const_get(theme_class).class_eval(&define_class_context)
  else
    Rpictogrify::Themes.const_set(theme_name, Class.new(Rpictogrify::Themes::Base, &define_class_context))
  end
end