Sha256: 9320bb27bdbe79be16904d17c7deb1b2bfefa9309ac6cd75316076d614642cb9

Contents?: true

Size: 1.21 KB

Versions: 8

Compression:

Stored size: 1.21 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: ['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

8 entries across 8 versions & 1 rubygems

Version Path
praxis-2.0.pre.18 tasks/thor/model.rb
praxis-2.0.pre.17 tasks/thor/model.rb
praxis-2.0.pre.16 tasks/thor/model.rb
praxis-2.0.pre.15 tasks/thor/model.rb
praxis-2.0.pre.14 tasks/thor/model.rb
praxis-2.0.pre.13 tasks/thor/model.rb
praxis-2.0.pre.12 tasks/thor/model.rb
praxis-2.0.pre.11 tasks/thor/model.rb