Class: Lennarb::Environment
- Inherits:
-
Object
- Object
- Lennarb::Environment
- Defined in:
- lib/lennarb/environment.rb
Overview
Manage the environment of the application.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the name of the environment.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?, #equal?, #===)
Implements equality for the environment.
-
#development? ⇒ Boolean
Returns true if the environment is development.
-
#initialize(name) ⇒ Environment
constructor
Initialize the environment.
-
#inspect ⇒ Object
Returns the name of the environment as a string.
-
#local? ⇒ Boolean
Returns true if the environment is local (either ‘test` or `development`).
-
#on(*envs) ⇒ Object
Yields a block if the environment is the same as the given environment.
-
#production? ⇒ Boolean
Returns true if the environment is production.
-
#test? ⇒ Boolean
Returns true if the environment is test.
-
#to_s ⇒ Object
Returns the name of the environment as a string.
-
#to_sym ⇒ Object
Returns the name of the environment as a symbol.
Constructor Details
#initialize(name) ⇒ Environment
Initialize the environment.
@param name [String, Symbol] The name of the environment.
17 18 19 20 21 22 23 |
# File 'lib/lennarb/environment.rb', line 17 def initialize(name) @name = name.to_sym return if NAMES.include?(@name) raise ArgumentError, "Invalid environment: #{@name.inspect}" end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the name of the environment.
12 13 14 |
# File 'lib/lennarb/environment.rb', line 12 def name @name end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?, equal?, ===
Implements equality for the environment.
43 |
# File 'lib/lennarb/environment.rb', line 43 def ==(other) = name == other || name.to_s == other |
#development? ⇒ Boolean
Returns true if the environment is development.
27 |
# File 'lib/lennarb/environment.rb', line 27 def development? = name == :development |
#inspect ⇒ Object
Returns the name of the environment as a string.
60 |
# File 'lib/lennarb/environment.rb', line 60 def inspect = to_s.inspect |
#local? ⇒ Boolean
Returns true if the environment is local (either ‘test` or `development`).
39 |
# File 'lib/lennarb/environment.rb', line 39 def local? = test? || development? |
#on(*envs) ⇒ Object
Yields a block if the environment is the same as the given environment.
-
To match all environments use ‘:any` or `:all`.
-
To match local environments use ‘:local`.
71 72 73 74 75 76 77 78 |
# File 'lib/lennarb/environment.rb', line 71 def on(*envs) matched = envs.include?(:any) || envs.include?(:all) || envs.include?(name) || (envs.include?(:local) && local?) yield if matched end |
#production? ⇒ Boolean
Returns true if the environment is production.
35 |
# File 'lib/lennarb/environment.rb', line 35 def production? = name == :production |
#test? ⇒ Boolean
Returns true if the environment is test.
31 |
# File 'lib/lennarb/environment.rb', line 31 def test? = name == :test |
#to_s ⇒ Object
Returns the name of the environment as a string.
56 |
# File 'lib/lennarb/environment.rb', line 56 def to_s = name.to_s |
#to_sym ⇒ Object
Returns the name of the environment as a symbol.
51 |
# File 'lib/lennarb/environment.rb', line 51 def to_sym = name |