Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Amber currently ships with 3 different environments: development, test and production. As a developer I would like to sometimes run code conditionally depending on the environment that the application is. ```crystal if Amber::Env.development? # ... code here ... end ``` This PR addresses the issue by creating a Amber::Env module that contains 3 module methods: Amber::Env.development? Amber::Env.test? Amber::Env.production? With the changes in this PR a developer should be able to call the appropriate method to check for the desired environment.
- Loading branch information
Showing
3 changed files
with
28 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require "../../../spec_helper" | ||
|
||
describe Amber::Env do | ||
{% for env in Amber::Env::ENVIRONMENTS %} | ||
describe ".{{env.id}}?" do | ||
it "returns true when the environment is {{env.id}}" do | ||
Amber::Settings.env = {{env}} | ||
Amber::Env.{{env.id}}?.should eq true | ||
end | ||
|
||
it "returns false when the environment does not match" do | ||
Amber::Settings.env = "invalid environment" | ||
Amber::Env.{{env.id}}?.should eq false | ||
end | ||
end | ||
{% end %} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Amber | ||
module ENV | ||
{% for env in Settings::ENVIRONMENTS %} | ||
def self.{{env.id}}? | ||
Settings.env.not_nil!.downcase == {{env.downcase.id.stringify}} | ||
end | ||
{% end %} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters