aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Saleem Abdulrasool <compnerd@compnerd.org> 2015-03-02 19:15:10 -0800
committerAvatar Saleem Abdulrasool <compnerd@compnerd.org> 2015-03-02 19:15:10 -0800
commitc5223a1e7478a9fa76e07309a300a88892cf4145 (patch)
tree2f4225721a07cd258bec0fa4f0521f37952fa530
parent68b75f315bcd069e5ec39b6276e3c32a3fc5d195 (diff)
downloadpaludis-c5223a1e7478a9fa76e07309a300a88892cf4145.tar.gz
paludis-c5223a1e7478a9fa76e07309a300a88892cf4145.tar.xz
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.
-rw-r--r--ruby/action.cc124
1 files changed, 114 insertions, 10 deletions
diff --git a/ruby/action.cc b/ruby/action.cc
index 3b6d6b8..0e3fe3f 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<InfoActionOptions>::free, value);
+ }
+ catch (const std::exception & e)
+ {
+ delete value;
+ exception_to_ruby_exception(e);
+ }
+ }
+
const FetchActionOptions
value_to_fetch_action_options(VALUE v)
{
@@ -297,6 +331,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> *action = new std::shared_ptr<Action>(std::make_shared<InfoAction>(options));
+ VALUE object = Data_Wrap_Struct(self, 0, &Common<std::shared_ptr<Action>>::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<Action> *instance;
+ Data_Get_Struct(self, std::shared_ptr<Action>, instance);
+ return info_action_options_to_value(std::static_pointer_cast<InfoAction>(*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<InfoActionOptions>(
+ n::make_output_manager() = &make_standard_output_manager));
+ VALUE object = Data_Wrap_Struct(self, 0, &Common<InfoActionOptions>::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
*/
VALUE
@@ -462,14 +565,6 @@ namespace
};
/*
- * Document-method InfoAction.new
- *
- * call-seq:
- * InfoAction.new -> InfoAction
- *
- * Create new InfoAction
- */
- /*
* Document-method ConfigAction.new
*
* call-seq:
@@ -868,14 +963,23 @@ namespace
&FetchActionFailure::failed_integrity_checks>::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<InfoAction, InfoActionOptions>::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