Class: ReservedSubdomain::File
- Inherits:
-
Object
- Object
- ReservedSubdomain::File
- Defined in:
- lib/reserved_subdomain/file.rb
Constant Summary collapse
- DIRECTORY =
::File.join(__dir__, 'literals')
Instance Attribute Summary collapse
-
#fileroot ⇒ Object
readonly
Returns the value of attribute fileroot.
-
#literals ⇒ Object
Returns the value of attribute literals.
Class Method Summary collapse
Instance Method Summary collapse
- #dedupe!(content) ⇒ Object
-
#initialize(fileroot = '*') ⇒ File
constructor
A new instance of File.
- #remove_reserved! ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(fileroot = '*') ⇒ File
13 14 15 16 |
# File 'lib/reserved_subdomain/file.rb', line 13 def initialize(fileroot = '*') @fileroot = fileroot @literals = files.map { |filename| ::File.read(filename).split("\n") }.compact.flatten end |
Instance Attribute Details
#fileroot ⇒ Object (readonly)
Returns the value of attribute fileroot.
11 12 13 |
# File 'lib/reserved_subdomain/file.rb', line 11 def fileroot @fileroot end |
#literals ⇒ Object
Returns the value of attribute literals.
11 12 13 |
# File 'lib/reserved_subdomain/file.rb', line 11 def literals @literals end |
Class Method Details
.load(fileroot = '*') ⇒ Object
6 7 8 |
# File 'lib/reserved_subdomain/file.rb', line 6 def load(fileroot = '*') new(fileroot).literals end |
Instance Method Details
#dedupe!(content) ⇒ Object
27 28 29 30 |
# File 'lib/reserved_subdomain/file.rb', line 27 def dedupe!(content) literals.reject! { |literal| content.include?(literal) } self end |
#remove_reserved! ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/reserved_subdomain/file.rb', line 32 def remove_reserved! literals.reject! do |literal| (literal =~ /^#/) || ReservedSubdomain::Prefix.new(literal).reserved? || ReservedSubdomain::Pattern.new(literal).reserved? end self end |
#save ⇒ Object
22 23 24 25 |
# File 'lib/reserved_subdomain/file.rb', line 22 def save ::File.open(files.first, 'w') { |f| f.write literals.join("\n") } self end |