From 2033c64248970071448511831e3e370447d7d906 Mon Sep 17 00:00:00 2001 From: Prakriti-nith Date: Mon, 30 Jul 2018 04:48:32 +0530 Subject: [PATCH] Added method append_method --- lib/tasks/new_adapter.rake | 42 ++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/lib/tasks/new_adapter.rake b/lib/tasks/new_adapter.rake index 6a4814b..8d45d74 100644 --- a/lib/tasks/new_adapter.rake +++ b/lib/tasks/new_adapter.rake @@ -4,35 +4,17 @@ def extract_adapter_template_code(file_name, template_code_str) template_code_str << "\n module Adapter" template_code_str << "\n module #{file_name.capitalize}Adapter" template_code_str << "\n extend self # rubocop:disable Style/ModuleFunction" - template_code_str << "\n def init(data, options, _user_options={})" - template_code_str << "\n # TODO" - template_code_str << "\n raise NotImplementedError, 'Not yet implemented'" - template_code_str << "\n end" + template_code_str << append_method('init', ['data', 'options', '_user_options']) template_code_str << "\n" - template_code_str << "\n def export_html_file(plot, path='./plot.html')" - template_code_str << "\n # TODO" - template_code_str << "\n raise NotImplementedError, 'Not yet implemented'" - template_code_str << "\n end" + template_code_str << append_method('export_html_file', ['plot', "path='./plot.html'"]) template_code_str << "\n" - template_code_str << "\n def show_in_iruby(plot)" - template_code_str << "\n # TODO" - template_code_str << "\n raise NotImplementedError, 'Not yet implemented'" - template_code_str << "\n end" + template_code_str << append_method('show_in_iruby', ['plot']) template_code_str << "\n" - template_code_str << "\n def init_script" - template_code_str << "\n # TODO" - template_code_str << "\n raise NotImplementedError, 'Not yet implemented'" - template_code_str << "\n end" + template_code_str << append_method('init_script') template_code_str << "\n" - template_code_str << "\n def generate_body(plot)" - template_code_str << "\n # TODO" - template_code_str << "\n raise NotImplementedError, 'Not yet implemented'" - template_code_str << "\n end" + template_code_str << append_method('generate_body', ['plot']) template_code_str << "\n" - template_code_str << "\n def init_iruby" - template_code_str << "\n # TODO" - template_code_str << "\n raise NotImplementedError, 'Not yet implemented'" - template_code_str << "\n end" + template_code_str << append_method('init_iruby') template_code_str << "\n end" template_code_str << "\n end" template_code_str << "\n end" @@ -40,6 +22,18 @@ def extract_adapter_template_code(file_name, template_code_str) template_code_str << "\n" end +def append_method(method_name, params=nil) + method_str = "\n def #{method_name}" + if params + method_str << '(' + method_str << params.join(', ') + method_str << ')' + end + method_str << "\n # TODO" + method_str << "\n raise NotImplementedError, 'Not yet implemented'" + method_str << "\n end" +end + namespace :new do desc "Generate a sample template for the new adapter" task :adapter do