Sha256: 7bfa2fab5b4e35e175aeda27dd342ea74fe5727d241e1f0d2902f32f2d6f7075

Contents?: true

Size: 1.57 KB

Versions: 12

Compression:

Stored size: 1.57 KB

Contents

module I18n::Tasks
  module Command
    module DSL
      module EnumOpt
        def enum_opt(name, list = nil)
          if list
            dsl(:enum_valid)[name] = list
          else
            dsl(:enum_valid)[name]
          end
        end

        DEFAULT_ENUM_OPT_DESC = proc { |valid, default|
          I18n.t('i18n_tasks.cmd.enum_opt.desc', valid_text: valid, default_text: default)
        }

        def enum_opt_attr(short, long, valid, desc, error_msg)
          desc ||= DEFAULT_ENUM_OPT_DESC
          desc_proc = proc { desc.call(valid * ', ', I18n.t('i18n_tasks.cmd.args.default_text', value: valid.first)) }
          {short: short, long: long, desc: desc_proc,
           conf:  {default: valid.first, argument: true, optional: false},
           parse: enum_parse_proc(:parse_enum_opt, valid, &error_msg)}
        end

        DEFAULT_LIST_OPT_DESC = proc { |valid, default|
          I18n.t('i18n_tasks.cmd.enum_list_opt.desc', valid_text: valid, default_text: default)
        }

        def enum_list_opt_attr(short, long, valid, desc, error_msg)
          desc ||= DEFAULT_LIST_OPT_DESC
          desc_proc = proc { desc.call(valid * ', ', I18n.t('i18n_tasks.cmd.args.default_all')) }
          {short: short, long: long, desc: desc_proc,
           conf:  {as: Array, delimiter: /\s*[+:,]\s*/},
           parse: enum_parse_proc(:parse_enum_list_opt, valid, &error_msg)}
        end

        def enum_parse_proc(method, valid, &error)
          proc { |opt, key|
            opt[key] = send(method, opt[key], valid, &error)
          }
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
i18n-tasks-0.7.13 lib/i18n/tasks/command/dsl/enum_opt.rb
i18n-tasks-0.7.12 lib/i18n/tasks/command/dsl/enum_opt.rb
i18n-tasks-0.7.11 lib/i18n/tasks/command/dsl/enum_opt.rb
i18n-tasks-0.7.10 lib/i18n/tasks/command/dsl/enum_opt.rb
i18n-tasks-0.7.9 lib/i18n/tasks/command/dsl/enum_opt.rb
i18n-tasks-0.7.8 lib/i18n/tasks/command/dsl/enum_opt.rb
i18n-tasks-0.7.7 lib/i18n/tasks/command/dsl/enum_opt.rb
i18n-tasks-0.7.6 lib/i18n/tasks/command/dsl/enum_opt.rb
i18n-tasks-0.7.5 lib/i18n/tasks/command/dsl/enum_opt.rb
i18n-tasks-0.7.4 lib/i18n/tasks/command/dsl/enum_opt.rb
i18n-tasks-0.7.3 lib/i18n/tasks/command/dsl/enum_opt.rb
i18n-tasks-0.7.2 lib/i18n/tasks/command/dsl/enum_opt.rb