Class: UnixUserManager::File::Base
- Inherits:
-
Object
- Object
- UnixUserManager::File::Base
- Defined in:
- lib/unix_user_manager/file/base.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#new_records ⇒ Object
readonly
Returns the value of attribute new_records.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #all ⇒ Object
- #build ⇒ Object
- #build_new_records ⇒ Object
- #can_add?(name, id = nil) ⇒ Boolean
- #exist?(name) ⇒ Boolean
- #find(name) ⇒ Object
- #find_by_id(id) ⇒ Object
- #id_exist?(id) ⇒ Boolean
- #ids ⇒ Object
-
#initialize(source) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(source) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 10 |
# File 'lib/unix_user_manager/file/base.rb', line 5 def initialize(source) @source = source @new_records = Hash.new { |h, k| h[k] = { id: nil } } parse_file end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/unix_user_manager/file/base.rb', line 3 def data @data end |
#new_records ⇒ Object (readonly)
Returns the value of attribute new_records.
3 4 5 |
# File 'lib/unix_user_manager/file/base.rb', line 3 def new_records @new_records end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
3 4 5 |
# File 'lib/unix_user_manager/file/base.rb', line 3 def source @source end |
Instance Method Details
#all ⇒ Object
38 39 40 |
# File 'lib/unix_user_manager/file/base.rb', line 38 def all data end |
#build ⇒ Object
42 43 44 |
# File 'lib/unix_user_manager/file/base.rb', line 42 def build @new_records.any? ? (source + "\n" + build_new_records) : source end |
#build_new_records ⇒ Object
46 47 48 |
# File 'lib/unix_user_manager/file/base.rb', line 46 def build_new_records raise NotImplementedError end |
#can_add?(name, id = nil) ⇒ Boolean
34 35 36 |
# File 'lib/unix_user_manager/file/base.rb', line 34 def can_add?(name, id = nil) !(exist?(name) || id_exist?(id) || @new_records.key?(name)) end |
#exist?(name) ⇒ Boolean
24 25 26 |
# File 'lib/unix_user_manager/file/base.rb', line 24 def exist?(name) !!data[name] end |
#find(name) ⇒ Object
16 17 18 |
# File 'lib/unix_user_manager/file/base.rb', line 16 def find(name) data[name] end |
#find_by_id(id) ⇒ Object
20 21 22 |
# File 'lib/unix_user_manager/file/base.rb', line 20 def find_by_id(id) data.key id end |
#id_exist?(id) ⇒ Boolean
28 29 30 31 32 |
# File 'lib/unix_user_manager/file/base.rb', line 28 def id_exist?(id) return false if id.nil? !!data.key(id) end |
#ids ⇒ Object
12 13 14 |
# File 'lib/unix_user_manager/file/base.rb', line 12 def ids data.values.sort end |