Sha256: 82e950c394011f171e0b37886b12274fd57bc2b3517be3b0f066e6825f27b030

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

# -*- encoding : utf-8 -*-

module Cardio
  module Generators
    # generate set module files
    class SetGenerator < ModBase
      source_root File.expand_path("templates", __dir__)

      argument :name, type: :string, banner: "MOD"
      argument :set_pattern, required: true
      argument :anchors, required: true, type: :array, banner: "[ANCHOR1] [ANCHOR2]"

      class_option "spec-only", type: :boolean,
                                default: false, group: :runtime,
                                desc: "create only spec file"

      def create_files
        template "set_template.erb", set_path unless options["spec-only"]
        template "set_spec_template.erb", set_path("spec")
      end

      private

      def set_path modifier=nil
        suffix = modifier ? "_#{modifier}" : nil
        filename = "#{anchors.last}#{suffix}.rb"
        dirs = anchors[0..-2]
        path_parts = [mod_path, modifier, "set", set_pattern, dirs, filename]
        File.join(*path_parts.compact)
      end

      def module_class_string
        "Card::Set::#{set_pattern.camelize}::#{anchors.map(&:camelize).join '::'}"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
card-1.108.1 lib/generators/set/set_generator.rb
card-1.108.0 lib/generators/set/set_generator.rb