Sha256: 7b2183c5690058e13bc7cb5d2d9c289edfe70acc53f8571e0bd7536080043018

Contents?: true

Size: 1.11 KB

Versions: 10

Compression:

Stored size: 1.11 KB

Contents

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

10 entries across 10 versions & 1 rubygems

Version Path
hobo_support-1.3.0.pre25 lib/generators/hobo_support/model.rb
hobo_support-1.3.0.pre24 lib/generators/hobo_support/model.rb
hobo_support-1.3.0.pre23 lib/generators/hobo_support/model.rb
hobo_support-1.3.0.pre22 lib/generators/hobo_support/model.rb
hobo_support-1.3.0.pre21 lib/generators/hobo_support/model.rb
hobo_support-1.3.0.pre20 lib/generators/hobo_support/model.rb
hobo_support-1.3.0.pre19 lib/generators/hobo_support/model.rb
hobo_support-1.3.0.pre18 lib/generators/hobo_support/model.rb
hobo_support-1.3.0.pre16 lib/generators/hobo_support/model.rb
hobo_support-1.3.0.pre15 lib/generators/hobo_support/model.rb