linux_admin 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7a836fda94b3dbbc618dcab138690adde8e2803a
4
- data.tar.gz: b3e87b291a6dba82b58a0b924c44fb41dbebadb1
2
+ SHA256:
3
+ metadata.gz: b829f3cc2362f608bad95b43d9e3fe8b97a57bf027c84d16cd38c758dc841840
4
+ data.tar.gz: 0f9741c5305f8dee09358f9c1c44edf12ad150fa11a79514c59a8110c8254094
5
5
  SHA512:
6
- metadata.gz: 78b8cd87fcbc328aa5c5910ab26b201bb48cd2f19029bc7da944c50bccc4d1a21324507e4c762fe76221604fe303a0f6f5fab1cac18b513780619aa2bcbd1a51
7
- data.tar.gz: 5c2f30b0e6ac5fc86bb116ad68dfe3e5b25b446742ad16e23cb0866f4f68582d1297b6027c4945c91e4dffeb69f7a9e962b78f7c2d3b4127a91bc780dda7d055
6
+ metadata.gz: e80cc3ce27b7b68d4d74947e81d8fa9451849aa0995a008874ec741ad30ff57a9c7306fca270299463a22785a490722aa55a0ffa036dd03903a6e79517beb755
7
+ data.tar.gz: 6887b3343ea5220c23c86373e049d4ff497babdda16bc70b8d542d506641575392092a3ecf1b85ec42060d31fc6f263efe5e29cd3fcb9bc7e7696bf100ccce83
@@ -25,13 +25,13 @@ module LinuxAdmin
25
25
  comment = "##{comment}" unless comment.blank?
26
26
  columns = columns.chomp.split
27
27
 
28
- FSTabEntry.new :device => columns[0],
28
+ FSTabEntry.new(:device => columns[0],
29
29
  :mount_point => columns[1],
30
30
  :fs_type => columns[2],
31
31
  :mount_options => columns[3],
32
32
  :dumpable => columns[4],
33
33
  :fsck_order => columns[5],
34
- :comment => comment
34
+ :comment => comment)
35
35
  end
36
36
 
37
37
  def has_content?
@@ -44,30 +44,35 @@ module LinuxAdmin
44
44
  end
45
45
 
46
46
  def column_lengths
47
- self.columns.collect { |c| c ? c.size : 0 }
47
+ columns.collect { |c| c ? c.to_s.size : 0 }
48
48
  end
49
49
 
50
50
  def formatted_columns(max_lengths)
51
51
  self.columns.collect.
52
- with_index { |col, i| col.to_s.rjust(max_lengths[i]) }.join(" ")
52
+ with_index { |col, i| col.to_s.rjust(max_lengths[i]) }.join(" ").rstrip
53
53
  end
54
54
  end
55
55
 
56
56
  class FSTab
57
57
  include Singleton
58
58
 
59
- attr_accessor :entries
60
- attr_accessor :maximum_column_lengths
61
-
62
59
  def initialize
63
60
  refresh
64
61
  end
65
62
 
63
+ def entries
64
+ @entries ||= LinuxAdmin::FSTab::EntryCollection.new
65
+ end
66
+
67
+ def maximum_column_lengths
68
+ entries.maximum_column_lengths
69
+ end
70
+
66
71
  def write!
67
72
  content = ''
68
- @entries.each do |entry|
73
+ entries.each do |entry|
69
74
  if entry.has_content?
70
- content << entry.formatted_columns(@maximum_column_lengths) << "\n"
75
+ content << entry.formatted_columns(entries.maximum_column_lengths) << "\n"
71
76
  else
72
77
  content << "#{entry.comment}"
73
78
  end
@@ -84,17 +89,27 @@ module LinuxAdmin
84
89
  end
85
90
 
86
91
  def refresh
87
- @entries = []
88
- @maximum_column_lengths = Array.new(7, 0) # # of columns
92
+ @entries = nil
89
93
  read.each do |line|
90
94
  entry = FSTabEntry.from_line(line)
91
- @entries << entry
95
+ entries << entry
96
+ end
97
+ end
98
+
99
+ class EntryCollection < Array
100
+ attr_reader :maximum_column_lengths
92
101
 
102
+ def initialize
103
+ @maximum_column_lengths = Array.new(7, 0) # # of columns
104
+ end
105
+
106
+ def <<(entry)
93
107
  lengths = entry.column_lengths
94
108
  lengths.each_index do |i|
95
- @maximum_column_lengths[i] =
96
- lengths[i] if lengths[i] > @maximum_column_lengths[i]
109
+ maximum_column_lengths[i] = [lengths[i], maximum_column_lengths[i]].max
97
110
  end
111
+
112
+ super
98
113
  end
99
114
  end
100
115
  end
@@ -1,3 +1,3 @@
1
1
  module LinuxAdmin
2
- VERSION = "1.2.3".freeze
2
+ VERSION = "1.2.4".freeze
3
3
  end
@@ -46,20 +46,86 @@ eos
46
46
 
47
47
  describe "#write!" do
48
48
  it "writes entries to /etc/fstab" do
49
- # maually set fstab
50
- entry = LinuxAdmin::FSTabEntry.new
51
- entry.device = '/dev/sda1'
52
- entry.mount_point = '/'
53
- entry.fs_type = 'ext4'
54
- entry.mount_options = 'defaults'
55
- entry.dumpable = 1
56
- entry.fsck_order = 1
57
- entry.comment = "# more"
58
- allow_any_instance_of(subject).to receive(:refresh) # in case this is the first time we reference .instance
59
- subject.instance.maximum_column_lengths = [9, 1, 4, 8, 1, 1, 1]
60
- subject.instance.entries = [entry]
49
+ expect(File).to receive(:read).with("/etc/fstab").and_return("")
50
+
51
+ subject.instance.entries << LinuxAdmin::FSTabEntry.new(
52
+ :device => '/dev/sda1',
53
+ :mount_point => '/',
54
+ :fs_type => 'ext4',
55
+ :mount_options => 'defaults',
56
+ :dumpable => 1,
57
+ :fsck_order => 1,
58
+ :comment => "# more"
59
+ )
61
60
 
62
61
  expect(File).to receive(:write).with('/etc/fstab', "/dev/sda1 / ext4 defaults 1 1 # more\n")
62
+
63
+ subject.instance.write!
64
+ end
65
+ end
66
+
67
+ describe "#entries" do
68
+ it "#<< updates maximum_column_lengths" do
69
+ expect(File).to receive(:read).with("/etc/fstab").and_return("")
70
+
71
+ subject.instance.entries << LinuxAdmin::FSTabEntry.new(
72
+ :device => '/dev/sda1',
73
+ :mount_point => '/',
74
+ :fs_type => 'ext4',
75
+ :mount_options => 'defaults',
76
+ :dumpable => 1,
77
+ :fsck_order => 1,
78
+ :comment => "# more"
79
+ )
80
+
81
+ expect(subject.instance.entries.maximum_column_lengths).to eq([9, 1, 4, 8, 1, 1, 6])
82
+ end
83
+ end
84
+
85
+ describe "integration test" do
86
+ it "input equals output, just alignment changed" do
87
+ original_fstab = <<~END_OF_FSTAB
88
+
89
+ #
90
+ # /etc/fstab
91
+ # Created by anaconda on Wed May 29 12:37:40 2019
92
+ #
93
+ # Accessible filesystems, by reference, are maintained under '/dev/disk'
94
+ # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
95
+ #
96
+ /dev/mapper/VG--MIQ-lv_os / xfs defaults 0 0
97
+ UUID=02bf07b5-2404-4779-b93c-d8eb7f2eedea /boot xfs defaults 0 0
98
+ /dev/mapper/VG--MIQ-lv_home /home xfs defaults 0 0
99
+ /dev/mapper/VG--MIQ-lv_tmp /tmp xfs defaults 0 0
100
+ /dev/mapper/VG--MIQ-lv_var /var xfs defaults 0 0
101
+ /dev/mapper/VG--MIQ-lv_var_log /var/log xfs defaults 0 0
102
+ /dev/mapper/VG--MIQ-lv_var_log_audit /var/log/audit xfs defaults 0 0
103
+ /dev/mapper/VG--MIQ-lv_log /var/www/miq/vmdb/log xfs defaults 0 0
104
+ /dev/mapper/VG--MIQ-lv_swap swap swap defaults 0 0
105
+ END_OF_FSTAB
106
+
107
+ new_fstab = <<~END_OF_FSTAB
108
+
109
+ # /etc/fstab
110
+ # Created by anaconda on Wed May 29 12:37:40 2019
111
+
112
+ # Accessible filesystems, by reference, are maintained under '/dev/disk'
113
+ # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
114
+
115
+ /dev/mapper/VG--MIQ-lv_os / xfs defaults 0 0
116
+ UUID=02bf07b5-2404-4779-b93c-d8eb7f2eedea /boot xfs defaults 0 0
117
+ /dev/mapper/VG--MIQ-lv_home /home xfs defaults 0 0
118
+ /dev/mapper/VG--MIQ-lv_tmp /tmp xfs defaults 0 0
119
+ /dev/mapper/VG--MIQ-lv_var /var xfs defaults 0 0
120
+ /dev/mapper/VG--MIQ-lv_var_log /var/log xfs defaults 0 0
121
+ /dev/mapper/VG--MIQ-lv_var_log_audit /var/log/audit xfs defaults 0 0
122
+ /dev/mapper/VG--MIQ-lv_log /var/www/miq/vmdb/log xfs defaults 0 0
123
+ /dev/mapper/VG--MIQ-lv_swap swap swap defaults 0 0
124
+ END_OF_FSTAB
125
+
126
+ expect(File).to receive(:read).with("/etc/fstab").and_return(original_fstab)
127
+ expect(File).to receive(:write).with("/etc/fstab", new_fstab)
128
+
63
129
  subject.instance.write!
64
130
  end
65
131
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linux_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Dunne
@@ -24,7 +24,7 @@ authors:
24
24
  autorequire:
25
25
  bindir: bin
26
26
  cert_chain: []
27
- date: 2019-05-14 00:00:00.000000000 Z
27
+ date: 2019-07-08 00:00:00.000000000 Z
28
28
  dependencies:
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: rake
@@ -326,7 +326,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
326
326
  version: '0'
327
327
  requirements: []
328
328
  rubyforge_project:
329
- rubygems_version: 2.6.14.3
329
+ rubygems_version: 2.7.6.2
330
330
  signing_key:
331
331
  specification_version: 4
332
332
  summary: LinuxAdmin is a module to simplify management of linux systems.