Sha256: cd202ef225667b6f5ab911cb5c0272101d6f001ab40cdedda703c936cd93cacb

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

require 'rails/generators/named_base'

module Hibachi
  module Generators
    class ModelGenerator < Rails::Generators::NamedBase
      include Rails::Generators::ResourceHelpers

      desc "Generates a model for interacting with the Chef config"
      source_root File.expand_path("../../templates", __FILE__)

      argument :model_attributes, :type => :array
      class_option :recipe, :type => :string, :description => "Specify recipe"

      def copy_model_definition
        template 'model.rb.erb', "app/models/#{file_path}.rb"
      end

      protected
      def model_class
        file_path.classify
      end

      def symbolized_model_attributes
        ARGV[1..-1].reject { |arg|
          arg =~ /\A--/
        }.map { |arg|
          ":#{arg}"
        }.join ', '
      end

      def recipe_name
        return "'#{derived_recipe_name}'" if derived_recipe_name =~ /\:/
        ":#{derived_recipe_name}" # prefer symbols
      end

      def derived_recipe_name
        options[:recipe] || file_path.tableize
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hibachi-0.0.1 lib/generators/hibachi/model_generator.rb
hibachi-0.0.1.pre lib/generators/hibachi/model_generator.rb