Class: ReservedSubdomain::Literal
- Inherits:
-
Object
- Object
- ReservedSubdomain::Literal
- Defined in:
- lib/reserved_subdomain/literal.rb
Instance Attribute Summary collapse
-
#subdomain ⇒ Object
readonly
Returns the value of attribute subdomain.
Class Method Summary collapse
-
.literals ⇒ Object
If the env var is set then we pre-load all the reserved literals into a big array.
- .load_literals ⇒ Object
Instance Method Summary collapse
-
#initialize(subdomain) ⇒ Literal
constructor
A new instance of Literal.
- #reserved? ⇒ Boolean
Constructor Details
#initialize(subdomain) ⇒ Literal
32 33 34 |
# File 'lib/reserved_subdomain/literal.rb', line 32 def initialize(subdomain) @subdomain = subdomain end |
Instance Attribute Details
#subdomain ⇒ Object (readonly)
Returns the value of attribute subdomain.
30 31 32 |
# File 'lib/reserved_subdomain/literal.rb', line 30 def subdomain @subdomain end |
Class Method Details
.literals ⇒ Object
If the env var is set then we pre-load all the reserved literals into a big array. This makes checking for reserved subdomains quicker but at the expense of keeping the big array in memory.
If you’re only checking for reserved subdomains when a user creates a new account then it may be better to load the literals from the file each time.
11 12 13 |
# File 'lib/reserved_subdomain/literal.rb', line 11 def literals @literals ||= ENV['RESERVED_SUBDOMAIN_PRELOAD'] ? load_literals : nil end |
.load_literals ⇒ Object
15 16 17 |
# File 'lib/reserved_subdomain/literal.rb', line 15 def load_literals literals_files.map { |filename| File.read(filename).split("\n") }.compact.flatten end |
Instance Method Details
#reserved? ⇒ Boolean
36 37 38 |
# File 'lib/reserved_subdomain/literal.rb', line 36 def reserved? literals.include? subdomain end |