rubysl-etc 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +0 -1
- data/.travis.yml +7 -0
- data/README.md +2 -2
- data/Rakefile +0 -1
- data/lib/rubysl/etc.rb +2 -0
- data/lib/rubysl/etc/etc.rb.ffi +182 -0
- data/lib/rubysl/etc/extconf.rb +15 -0
- data/lib/{rubysl-etc → rubysl/etc}/version.rb +1 -1
- data/rubysl-etc.gemspec +18 -18
- data/spec/endgrent_spec.rb +6 -0
- data/spec/endpwent_spec.rb +6 -0
- data/spec/getgrent_spec.rb +6 -0
- data/spec/getgrgid_spec.rb +78 -0
- data/spec/getgrnam_spec.rb +36 -0
- data/spec/getlogin_spec.rb +13 -0
- data/spec/getpwent_spec.rb +6 -0
- data/spec/getpwnam_spec.rb +36 -0
- data/spec/getpwuid_spec.rb +43 -0
- data/spec/group_spec.rb +16 -0
- data/spec/passwd_spec.rb +1 -0
- data/spec/setgrent_spec.rb +1 -0
- data/spec/setpwent_spec.rb +1 -0
- data/spec/shared/windows.rb +7 -0
- data/spec/struct_group_spec.rb +30 -0
- data/spec/struct_passwd_spec.rb +42 -0
- metadata +88 -90
- data/lib/rubysl-etc.rb +0 -7
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b05a8c6ebb0126ae1179c7e9ea4e585f8c39d62d
|
4
|
+
data.tar.gz: 3c7efda145e27e56c1f0cb2de956b29df62a81c0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 101fa04f79d423b852bfb4c767a3563a153f55498f488e4b5d02ebbf2482bf8fc12493227d852481d5050cae806f8530ccba18bf657c51fc05c5c597552bc0c9
|
7
|
+
data.tar.gz: 6d711912110431d200f7424aad0c44e26a33274f4a617f3fe3aa0dcb0d0ed082e678fc01d775f6de61bc2b3c4be6ae32fea77f7a58261c002a928a9920ef0f8d
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# Rubysl::Etc
|
2
2
|
|
3
3
|
TODO: Write a gem description
|
4
4
|
|
@@ -24,6 +24,6 @@ TODO: Write usage instructions here
|
|
24
24
|
|
25
25
|
1. Fork it
|
26
26
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am '
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
28
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
29
|
5. Create new Pull Request
|
data/Rakefile
CHANGED
data/lib/rubysl/etc.rb
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
class Struct::Passwd < Rubinius::FFI::Struct
|
2
|
+
@@@
|
3
|
+
struct do |s|
|
4
|
+
s.include "sys/types.h"
|
5
|
+
s.include "pwd.h"
|
6
|
+
|
7
|
+
s.name "struct passwd"
|
8
|
+
s.field :pw_name, :string
|
9
|
+
s.field :pw_passwd, :string
|
10
|
+
s.field :pw_uid, :uid_t
|
11
|
+
s.field :pw_gid, :gid_t
|
12
|
+
s.field :pw_gecos, :string
|
13
|
+
s.field :pw_dir, :string
|
14
|
+
s.field :pw_shell, :string
|
15
|
+
end
|
16
|
+
@@@
|
17
|
+
|
18
|
+
def name; self[:pw_name]; end
|
19
|
+
def passwd; self[:pw_passwd]; end
|
20
|
+
def uid; self[:pw_uid]; end
|
21
|
+
def gid; self[:pw_gid]; end
|
22
|
+
def gecos; self[:pw_gecos]; end
|
23
|
+
def dir; self[:pw_dir]; end
|
24
|
+
def shell; self[:pw_shell]; end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Struct::Group < Rubinius::FFI::Struct
|
28
|
+
@@@
|
29
|
+
struct do |s|
|
30
|
+
s.include "sys/types.h"
|
31
|
+
s.include "grp.h"
|
32
|
+
|
33
|
+
s.name "struct group"
|
34
|
+
s.field :gr_name, :string
|
35
|
+
s.field :gr_passwd, :string
|
36
|
+
s.field :gr_gid, :gid_t
|
37
|
+
s.field :gr_mem, :pointer
|
38
|
+
end
|
39
|
+
@@@
|
40
|
+
|
41
|
+
FFI = Rubinius::FFI
|
42
|
+
|
43
|
+
def name; self[:gr_name]; end
|
44
|
+
def gid; self[:gr_gid]; end
|
45
|
+
def passwd; self[:gr_passwd]; end
|
46
|
+
def mem
|
47
|
+
ptr = self[:gr_mem].read_pointer
|
48
|
+
|
49
|
+
ary = []
|
50
|
+
i = 1
|
51
|
+
|
52
|
+
while not ptr.null? do
|
53
|
+
ary << ptr.read_string
|
54
|
+
ptr = (self[:gr_mem] + i * FFI::Pointer.size).read_pointer
|
55
|
+
i += 1
|
56
|
+
end
|
57
|
+
|
58
|
+
ary
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
module Etc
|
63
|
+
FFI = Rubinius::FFI
|
64
|
+
|
65
|
+
const_set(:Passwd, Struct::Passwd)
|
66
|
+
const_set(:Group, Struct::Group)
|
67
|
+
|
68
|
+
def self.getlogin
|
69
|
+
getpwuid.name
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.getpwnam(name)
|
73
|
+
login = StringValue(name)
|
74
|
+
|
75
|
+
passwd_ptr = FFI::Platform::POSIX.getpwnam(name)
|
76
|
+
if passwd_ptr.nil?
|
77
|
+
raise ArgumentError, "cannot find user - #{name}"
|
78
|
+
end
|
79
|
+
|
80
|
+
Struct::Passwd.new(passwd_ptr)
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.getpwuid(uid = Process.uid)
|
84
|
+
uid = Rubinius::Type.coerce_to(uid, Integer, :to_int)
|
85
|
+
|
86
|
+
passwd_ptr = FFI::Platform::POSIX.getpwuid(uid)
|
87
|
+
if passwd_ptr.nil?
|
88
|
+
raise ArgumentError, "cannot find user - #{uid}"
|
89
|
+
end
|
90
|
+
|
91
|
+
Struct::Passwd.new(passwd_ptr)
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.setpwent
|
95
|
+
FFI::Platform::POSIX.setpwent
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.getpwent
|
99
|
+
passwd_ptr = FFI::Platform::POSIX.getpwent
|
100
|
+
return nil if passwd_ptr.nil?
|
101
|
+
|
102
|
+
Struct::Passwd.new(passwd_ptr)
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.endpwent
|
106
|
+
FFI::Platform::POSIX.endpwent
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.passwd
|
110
|
+
Rubinius.synchronize(self) do
|
111
|
+
begin
|
112
|
+
setpwent
|
113
|
+
|
114
|
+
loop do
|
115
|
+
pw = getpwent
|
116
|
+
return if pw.nil?
|
117
|
+
|
118
|
+
yield pw
|
119
|
+
end
|
120
|
+
ensure
|
121
|
+
endpwent
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.getgrnam(name)
|
127
|
+
name = StringValue(name)
|
128
|
+
|
129
|
+
group_ptr = FFI::Platform::POSIX.getgrnam(name)
|
130
|
+
if group_ptr.nil?
|
131
|
+
raise ArgumentError, "cannot find group - #{name}"
|
132
|
+
end
|
133
|
+
|
134
|
+
Struct::Group.new(group_ptr)
|
135
|
+
end
|
136
|
+
|
137
|
+
def self.getgrgid(gid = Process.gid)
|
138
|
+
gid = Rubinius::Type.coerce_to(gid, Integer, :to_int)
|
139
|
+
|
140
|
+
group_ptr = FFI::Platform::POSIX.getgrgid(gid)
|
141
|
+
if group_ptr.nil?
|
142
|
+
raise ArgumentError, "cannot find group - #{gid}"
|
143
|
+
end
|
144
|
+
|
145
|
+
Struct::Group.new(group_ptr)
|
146
|
+
end
|
147
|
+
|
148
|
+
def self.setgrent
|
149
|
+
FFI::Platform::POSIX.setgrent
|
150
|
+
end
|
151
|
+
|
152
|
+
def self.getgrent
|
153
|
+
group_ptr = FFI::Platform::POSIX.getgrent
|
154
|
+
return nil if group_ptr.nil?
|
155
|
+
|
156
|
+
Struct::Group.new(group_ptr)
|
157
|
+
end
|
158
|
+
|
159
|
+
def self.endgrent
|
160
|
+
FFI::Platform::POSIX.endgrent
|
161
|
+
end
|
162
|
+
|
163
|
+
def self.group
|
164
|
+
Rubinius.synchronize(self) do
|
165
|
+
begin
|
166
|
+
raise "parallel group iteration" if @parallel_iteration
|
167
|
+
@parallel_iteration = true
|
168
|
+
setgrent
|
169
|
+
|
170
|
+
loop do
|
171
|
+
gr = getgrent
|
172
|
+
return if gr.nil?
|
173
|
+
|
174
|
+
yield gr
|
175
|
+
end
|
176
|
+
ensure
|
177
|
+
endgrent
|
178
|
+
@parallel_iteration = false
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "ffi2/generators"
|
2
|
+
|
3
|
+
FFI::FileProcessor.new "etc.rb.ffi", "etc.rb"
|
4
|
+
|
5
|
+
# Fake out rubygem's expected build steps with extconf.rb
|
6
|
+
File.open "Makefile", "w" do |f|
|
7
|
+
f.puts <<-EOM
|
8
|
+
.PHONY: all install
|
9
|
+
|
10
|
+
all:
|
11
|
+
|
12
|
+
install:
|
13
|
+
|
14
|
+
EOM
|
15
|
+
end
|
data/rubysl-etc.gemspec
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
#
|
2
|
-
require
|
1
|
+
# coding: utf-8
|
2
|
+
require './lib/rubysl/etc/version'
|
3
3
|
|
4
|
-
Gem::Specification.new do |
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "rubysl-etc"
|
6
|
+
spec.version = RubySL::Etc::VERSION
|
7
|
+
spec.authors = ["Brian Shirai"]
|
8
|
+
spec.email = ["brixen@gmail.com"]
|
9
|
+
spec.description = %q{Ruby standard library etc.}
|
10
|
+
spec.summary = %q{Ruby standard library etc.}
|
11
|
+
spec.homepage = "https://github.com/rubysl/rubysl-etc"
|
12
|
+
spec.license = "BSD"
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
gem.version = RubySL::Etc::VERSION
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.extensions = ["lib/rubysl/etc/extconf.rb"]
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
gem.add_development_dependency "rake", "~> 10.0"
|
21
|
-
gem.add_development_dependency "mspec", "~> 1.5"
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
22
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'etc'
|
2
|
+
|
3
|
+
platform_is :windows do
|
4
|
+
describe "Etc.getgrgid" do
|
5
|
+
it "returns nil" do
|
6
|
+
Etc.getgrgid(1).should == nil
|
7
|
+
Etc.getgrgid(nil).should == nil
|
8
|
+
Etc.getgrgid('nil').should == nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# TODO: verify these on non-windows, non-darwin OS
|
14
|
+
platform_is_not :windows do
|
15
|
+
describe "Etc.getgrgid" do
|
16
|
+
before(:all) do
|
17
|
+
@gid = `id -g`.strip.to_i
|
18
|
+
@name = `id -gn`.strip
|
19
|
+
end
|
20
|
+
|
21
|
+
ruby_version_is "" ... "1.9" do
|
22
|
+
it "returns a Struct::Group struct instance for the given user" do
|
23
|
+
gr = Etc.getgrgid(@gid)
|
24
|
+
|
25
|
+
gr.is_a?(Struct::Group).should == true
|
26
|
+
gr.gid.should == @gid
|
27
|
+
gr.name.should == @name
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns the Struct::Group for a given gid if it exists" do
|
31
|
+
grp = Etc.getgrgid(@gid)
|
32
|
+
grp.should be_kind_of(Struct::Group)
|
33
|
+
grp.gid.should == @gid
|
34
|
+
grp.name.should == @name
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
ruby_version_is "1.9" do
|
39
|
+
it "returns a Etc::Group struct instance for the given user" do
|
40
|
+
gr = Etc.getgrgid(@gid)
|
41
|
+
|
42
|
+
gr.is_a?(Etc::Group).should == true
|
43
|
+
gr.gid.should == @gid
|
44
|
+
gr.name.should == @name
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns the Etc::Group for a given gid if it exists" do
|
48
|
+
grp = Etc.getgrgid(@gid)
|
49
|
+
grp.should be_kind_of(Etc::Group)
|
50
|
+
grp.gid.should == @gid
|
51
|
+
grp.name.should == @name
|
52
|
+
end
|
53
|
+
|
54
|
+
it "uses Process.gid as the default value for the argument" do
|
55
|
+
gr = Etc.getgrgid
|
56
|
+
|
57
|
+
gr.gid.should == @gid
|
58
|
+
gr.name.should == @name
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "returns the Group for a given gid if it exists" do
|
63
|
+
grp = Etc.getgrgid(@gid)
|
64
|
+
grp.should be_kind_of(Struct::Group)
|
65
|
+
grp.gid.should == @gid
|
66
|
+
grp.name.should == @name
|
67
|
+
end
|
68
|
+
|
69
|
+
it "raises if the group does not exist" do
|
70
|
+
lambda { Etc.getgrgid(9876)}.should raise_error(ArgumentError)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "raises a TypeError if not passed an Integer" do
|
74
|
+
lambda { Etc.getgrgid("foo") }.should raise_error(TypeError)
|
75
|
+
lambda { Etc.getgrgid(nil) }.should raise_error(TypeError)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'etc'
|
2
|
+
|
3
|
+
platform_is :windows do
|
4
|
+
describe "Etc.getgrnam" do
|
5
|
+
it "returns nil" do
|
6
|
+
Etc.getgrnam(1).should == nil
|
7
|
+
Etc.getgrnam(nil).should == nil
|
8
|
+
Etc.getgrnam('nil').should == nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
platform_is_not :windows do
|
14
|
+
describe "Etc.getgrnam" do
|
15
|
+
ruby_version_is "" ... "1.9" do
|
16
|
+
it "returns a Struct::Group struct instance for the given group" do
|
17
|
+
gr = Etc.getgrnam("daemon")
|
18
|
+
gr.is_a?(Struct::Group).should == true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
ruby_version_is "1.9" do
|
23
|
+
it "returns a Etc::Group struct instance for the given group" do
|
24
|
+
gr = Etc.getgrnam("daemon")
|
25
|
+
gr.is_a?(Etc::Group).should == true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "only accepts strings as argument" do
|
30
|
+
lambda {
|
31
|
+
Etc.getgrnam(123)
|
32
|
+
Etc.getgrnam(nil)
|
33
|
+
}.should raise_error(TypeError)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'etc'
|
2
|
+
|
3
|
+
describe "Etc.getlogin" do
|
4
|
+
it "returns the name of the user who runs this process" do
|
5
|
+
if Etc.getlogin
|
6
|
+
Etc.getlogin.should == username
|
7
|
+
else
|
8
|
+
# Etc.getlogin may return nil if the login name is not set
|
9
|
+
# because of chroot or sudo or something.
|
10
|
+
Etc.getlogin.should be_nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'etc'
|
2
|
+
|
3
|
+
platform_is :windows do
|
4
|
+
describe "Etc.getpwnam" do
|
5
|
+
it "returns nil" do
|
6
|
+
Etc.getpwnam(1).should == nil
|
7
|
+
Etc.getpwnam(nil).should == nil
|
8
|
+
Etc.getpwnam('nil').should == nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
platform_is_not :windows do
|
14
|
+
describe "Etc.getpwnam" do
|
15
|
+
ruby_version_is "" ... "1.9" do
|
16
|
+
it "returns a Passwd struct instance for the given user" do
|
17
|
+
pw = Etc.getpwnam(`whoami`.strip)
|
18
|
+
pw.is_a?(Struct::Passwd).should == true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
ruby_version_is "1.9" do
|
23
|
+
it "returns a Etc::Passwd struct instance for the given user" do
|
24
|
+
pw = Etc.getpwnam(`whoami`.strip)
|
25
|
+
pw.is_a?(Etc::Passwd).should == true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "only accepts strings as argument" do
|
30
|
+
lambda {
|
31
|
+
Etc.getpwnam(123)
|
32
|
+
Etc.getpwnam(nil)
|
33
|
+
}.should raise_error(TypeError)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'etc'
|
2
|
+
|
3
|
+
platform_is :windows do
|
4
|
+
describe "Etc.getpwuid" do
|
5
|
+
it "returns nil" do
|
6
|
+
Etc.getpwuid(1).should == nil
|
7
|
+
Etc.getpwuid(nil).should == nil
|
8
|
+
Etc.getpwuid('nil').should == nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
platform_is_not :windows do
|
14
|
+
describe "Etc.getpwuid" do
|
15
|
+
before :all do
|
16
|
+
@pw = Etc.getpwuid(`id -u`.strip.to_i)
|
17
|
+
end
|
18
|
+
|
19
|
+
ruby_version_is "" ... "1.9" do
|
20
|
+
it "returns a Struct::Passwd struct instance for the given user" do
|
21
|
+
@pw.is_a?(Struct::Passwd).should == true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
ruby_version_is "1.9" do
|
26
|
+
it "returns a Etc::Passwd struct instance for the given user" do
|
27
|
+
@pw.is_a?(Etc::Passwd).should == true
|
28
|
+
end
|
29
|
+
|
30
|
+
it "uses Process.uid as the default value for the argument" do
|
31
|
+
pw = Etc.getpwuid
|
32
|
+
pw.should == @pw
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "only accepts integers as argument" do
|
37
|
+
lambda {
|
38
|
+
Etc.getpwuid("foo")
|
39
|
+
Etc.getpwuid(nil)
|
40
|
+
}.should raise_error(TypeError)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/group_spec.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path('../shared/windows', __FILE__)
|
2
|
+
require 'etc'
|
3
|
+
|
4
|
+
describe "Etc.group" do
|
5
|
+
it_behaves_like(:etc_on_windows, :group)
|
6
|
+
|
7
|
+
it "raises a RuntimeError for parallel iteration" do
|
8
|
+
proc {
|
9
|
+
Etc.group do | group |
|
10
|
+
Etc.group do | group2 |
|
11
|
+
end
|
12
|
+
end
|
13
|
+
}.should raise_error(RuntimeError)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/spec/passwd_spec.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'etc'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'etc'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'etc'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'etc'
|
2
|
+
|
3
|
+
describe "Struct::Group" do
|
4
|
+
platform_is_not :windows do
|
5
|
+
before :all do
|
6
|
+
@g = Etc.getgrgid(`id -g`.strip.to_i)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns group name" do
|
10
|
+
@g.name.should == `id -gn`.strip
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns group password" do
|
14
|
+
@g.passwd.is_a?(String).should == true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns group id" do
|
18
|
+
@g.gid.should == `id -g`.strip.to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns an array of users belonging to the group" do
|
22
|
+
@g.mem.is_a?(Array).should == true
|
23
|
+
end
|
24
|
+
|
25
|
+
it "can be compared to another object" do
|
26
|
+
(@g == nil).should == false
|
27
|
+
(@g == Object.new).should == false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'etc'
|
2
|
+
|
3
|
+
describe "Struct::Passwd" do
|
4
|
+
platform_is_not :windows do
|
5
|
+
before :all do
|
6
|
+
@pw = Etc.getpwuid(`id -u`.strip.to_i)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns user name" do
|
10
|
+
@pw.name.should == `id -un`.strip
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns user password" do
|
14
|
+
@pw.passwd.is_a?(String).should == true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns user id" do
|
18
|
+
@pw.uid.should == `id -u`.strip.to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns user group id" do
|
22
|
+
@pw.gid.should == `id -g`.strip.to_i
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns user personal information (gecos field)" do
|
26
|
+
@pw.gecos.is_a?(String).should == true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns user home directory" do
|
30
|
+
@pw.dir.is_a?(String).should == true
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns user shell" do
|
34
|
+
@pw.shell.is_a?(String).should == true
|
35
|
+
end
|
36
|
+
|
37
|
+
it "can be compared to another object" do
|
38
|
+
(@pw == nil).should == false
|
39
|
+
(@pw == Object.new).should == false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
CHANGED
@@ -1,118 +1,116 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubysl-etc
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 1
|
10
|
-
version: 0.0.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Brian Shirai
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
date: 2013-08-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
22
21
|
prerelease: false
|
23
|
-
|
24
|
-
|
25
|
-
requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
26
24
|
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
|
30
|
-
- 1
|
31
|
-
- 0
|
32
|
-
version: "1.0"
|
33
|
-
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
36
28
|
name: rake
|
37
|
-
|
38
|
-
|
39
|
-
none: false
|
40
|
-
requirements:
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
41
31
|
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 10
|
46
|
-
- 0
|
47
|
-
version: "10.0"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
48
34
|
type: :development
|
49
|
-
version_requirements: *id002
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
name: mspec
|
52
35
|
prerelease: false
|
53
|
-
|
54
|
-
|
55
|
-
requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
56
38
|
- - ~>
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
- 5
|
62
|
-
version: "1.5"
|
63
|
-
type: :development
|
64
|
-
version_requirements: *id003
|
65
|
-
description: Ruby Standard Library - etc
|
66
|
-
email:
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Ruby standard library etc.
|
42
|
+
email:
|
67
43
|
- brixen@gmail.com
|
68
44
|
executables: []
|
69
|
-
|
70
|
-
|
71
|
-
|
45
|
+
extensions:
|
46
|
+
- lib/rubysl/etc/extconf.rb
|
72
47
|
extra_rdoc_files: []
|
73
|
-
|
74
|
-
files:
|
48
|
+
files:
|
75
49
|
- .gitignore
|
50
|
+
- .travis.yml
|
76
51
|
- Gemfile
|
77
52
|
- LICENSE
|
78
53
|
- README.md
|
79
54
|
- Rakefile
|
80
|
-
- lib/rubysl
|
81
|
-
- lib/rubysl
|
55
|
+
- lib/rubysl/etc.rb
|
56
|
+
- lib/rubysl/etc/etc.rb.ffi
|
57
|
+
- lib/rubysl/etc/extconf.rb
|
58
|
+
- lib/rubysl/etc/version.rb
|
82
59
|
- rubysl-etc.gemspec
|
83
|
-
|
84
|
-
|
85
|
-
|
60
|
+
- spec/endgrent_spec.rb
|
61
|
+
- spec/endpwent_spec.rb
|
62
|
+
- spec/getgrent_spec.rb
|
63
|
+
- spec/getgrgid_spec.rb
|
64
|
+
- spec/getgrnam_spec.rb
|
65
|
+
- spec/getlogin_spec.rb
|
66
|
+
- spec/getpwent_spec.rb
|
67
|
+
- spec/getpwnam_spec.rb
|
68
|
+
- spec/getpwuid_spec.rb
|
69
|
+
- spec/group_spec.rb
|
70
|
+
- spec/passwd_spec.rb
|
71
|
+
- spec/setgrent_spec.rb
|
72
|
+
- spec/setpwent_spec.rb
|
73
|
+
- spec/shared/windows.rb
|
74
|
+
- spec/struct_group_spec.rb
|
75
|
+
- spec/struct_passwd_spec.rb
|
76
|
+
homepage: https://github.com/rubysl/rubysl-etc
|
77
|
+
licenses:
|
78
|
+
- BSD
|
79
|
+
metadata: {}
|
86
80
|
post_install_message:
|
87
81
|
rdoc_options: []
|
88
|
-
|
89
|
-
require_paths:
|
82
|
+
require_paths:
|
90
83
|
- lib
|
91
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
none: false
|
102
|
-
requirements:
|
103
|
-
- - ">="
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
hash: 2002549777813010636
|
106
|
-
segments:
|
107
|
-
- 0
|
108
|
-
version: "0"
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
109
94
|
requirements: []
|
110
|
-
|
111
95
|
rubyforge_project:
|
112
|
-
rubygems_version:
|
96
|
+
rubygems_version: 2.0.3
|
113
97
|
signing_key:
|
114
|
-
specification_version:
|
115
|
-
summary: Ruby
|
116
|
-
test_files:
|
117
|
-
|
118
|
-
|
98
|
+
specification_version: 4
|
99
|
+
summary: Ruby standard library etc.
|
100
|
+
test_files:
|
101
|
+
- spec/endgrent_spec.rb
|
102
|
+
- spec/endpwent_spec.rb
|
103
|
+
- spec/getgrent_spec.rb
|
104
|
+
- spec/getgrgid_spec.rb
|
105
|
+
- spec/getgrnam_spec.rb
|
106
|
+
- spec/getlogin_spec.rb
|
107
|
+
- spec/getpwent_spec.rb
|
108
|
+
- spec/getpwnam_spec.rb
|
109
|
+
- spec/getpwuid_spec.rb
|
110
|
+
- spec/group_spec.rb
|
111
|
+
- spec/passwd_spec.rb
|
112
|
+
- spec/setgrent_spec.rb
|
113
|
+
- spec/setpwent_spec.rb
|
114
|
+
- spec/shared/windows.rb
|
115
|
+
- spec/struct_group_spec.rb
|
116
|
+
- spec/struct_passwd_spec.rb
|