Sha256: 00de1e91516da7452c40596be203e254afdb867bf39c4c7ebb0d1d6c39154492

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

# -*- coding: utf-8 -*-
class Courier::Template::Base

  attr_accessor :name, :defaults

  def initialize(args)
    self.name = args[:name].to_sym or raise 'no template name defined'
    self.defaults={}
  end

  def get_text(args)
    raise 'Service is not defined' unless args[:service]
    args[:scope]=[:courier, args[:service].name] unless args[:scope]
    args[:cascade]=true unless args.has_key? :cascade
    I18n::translate(name, args )
  end

  def get(service)
    service = Courier.service(service) if service.is_a?(Symbol)
    name = service.name.to_sym
    raise "Not defined default value for #{service} in template #{self}" unless defaults.has_key? name
    defaults[name]
  end

  def set(service, val)
    service = Courier.service(service) if service.is_a?(Symbol)
    defaults[service.name.to_sym] = check_val(val)
  end

  def to_s
    "Courier::Template(#{name})"
  end

  def key
    name
  end

  private

  def check_val(val)
    raise "Value must be :on or :off" unless val==:on or val==:off
    val
  end


end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
courier-0.1.3 lib/courier/template/base.rb