Sha256: b2d87423a8e8ad06bc0d67d71eaf01c68bbc88ca7087af4a41d48d5f30cc4968
Contents?: true
Size: 1.14 KB
Versions: 9
Compression:
Stored size: 1.14 KB
Contents
module I18n::Tasks module Command module DSL def self.included(base) base.module_eval do @dsl = Hash.new { |h, k| h[k] = {} } extend ClassMethods end end def t(*args) I18n.t(*args) end module ClassMethods def cmd(name, conf = nil) if conf conf = conf.dup conf[:args] = (args = conf[:args]) ? args.map { |arg| Symbol === arg ? arg(arg) : arg } : [] dsl(:cmds)[name] = conf else dsl(:cmds)[name] end end def arg(ref, *args) if args.present? dsl(:args)[ref] = args else dsl(:args)[ref] end end def cmds dsl(:cmds) end def dsl(key) @dsl[key] end # late-bound I18n.t for module bodies def t(*args) proc { I18n.t(*args) } end # if class is a module, merge DSL definitions when it is included def included(base) base.instance_variable_get(:@dsl).deep_merge!(@dsl) end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems