Class: Appfuel::Initialize::Initializer
- Inherits:
-
Object
- Object
- Appfuel::Initialize::Initializer
- Defined in:
- lib/appfuel/initialize/initializer.rb
Overview
The client application will declare a series of initializer blocks. Each of these blocks are represented as this class. This allows us to save the block to be later executed along with info about which environments this can run on
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#envs ⇒ Object
readonly
Returns the value of attribute envs.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #add_env(name) ⇒ Array
-
#call(config, container) ⇒ Object
Delegate to executing the stored code.
-
#env_allowed?(env) ⇒ Bool
Determines which env this is allowed to execute on.
-
#initialize(name, env = [], &block) ⇒ Initializer
constructor
Ensure each environment is stored as a lowercased string, convert the name to a string as save the block to be executed later.
Constructor Details
#initialize(name, env = [], &block) ⇒ Initializer
Ensure each environment is stored as a lowercased string, convert the name to a string as save the block to be executed later
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/appfuel/initialize/initializer.rb', line 20 def initialize(name, env = [], &block) @name = name.to_s @envs = [] env = [env] if env.is_a?(String) || env.is_a?(Symbol) env = [] if env.nil? unless env.is_a?(Array) fail ArgumentError, "environments must be a string, symbol or array" end env.each {|item| add_env(item) } fail ArgumentError, "initializer requires a block" unless block_given? @code = block end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
8 9 10 |
# File 'lib/appfuel/initialize/initializer.rb', line 8 def code @code end |
#envs ⇒ Object (readonly)
Returns the value of attribute envs.
8 9 10 |
# File 'lib/appfuel/initialize/initializer.rb', line 8 def envs @envs end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/appfuel/initialize/initializer.rb', line 8 def name @name end |
Instance Method Details
#add_env(name) ⇒ Array
51 52 53 54 55 |
# File 'lib/appfuel/initialize/initializer.rb', line 51 def add_env(name) name = name.to_s.downcase fail "env already exists" if envs.include?(name) envs << name.to_s.downcase end |
#call(config, container) ⇒ Object
Delegate to executing the stored code
62 63 64 65 |
# File 'lib/appfuel/initialize/initializer.rb', line 62 def call(config, container) code.call(config, container) nil end |
#env_allowed?(env) ⇒ Bool
Determines which env this is allowed to execute on. No enironment means it it is allow to execute on all
41 42 43 44 45 |
# File 'lib/appfuel/initialize/initializer.rb', line 41 def env_allowed?(env) return true if envs.empty? envs.include?(env.to_s.downcase) end |