Sha256: b1b63cf7d0e9932029edaa3981377719d1fd8b2d8442ba77db84d3954df2e774
Contents?: true
Size: 1.45 KB
Versions: 1
Compression:
Stored size: 1.45 KB
Contents
require 'erb' module Hanami module Sequel module CLI class Model < Hanami::CLI::Command argument :name, required: true, desc: 'Name of the model' def call(name:, **options) under_name = Utils::String.underscore(name) table_name = Utils::String.pluralize(under_name) camel_name = Utils::String.classify(name) model_name = "#{camel_name}Model" b = ErBinding.new(model_name: model_name, table_name: table_name) # db/migrations/date-create-table_name.rb now = Time.now.strftime('%Y%m%d%H%M%S') destination = File.join(CLI.config.migrations, "#{now}_create_#{table_name}.rb") CLI.generate(CLI.template('model-migration'), b, destination) # lib/project_name/models/model_name.rb destination = File.join(CLI.lib_path, 'models', "/#{under_name}_model.rb") CLI.generate(CLI.template('model-sequel'), b, destination) # spec/project_name/models/model_name_spec.rb destination = File.join(CLI.spec_path, 'models', "/#{under_name}_model_spec.rb") CLI.generate(CLI.template('model-spec'), b, destination) end end end end end Hanami::CLI.register 'sequel model', Hanami::Sequel::CLI::Model
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hanami-sequel-1.1.0.1 | lib/hanami/sequel/commands/model.rb |