Sha256: 60cb0868918777a185f799c4df893060f0097e6bcd439a322a7c3201e1245302
Contents?: true
Size: 1.16 KB
Versions: 6
Compression:
Stored size: 1.16 KB
Contents
# frozen_string_literal: true 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] = (conf[:args] || []).map { |arg| arg.is_a?(Symbol) ? 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
6 entries across 6 versions & 1 rubygems