Sha256: 2d56f67cd950f179afa7023c9c2f2d4f26958d7f4e9cb386a1b31d4d3cb58e33

Contents?: true

Size: 943 Bytes

Versions: 4

Compression:

Stored size: 943 Bytes

Contents

module Localtower
  module Generators
    class Model
      def initialize(opts)
        @opts = JSON[opts.to_json]
      end

      def run
        if not @opts['attributes'] or not @opts['model_name'].present?
          return nil
        end

        attributes_list = []

        @opts['attributes'].each do |attribute_data|
          str = "#{attribute_data["attribute_name"]}:#{attribute_data["attribute_type"]}"
          str << ":index" if attribute_data["index"]

          attributes_list << str
        end

        attributes_str = attributes_list.join(" ")
        cmd = "rails g model #{@opts['model_name'].camelize} #{attributes_str}"

        ::Localtower::Tools.perform_cmd(cmd, false)

        if @opts['run_migrate']
          ::Localtower::Tools.perform_cmd('rake db:migrate', false)
          # ::Localtower::Tools.perform_cmd('rake db:migrate RAILS_ENV=test', false)
        end

        self
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
localtower-0.1.7 lib/localtower/generators/model.rb
localtower-0.1.6 lib/localtower/generators/model.rb
localtower-0.1.5 lib/localtower/generators/model.rb
localtower-0.1.4 lib/localtower/generators/model.rb