lib/pliny/commands/generator.rb in pliny-0.0.1.pre2 vs lib/pliny/commands/generator.rb in pliny-0.0.1.pre3

- old
+ new

@@ -37,22 +37,29 @@ create_migration when "model" create_model create_model_migration create_model_test + create_serializer + create_serializer_test when "scaffold" create_endpoint(scaffold: true) create_endpoint_test create_endpoint_acceptance_test(scaffold: true) create_model create_model_migration create_model_test create_schema rebuild_schema + create_serializer + create_serializer_test when "schema" create_schema rebuild_schema + when "serializer" + create_serializer + create_serializer_test else abort("Don't know how to generate '#{type}'.") end end @@ -63,15 +70,15 @@ def name args[1] end def singular_class_name - name.singularize.camelize + name.gsub(/-/, '_').singularize.camelize end def plural_class_name - name.pluralize.camelize + name.gsub(/-/, '_').pluralize.camelize end def field_name name.tableize.singularize end @@ -170,9 +177,21 @@ schemata = "./docs/schema.json" write_file(schemata) do Prmd.combine("./docs/schema/schemata", meta: "./docs/schema/meta.json") end display "rebuilt #{schemata}" + end + + def create_serializer + serializer = "./lib/serializers/#{name}_serializer.rb" + render_template("serializer.erb", serializer, singular_class_name: singular_class_name) + display "created serializer file #{serializer}" + end + + def create_serializer_test + test = "./spec/serializers/#{name}_serializer_spec.rb" + render_template("serializer_test.erb", test, singular_class_name: singular_class_name) + display "created test #{test}" end def render_template(template_file, destination_path, vars={}) template_path = File.dirname(__FILE__) + "/../templates/#{template_file}" template = ERB.new(File.read(template_path), 0, ">")