Sha256: b906b59d44d3f9ac2288a8c978669f1ecbed763b30cfb794484f73b4bd09cf29

Contents?: true

Size: 1.91 KB

Versions: 5

Compression:

Stored size: 1.91 KB

Contents

require 'thor'
require 'active_support/all'

module TogoStanza
  module CLI
    class ProviderGenerator < Thor::Group
      include Thor::Actions

      argument :name

      def self.source_root
        File.expand_path('../../../templates/provider', __FILE__)
      end

      def create_files
        template 'Gemfile.erb',   "#{name}/Gemfile"
        template 'config.ru.erb', "#{name}/config.ru"

        create_file "#{name}/log/.keep"
      end

      def init_repo
        inside name do
          run "bundle"
          run "git init ."
          run "git add -A"
        end
      end
    end

    class StanzaGenerator < Thor::Group
      include Thor::Actions

      argument :name

      def self.source_root
        File.expand_path('../../../templates/stanza', __FILE__)
      end

      def create_files
        template 'Gemfile.erb',      "#{file_name}/Gemfile"
        template 'gemspec.erb',      "#{file_name}/#{file_name}.gemspec"
        template 'lib.rb.erb',       "#{file_name}/lib/#{file_name}.rb"
        template 'stanza.rb.erb',    "#{file_name}/stanza.rb"
        template 'template.hbs.erb', "#{file_name}/template.hbs"
        template 'help.md.erb',      "#{file_name}/help.md"

        create_file "#{file_name}/assets/.keep"
      end

      def inject_gem
        append_to_file 'Gemfile', "gem '#{file_name}', path: './#{file_name}'\n"
      end

      private

      def stanza_id
        name.underscore.sub(/_stanza$/, '')
      end

      def file_name
        stanza_id + '_stanza'
      end

      def class_name
        file_name.classify
      end

      def title
        stanza_id.titleize
      end
    end

    class Stanza < Thor
      register StanzaGenerator, 'new', 'new NAME', 'Creates a new stanza'
    end

    class Root < Thor
      register ProviderGenerator, 'init', 'init NAME', 'Creates a new provider'

      desc 'stanza [COMMAND]', ''
      subcommand 'stanza', Stanza
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
togostanza-0.1.0 lib/togostanza/cli.rb
togostanza-0.0.9 lib/togostanza/cli.rb
togostanza-0.0.8 lib/togostanza/cli.rb
togostanza-0.0.7 lib/togostanza/cli.rb
togostanza-0.0.6 lib/togostanza/cli.rb