Sha256: 0c4c613b36c837a6f78d56ecfe7367cf5ac54c9d82320d0996c6f38d6398aedf

Contents?: true

Size: 1.16 KB

Versions: 21

Compression:

Stored size: 1.16 KB

Contents

require 'generators/hobo_support/eval_template'

module Generators
  module HoboSupport
    Model = classy_module do
      include EvalTemplate

      argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"

      def self.banner
      "rails generate hobo:model #{self.arguments.map(&:usage).join(' ')} [options]"
      end

      class_option :timestamps, :type => :boolean

      def generate_model
        invoke "active_record:model", [name], {:migration => false}.merge(options)
      end

      def inject_hobo_code_into_model_file
        inject_into_class model_path, class_name do
          eval_template('model_injection.rb.erb')
        end
      end

      protected

      def model_path
        @model_path ||= File.join("app", "models", "#{file_path}.rb")
      end

      def max_attribute_length
        attributes.*.name.*.length.max
      end

      def field_attributes
        attributes.reject { |a| a.name == "bt" || a.name == "hm" }
      end

      def hms
        attributes.select { |a| a.name == "hm" }.*.type
      end

      def bts
        attributes.select { |a| a.name == "bt" }.*.type
      end

    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
hobo_support-1.3.3 lib/generators/hobo_support/model.rb
hobo_support-1.3.2 lib/generators/hobo_support/model.rb
hobo_support-1.3.1 lib/generators/hobo_support/model.rb
hobo_support-1.4.0.pre8 lib/generators/hobo_support/model.rb
hobo_support-1.4.0.pre7 lib/generators/hobo_support/model.rb
hobo_support-1.4.0.pre6 lib/generators/hobo_support/model.rb
hobo_support-1.4.0.pre5 lib/generators/hobo_support/model.rb
hobo_support-1.4.0.pre4 lib/generators/hobo_support/model.rb
hobo_support-1.4.0.pre3 lib/generators/hobo_support/model.rb
hobo_support-1.4.0.pre2 lib/generators/hobo_support/model.rb
hobo_support-1.3.0 lib/generators/hobo_support/model.rb
hobo_support-1.3.0.RC4 lib/generators/hobo_support/model.rb
hobo_support-1.3.0.RC3 lib/generators/hobo_support/model.rb
hobo_support-1.3.0.RC2 lib/generators/hobo_support/model.rb
hobo_support-1.3.0.RC1 lib/generators/hobo_support/model.rb
hobo_support-1.3.0.RC lib/generators/hobo_support/model.rb
hobo_support-1.3.0.pre31 lib/generators/hobo_support/model.rb
hobo_support-1.3.0.pre29 lib/generators/hobo_support/model.rb
hobo_support-1.3.0.pre28 lib/generators/hobo_support/model.rb
hobo_support-1.3.0.pre27 lib/generators/hobo_support/model.rb