etc 0.2.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8ae337119cdf0d4de924a5ead10fef45273f280a
4
- data.tar.gz: 48d0f0864f628b37f55eb2e5cb49ab13564c9631
2
+ SHA256:
3
+ metadata.gz: 470f56643e5fb28930ac3d0d1cb4200778c74610c06d958a2c5264eed49fd6ed
4
+ data.tar.gz: 311937e0471e67df04429ca390b9dd7240e7cb1bef91ca4f06232be0966f8d4f
5
5
  SHA512:
6
- metadata.gz: a23eb4e20bd188cae18155adcbcd391310b74f623ec70ea4b92a0d79e4833f3a3c01495ce1d5a294e349a867c5440cfb789aae21850094a66aeb936cc63b341c
7
- data.tar.gz: da3a5cee8c1f22a1c780d1d3a9fb83baa076f6a9bbb3fdb9d0adb9840004e251ea2593033ec9e94ba96d946410de26b6ca64130d02996ce3dc7a0a063b73a998
6
+ metadata.gz: 6afef3a83d16491cf6ae5baf9cd0dc496681cb06a58647e9b7389ff149dbaa548a372642657615392ca1b087aaaa94ef3e72a3f75bb25e12a9172e29752a272a
7
+ data.tar.gz: ee873bfdd434c3e5f501890dcd0707dbed08f6deb68ffb918d2b5c3823612db8e1e3b34286f8b32a032a62ed5089fef9a07e0a07832e9fc37d1c725c8b30a2d0
@@ -1,5 +1,7 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
+ - 2.3.5
5
+ - 2.4.2
4
6
  - ruby-head
5
7
  before_install: gem install bundler
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # Etc
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/etc`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Build Status](https://travis-ci.org/ruby/etc.svg?branch=master)](https://travis-ci.org/ruby/etc)
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ The Etc module provides access to information typically stored in files in the /etc directory on Unix systems.
6
+
7
+ The information accessible consists of the information found in the `/etc/passwd` and `/etc/group` files, plus information about he system's temporary directory (/tmp) and configuration directory (/etc).
8
+
9
+ The Etc module provides a more reliable way to access information about the logged in user than environment variables such as +$USER+.
6
10
 
7
11
  ## Installation
8
12
 
@@ -22,7 +26,18 @@ Or install it yourself as:
22
26
 
23
27
  ## Usage
24
28
 
25
- TODO: Write usage instructions here
29
+ ```
30
+ require 'etc'
31
+
32
+ login = Etc.getlogin
33
+ info = Etc.getpwnam(login)
34
+ username = info.gecos.split(/,/).first
35
+ puts "Hello #{username}, I see your login name is #{login}"
36
+ ```
37
+
38
+ Note that the methods provided by this module are not always secure. It should be used for informational purposes, and not for security.
39
+
40
+ All operations defined in this module are class methods, so that you can include the Etc module into your class.
26
41
 
27
42
  ## Development
28
43
 
@@ -36,4 +51,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/e
36
51
 
37
52
  ## License
38
53
 
39
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
54
+ The gem is available as open source under the terms of the [2-Clause BSD License](https://opensource.org/licenses/BSD-2-Clause).
@@ -1,9 +1,10 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  Gem::Specification.new do |spec|
4
5
  spec.name = "etc"
5
- spec.version = "0.2.1"
6
- spec.date = '2017-02-27'
6
+ spec.version = "1.0.0"
7
+ spec.date = '2017-12-13'
7
8
  spec.authors = ["Yukihiro Matsumoto"]
8
9
  spec.email = ["matz@ruby-lang.org"]
9
10
 
@@ -32,7 +33,7 @@ Gem::Specification.new do |spec|
32
33
  spec.require_paths = ["lib"]
33
34
  spec.extensions = %w{ext/etc/extconf.rb}
34
35
 
35
- spec.required_ruby_version = ">= 2.5.0dev"
36
+ spec.required_ruby_version = ">= 2.3.0"
36
37
 
37
38
  spec.add_development_dependency "bundler"
38
39
  spec.add_development_dependency "rake"
@@ -215,9 +215,10 @@ etc_getpwnam(VALUE obj, VALUE nam)
215
215
  {
216
216
  #ifdef HAVE_GETPWENT
217
217
  struct passwd *pwd;
218
+ const char *p = StringValueCStr(nam);
218
219
 
219
- SafeStringValue(nam);
220
- pwd = getpwnam(RSTRING_PTR(nam));
220
+ rb_check_safe_obj(nam);
221
+ pwd = getpwnam(p);
221
222
  if (pwd == 0) rb_raise(rb_eArgError, "can't find user for %"PRIsVALUE, nam);
222
223
  return setup_passwd(pwd);
223
224
  #else
@@ -458,9 +459,10 @@ etc_getgrnam(VALUE obj, VALUE nam)
458
459
  {
459
460
  #ifdef HAVE_GETGRENT
460
461
  struct group *grp;
462
+ const char *p = StringValueCStr(nam);
461
463
 
462
- SafeStringValue(nam);
463
- grp = getgrnam(RSTRING_PTR(nam));
464
+ rb_check_safe_obj(nam);
465
+ grp = getgrnam(p);
464
466
  if (grp == 0) rb_raise(rb_eArgError, "can't find group for %"PRIsVALUE, nam);
465
467
  return setup_group(grp);
466
468
  #else
@@ -625,8 +627,9 @@ VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc);
625
627
  * Returns system configuration directory.
626
628
  *
627
629
  * This is typically "/etc", but is modified by the prefix used when Ruby was
628
- * compiled. For example, if Ruby is built and installed in /usr/local, returns
629
- * "/usr/local/etc".
630
+ * compiled. For example, if Ruby is built and installed in /usr/local,
631
+ * returns "/usr/local/etc" on other platforms than Windows.
632
+ * On Windows, this always returns the directory provided by the system.
630
633
  */
631
634
  static VALUE
632
635
  etc_sysconfdir(VALUE obj)
@@ -1012,7 +1015,7 @@ etc_nprocessors(VALUE obj)
1012
1015
 
1013
1016
  ncpus = etc_nprocessors_affin();
1014
1017
  if (ncpus != -1) {
1015
- return INT2NUM(ncpus);
1018
+ return INT2NUM(ncpus);
1016
1019
  }
1017
1020
  /* fallback to _SC_NPROCESSORS_ONLN */
1018
1021
  #endif
@@ -12,8 +12,10 @@ have_func("uname((struct utsname *)NULL)", headers)
12
12
  have_func("getlogin")
13
13
  have_func("getpwent")
14
14
  have_func("getgrent")
15
- sysconfdir = RbConfig.expand(RbConfig::CONFIG["sysconfdir"].dup, "prefix"=>"", "DESTDIR"=>"")
16
- $defs.push("-DSYSCONFDIR=#{Shellwords.escape(sysconfdir.dump)}")
15
+ if (sysconfdir = RbConfig::CONFIG["sysconfdir"] and
16
+ !RbConfig.expand(sysconfdir.dup, "prefix"=>"", "DESTDIR"=>"").empty?)
17
+ $defs.push("-DSYSCONFDIR=#{Shellwords.escape(sysconfdir.dump)}")
18
+ end
17
19
 
18
20
  have_func("sysconf")
19
21
  have_func("confstr")
@@ -97,12 +97,12 @@ class TestEtc < Test::Unit::TestCase
97
97
  end
98
98
 
99
99
  def test_getgrnam
100
- groups = {}
100
+ groups = Hash.new {[]}
101
101
  Etc.group do |s|
102
- groups[s.name] ||= s.gid unless /\A\+/ =~ s.name
102
+ groups[s.name] |= [s.gid] unless /\A\+/ =~ s.name
103
103
  end
104
104
  groups.each_pair do |n, s|
105
- assert_equal(s, Etc.getgrnam(n).gid)
105
+ assert_include(s, Etc.getgrnam(n).gid)
106
106
  end
107
107
  end
108
108
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukihiro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-27 00:00:00.000000000 Z
11
+ date: 2017-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -99,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
- version: 2.5.0dev
102
+ version: 2.3.0
103
103
  required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  requirements:
105
105
  - - ">="
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  version: '0'
108
108
  requirements: []
109
109
  rubyforge_project:
110
- rubygems_version: 2.6.12
110
+ rubygems_version: 2.7.3
111
111
  signing_key:
112
112
  specification_version: 4
113
113
  summary: Provides access to information typically stored in UNIX /etc directory.