Sha256: 0c65c34df99d8a3c50d138e22d5a31daf3ff2694b43b3611661bbe21bb555d0d

Contents?: true

Size: 1.2 KB

Versions: 13

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module PraxisGen
  class Model < Thor
    require 'active_support/inflector'
    include Thor::Actions

    def self.source_root
      "#{File.dirname(__FILE__)}/templates/generator/scaffold"
    end

    desc 'gmodel', 'Generates a skeleton model file under app/models for ActiveRecord or Sequel.'
    argument :model_name, required: true
    option :orm, required: false, default: 'activerecord', enum: %w[activerecord sequel]
    def g
      # self.class.check_name(model_name)
      template_file = \
        if options[:orm] == 'activerecord'
          'models/active_record.rb'
        else
          'models/sequel.rb'
        end
      puts "Generating Model for #{model_name}"
      template template_file, "app/models/#{model_name}.rb"
      nil
    end
    # Helper functions (which are available in the ERB contexts)
    no_commands do
      def model_class
        model_name.camelize
      end
    end

    # TODO: do we want the argument to be camelcase? or snake case?
    def self.check_name(name)
      sanitized = name.downcase.gsub(/[^a-z0-9_]/, '')
      raise 'Please use only downcase letters, numbers and underscores for the model' unless sanitized == name
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
praxis-2.0.pre.31 tasks/thor/model.rb
praxis-2.0.pre.30 tasks/thor/model.rb
praxis-2.0.pre.29 tasks/thor/model.rb
praxis-2.0.pre.28 tasks/thor/model.rb
praxis-2.0.pre.27 tasks/thor/model.rb
praxis-2.0.pre.26 tasks/thor/model.rb
praxis-2.0.pre.25 tasks/thor/model.rb
praxis-2.0.pre.24 tasks/thor/model.rb
praxis-2.0.pre.23 tasks/thor/model.rb
praxis-2.0.pre.22 tasks/thor/model.rb
praxis-2.0.pre.21 tasks/thor/model.rb
praxis-2.0.pre.20 tasks/thor/model.rb
praxis-2.0.pre.19 tasks/thor/model.rb