class Paludis::Choice

A collection of ChoiceValue objects for a PackageID's Choices.

Public Instance Methods

each {|choice_value| block } → Nil click to toggle source

Our ChoiceValue children.

VALUE
    choice_each(VALUE self_v)
    {
        std::shared_ptr<const Choice> self(value_to_choice(self_v));
        for (Choice::ConstIterator k(self->begin()), k_end(self->end()) ;
                k != k_end ; ++k)
        {
            VALUE val(choice_value_to_value(*k));
            if (Qnil != val)
                rb_yield(val);
        }
        return Qnil;
    }

    /*
     * call-seq:
     *     raw_name -> String
     *
     * Our raw name, for example 'USE' or 'LINGUAS'.
     */
    FAKE_RDOC_METHOD(choice_raw_name)

    /*
     * call-seq:
     *     human_name -> String
     *
     * A human-readable name (often the same as raw_name).
     */
    FAKE_RDOC_METHOD(choice_human_name)

    /*
     * call-seq:
     *     prefix -> String
     *
     * The prefix for our ChoiceValue children.
     *
     * An empty string for USE and ARCH, 'linguas' for LINGUAS etc.
     */
    FAKE_RDOC_METHOD(choice_prefix)

    template <typename R_, const R_ (Choice::* r_) () const>
    struct ChoiceStringishMembers
    {
        static VALUE fetch(VALUE self_v)
        {
            try
            {
                std::shared_ptr<const Choice> self(value_to_choice(self_v));
                return rb_str_new2(stringify(((*self).*r_)()).c_str());
            }
            catch (const std::exception & e)
            {
                exception_to_ruby_exception(e);
            }
        }
    };

    /*
     * call-seq:
     *     contains_every_value? -> true or false
     *
     * If true, pretend that we contain every possible value and that any value not listed
     * as a child exists and is not enabled.
     *
     * For pesky 0-based EAPIs that don't require things like userland_GNU in IUSE, and that
     * don't have a comprehensive list of possible values.
     */
    FAKE_RDOC_METHOD(choice_contains_every_value)

    /*
     * call-seq:
     *     hidden? -> true or false
     *
     * If true, this option should not usually be shown visually to a user.
     */
    FAKE_RDOC_METHOD(choice_hidden)

    /*
     * call-seq:
     *     show_with_no_prefix? -> true or false
     *
     * If true, hint that we're better not displaying our prefix to the user.
     *
     * This is used by --pretend --install and --query to avoid showing a Use:
     * prefix before a list of use flag names.
     */
    FAKE_RDOC_METHOD(choice_show_with_no_prefix)

    /*
     * call-seq:
     *     consider_added_or_changed? -> true or false
     *
     * If false, do not consider flags in this section for 'added' or 'changed'
     * detection.
     *
     * Used by build_options.
     */
    FAKE_RDOC_METHOD(choice_consider_added_or_changed)

    template <typename R_, R_ (Choice::* r_) () const>
    struct ChoiceBoolishMembers
    {
        static VALUE fetch(VALUE self_v)
        {
            try
            {
                std::shared_ptr<const Choice> self(value_to_choice(self_v));
                return bool_to_value(((*self).*r_)());
            }
            catch (const std::exception & e)
            {
                exception_to_ruby_exception(e);
            }
        }
    };

    /*
     * call-seq:
     *     unprefixed_name -> String
     *
     * Our name, without an prefix (for example, 'nls' or 'en').
     */
    FAKE_RDOC_METHOD(choice_value_unprefixed_name)

    /*
     * call-seq:
     *     name_with_prefix -> String
     *
     * Our name, with prefix if there is one (for example, 'nls' or 'linguas_en').
     */
    FAKE_RDOC_METHOD(choice_value_name_with_prefix)

    /*
     * call-seq:
     *     description -> String
     *
     * The flag's description, or an empty string.
     */
    FAKE_RDOC_METHOD(choice_value_description)

    template <typename R_, const R_ (ChoiceValue::* r_) () const>
    struct ChoiceValueStringishMembers
    {
        static VALUE fetch(VALUE self_v)
        {
            try
            {
                std::shared_ptr<const ChoiceValue> self(value_to_choice_value(self_v));
                return rb_str_new2(stringify(((*self).*r_)()).c_str());
            }
            catch (const std::exception & e)
            {
                exception_to_ruby_exception(e);
            }
        }
    };

    /*
     * call-seq:
     *     enabled? -> true or false
     *
     * Is this flag enabled?
     */
    FAKE_RDOC_METHOD(choice_value_enabled)

    /*
     * call-seq:
     *     enabled_by_default? -> true or false
     *
     * Would this flag be enabled by default (i.e. before considering
     * any overrides from the Environment)?
     */
    FAKE_RDOC_METHOD(choice_value_enabled_by_default)

    /*
     * call-seq:
     *     locked? -> true or false
     *
     * Is this flag locked (forced or masked)?
     */
    FAKE_RDOC_METHOD(choice_value_locked)

    template <typename R_, R_ (ChoiceValue::* r_) () const>
    struct ChoiceValueBoolishMembers
    {
        static VALUE fetch(VALUE self_v)
        {
            try
            {
                std::shared_ptr<const ChoiceValue> self(value_to_choice_value(self_v));
                return bool_to_value(((*self).*r_)());
            }
            catch (const std::exception & e)
            {
                exception_to_ruby_exception(e);
            }
        }
    };

    /*
     * call-seq:
     *     origin -> ChoiceOrigin
     *
     * Is this flag explicitly listed?
     *
     * Use this to avoid showing things like LINGUAS values that aren't listed
     * in IUSE but that end up as a ChoiceValue anyway.
     */
    VALUE
    choice_value_origin(VALUE self_v)
    {
        std::shared_ptr<const ChoiceValue> self(value_to_choice_value(self_v));
        return INT2FIX(self->origin());
    }

    void do_register_choice()
    {
        /*
         * Document-class: Paludis::Choices
         *
         * A collection of Choice objects for a PackageID.
         */
        c_choices = rb_define_class_under(c_paludis_module, "Choices", rb_cObject);
        rb_funcall(c_choices, rb_intern("private_class_method"), 1, rb_str_new2("new"));
        rb_define_method(c_choices, "each", choices_each, 0);
        rb_include_module(c_choices, rb_mEnumerable);
        rb_define_method(c_choices, "find_by_name_with_prefix", choices_find_by_name_with_prefix, 1);
        rb_define_method(c_choices, "has_matching_contains_every_value_prefix?", choices_has_matching_contains_every_value_prefix, 1);

        /*
         * Document-class: Paludis::Choice
         *
         * A collection of ChoiceValue objects for a PackageID's Choices.
         */
        c_choice = rb_define_class_under(c_paludis_module, "Choice", rb_cObject);
        rb_funcall(c_choice, rb_intern("private_class_method"), 1, rb_str_new2("new"));
        rb_define_method(c_choice, "raw_name", choice_raw_name, 0)
        rb_define_method(c_choice, "human_name", choice_human_name, 0)
        rb_define_method(c_choice, "prefix", choice_prefix, 0)
        rb_define_method(c_choice, "contains_every_value?", choice_contains_every_value, 0)
        rb_define_method(c_choice, "hidden?", choice_hidden, 0)
        rb_define_method(c_choice, "show_with_no_prefix?", choice_show_with_no_prefix, 0)
        rb_define_method(c_choice, "consider_added_or_changed?", choice_consider_added_or_changed, 0)
        rb_define_method(c_choice, "each", choice_each, 0);
        rb_include_module(c_choice, rb_mEnumerable);

        /*
         * Document-module: Paludis::ChoiceOrigin
         *
         * The origin of a Choice
         */
        c_choice_origin = rb_define_module_under(c_paludis_module, "ChoiceOrigin");
        for (ChoiceOrigin l(static_cast<ChoiceOrigin>(0)), l_end(last_co) ; l != l_end ;
                l = static_cast<ChoiceOrigin>(static_cast<int>(l) + 1))
            rb_define_const(c_choice_origin, value_case_to_RubyCase(stringify(l)).c_str(), INT2FIX(l));


        /*
         * Document-class: Paludis::ChoiceValue
         *
         * A single ChoiceValue object for a Choice.
         */
        c_choice_value = rb_define_class_under(c_paludis_module, "ChoiceValue", rb_cObject);
        rb_funcall(c_choice_value, rb_intern("private_class_method"), 1, rb_str_new2("new"));
        rb_define_method(c_choice_value, "unprefixed_name", choice_value_unprefixed_name, 0)
        rb_define_method(c_choice_value, "name_with_prefix", choice_value_name_with_prefix, 0)
        rb_define_method(c_choice_value, "enabled?", choice_value_enabled, 0)
        rb_define_method(c_choice_value, "enabled_by_default?", choice_value_enabled_by_default, 0)
        rb_define_method(c_choice_value, "locked?", choice_value_locked, 0)
        rb_define_method(c_choice_value, "description", choice_value_description, 0)
        rb_define_method(c_choice_value, "origin", choice_value_origin, 0);
    }
}