aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2006-12-06 15:21:04 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2006-12-06 15:21:04 +0000
commit149a8024b46c2fe939ed89a60c5d7a3acd0b7acc (patch)
tree104f89dda165e8c933343e872a3f90485e2710ee
parente69934697054c073dd980fff72526782603d4cb2 (diff)
downloadpaludis-149a8024b46c2fe939ed89a60c5d7a3acd0b7acc.tar.gz
paludis-149a8024b46c2fe939ed89a60c5d7a3acd0b7acc.tar.xz
Improve ruby DefaultConfig.
-rw-r--r--ruby/environment.cc14
-rw-r--r--ruby/environment_TEST.rb29
2 files changed, 43 insertions, 0 deletions
diff --git a/ruby/environment.cc b/ruby/environment.cc
index d7b91e8..8ce34b2 100644
--- a/ruby/environment.cc
+++ b/ruby/environment.cc
@@ -170,6 +170,16 @@ namespace
}
}
+ template <std::string (DefaultConfig::* m_) () const>
+ struct ConfigStruct
+ {
+ static VALUE
+ fetch(VALUE)
+ {
+ return rb_str_new2((((DefaultConfig::get_instance())->*m_)()).c_str());
+ }
+ };
+
VALUE
default_config_config_suffix_set(VALUE klass, VALUE str)
{
@@ -254,10 +264,14 @@ namespace
c_default_config = rb_define_class_under(paludis_module(), "DefaultConfig", rb_cObject);
rb_funcall(c_default_config, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_funcall(rb_const_get(rb_cObject, rb_intern("Singleton")), rb_intern("included"), 1, c_default_config);
rb_define_singleton_method(c_default_config, "config_suffix",
RUBY_FUNC_CAST(&default_config_config_suffix), 0);
rb_define_singleton_method(c_default_config, "config_suffix=",
RUBY_FUNC_CAST(&default_config_config_suffix_set), 1);
+ rb_define_method(c_default_config, "config_dir", RUBY_FUNC_CAST((&ConfigStruct<&DefaultConfig::config_dir>::fetch)), 0);
+ rb_define_method(c_default_config, "root", RUBY_FUNC_CAST((&ConfigStruct<&DefaultConfig::root>::fetch)), 0);
+ rb_define_method(c_default_config, "bashrc_files", RUBY_FUNC_CAST((&ConfigStruct<&DefaultConfig::bashrc_files>::fetch)), 0);
c_no_config_environment = rb_define_class_under(paludis_module(), "NoConfigEnvironment", c_environment);
rb_define_singleton_method(c_no_config_environment, "new", RUBY_FUNC_CAST(&no_config_environment_new), 1);
diff --git a/ruby/environment_TEST.rb b/ruby/environment_TEST.rb
index 5426506..75d073c 100644
--- a/ruby/environment_TEST.rb
+++ b/ruby/environment_TEST.rb
@@ -283,5 +283,34 @@ module Paludis
end
end
end
+
+ class TestCase_DefaultConfig < Test::Unit::TestCase
+ def test_respond_to
+ assert_respond_to DefaultConfig, :config_suffix
+ assert_respond_to DefaultConfig, :config_suffix=
+ assert_respond_to DefaultConfig.instance, :config_dir
+ assert_respond_to DefaultConfig.instance, :root
+ assert_respond_to DefaultConfig.instance, :bashrc_files
+ end
+
+ def test_root
+ assert_kind_of String, DefaultConfig.instance.root
+ assert_equal '', DefaultConfig.instance.root
+ end
+
+ def test_config_dir
+ assert_kind_of String, DefaultConfig.instance.config_dir
+ cd = DefaultConfig.instance.config_dir
+ assert_equal '/environment_TEST_dir/home/.paludis',
+ cd.gsub(Dir.getwd,'')
+ end
+
+ def test_bashrc_files
+ assert_kind_of String, DefaultConfig.instance.bashrc_files
+ cd = DefaultConfig.instance.bashrc_files
+ assert_equal '/environment_TEST_dir/home/.paludis/bashrc',
+ cd.gsub(Dir.getwd,'')
+ end
+ end
end