From c5223a1e7478a9fa76e07309a300a88892cf4145 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Mon, 2 Mar 2015 19:15:10 -0800 Subject: ruby: hand roll InfoAction Rather than relying on EasyAction, just expand the construction of the InfoAction for the bindings. This will be expanded soon to support cross compilation. --- ruby/action.cc | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 114 insertions(+), 10 deletions(-) diff --git a/ruby/action.cc b/ruby/action.cc index 3b6d6b80f..0e3fe3fd8 100644 --- a/ruby/action.cc +++ b/ruby/action.cc @@ -36,7 +36,9 @@ namespace static VALUE c_fetch_action_options; static VALUE c_fetch_action_failure; + static VALUE c_info_action_options; static VALUE c_info_action; + static VALUE c_config_action; static VALUE c_install_action_options; @@ -55,6 +57,38 @@ namespace return wp_yes; } + const InfoActionOptions + value_to_info_action_options(VALUE v) + { + if (rb_obj_is_kind_of(v, c_info_action_options)) + { + InfoActionOptions *instance; + Data_Get_Struct(v, InfoActionOptions, instance); + return *instance; + } + else + { + rb_raise(rb_eTypeError, "Can't convert %s into InfoActionOptions", + rb_obj_classname(v)); + } + } + + VALUE + info_action_options_to_value(const InfoActionOptions &options) + { + InfoActionOptions *value = new InfoActionOptions(options); + try + { + return Data_Wrap_Struct(c_info_action_options, 0, + &Common::free, value); + } + catch (const std::exception & e) + { + delete value; + exception_to_ruby_exception(e); + } + } + const FetchActionOptions value_to_fetch_action_options(VALUE v) { @@ -295,6 +329,75 @@ namespace } } + /* + * call-seq: + * InfoAction.new -> InfoAction + */ + VALUE + info_action_new(VALUE self, VALUE opts) + { + const InfoActionOptions options = value_to_info_action_options(opts); + std::shared_ptr *action = new std::shared_ptr(std::make_shared(options)); + VALUE object = Data_Wrap_Struct(self, 0, &Common>::free, action); + rb_obj_call_init(object, 1, &self); + return object; + } + + /* + * call-seq: + * options -> InfoActionOptions + * + * Our InfoActionOptions. + */ + VALUE + info_action_options(VALUE self) + { + std::shared_ptr *instance; + Data_Get_Struct(self, std::shared_ptr, instance); + return info_action_options_to_value(std::static_pointer_cast(*instance)->options); + } + + /* + * call-seq: + * InfoActionOptions.new() -> InfoActionOptions + * InfoActionOptions.new(Hash) -> InfoActionOptions + * + * InfoActionOptions.new can either be called with all parameters in order, + * or with one hash parameter, where the hash keys are symbols with the + * names above. + */ + VALUE + info_action_options_new(int argc, VALUE *argv, VALUE self) + { + InfoActionOptions *options = nullptr; + try + { + if (argc == 1 && rb_obj_is_kind_of(argv[0], rb_cHash)) + { + // TODO(compnerd) raise an error if hashtable is not empty + } + else if (argc == 0) + { + } + else + { + rb_raise(rb_eArgError, "InfoActionOptions expects zero or one arguments, but got %d", argc); + } + + options = + new InfoActionOptions(make_named_values( + n::make_output_manager() = &make_standard_output_manager)); + VALUE object = Data_Wrap_Struct(self, 0, &Common::free, options); + rb_obj_call_init(object, argc, argv); + return object; + } + catch (const std::exception & e) + { + delete options; + exception_to_ruby_exception(e); + } + } + /* * call-seq: * FetchAction.new -> FetchAction @@ -461,14 +564,6 @@ namespace } }; - /* - * Document-method InfoAction.new - * - * call-seq: - * InfoAction.new -> InfoAction - * - * Create new InfoAction - */ /* * Document-method ConfigAction.new * @@ -867,15 +962,24 @@ namespace RUBY_FUNC_CAST((&NVFetch::fetch)), 0); + /* + * Document-class: Paludis::InfoActionOptions + * + * Options for Paludis::InfoAction + */ + c_info_action_options = rb_define_class_under(paludis_module(), "InfoActionOptions", rb_cObject); + rb_define_singleton_method(c_info_action_options, "new", RUBY_FUNC_CAST(&info_action_options_new), -1); + rb_define_method(c_info_action_options, "initialize", RUBY_FUNC_CAST(&empty_init), -1); + /* * Document-class: Paludis::InfoAction * * An action for fetching. */ c_info_action = rb_define_class_under(paludis_module(), "InfoAction", c_action); - rb_define_singleton_method(c_info_action, "new", - RUBY_FUNC_CAST((&EasyActionNew::easy_action_new)), 0); + rb_define_singleton_method(c_info_action, "new", RUBY_FUNC_CAST(&info_action_new), 1); rb_define_method(c_info_action, "initialize", RUBY_FUNC_CAST(&empty_init), -1); + rb_define_method(c_info_action, "options", RUBY_FUNC_CAST(&info_action_options), 0); /* * Document-class: Paludis::ConfigAction -- cgit v1.2.3