Class: Penchant::FileProcessor
- Inherits:
-
Object
- Object
- Penchant::FileProcessor
- Defined in:
- lib/penchant/file_processor.rb
Constant Summary collapse
- ANY_ENVIRONMENT =
:any_environment
Instance Attribute Summary collapse
-
#available_environments ⇒ Object
readonly
Returns the value of attribute available_environments.
-
#defined_git_repos ⇒ Object
readonly
Returns the value of attribute defined_git_repos.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#is_deployment ⇒ Object
readonly
Returns the value of attribute is_deployment.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(string) ⇒ Object
- #defaults_for(*args) ⇒ Object
- #ensure_git_hooks! ⇒ Object
- #env(*args) ⇒ Object
- #for_environment?(envs) ⇒ Boolean
-
#initialize(data) ⇒ FileProcessor
constructor
A new instance of FileProcessor.
- #no_deployment ⇒ Object
- #opposites(left, right) ⇒ Object
- #os(*args) ⇒ Object
- #property(name, hash = nil, &block) ⇒ Object
- #result(_env, _is_deployment) ⇒ Object
Constructor Details
#initialize(data) ⇒ FileProcessor
11 12 13 14 15 16 17 18 19 |
# File 'lib/penchant/file_processor.rb', line 11 def initialize(data) @data = data @available_environments = [] @defined_git_repos = [] @defaults = Defaults.new @properties = PropertyStackBuilder.new(@defaults) @_current_env_defaults = {} end |
Instance Attribute Details
#available_environments ⇒ Object (readonly)
Returns the value of attribute available_environments.
3 4 5 |
# File 'lib/penchant/file_processor.rb', line 3 def available_environments @available_environments end |
#defined_git_repos ⇒ Object (readonly)
Returns the value of attribute defined_git_repos.
3 4 5 |
# File 'lib/penchant/file_processor.rb', line 3 def defined_git_repos @defined_git_repos end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
3 4 5 |
# File 'lib/penchant/file_processor.rb', line 3 def environment @environment end |
#is_deployment ⇒ Object (readonly)
Returns the value of attribute is_deployment.
3 4 5 |
# File 'lib/penchant/file_processor.rb', line 3 def is_deployment @is_deployment end |
Class Method Details
.result(data, *args) ⇒ Object
7 8 9 |
# File 'lib/penchant/file_processor.rb', line 7 def self.result(data, *args) new(data).result(*args) end |
Instance Method Details
#<<(string) ⇒ Object
32 33 34 |
# File 'lib/penchant/file_processor.rb', line 32 def <<(string) @output << string end |
#defaults_for(*args) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/penchant/file_processor.rb', line 90 def defaults_for(*args) defaults = args.pop args.flatten.each do |gem| @defaults[gem].merge!(defaults) end end |
#ensure_git_hooks! ⇒ Object
82 83 84 |
# File 'lib/penchant/file_processor.rb', line 82 def ensure_git_hooks! Penchant::Hooks.install! end |
#env(*args) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/penchant/file_processor.rb', line 36 def env(*args) = {} = args.pop if args.last.kind_of?(::Hash) @available_environments += args requested_env_defaults = _defaults_for(Env.new(environment)) if block_given? if for_environment?(args) @_current_env_defaults = requested_env_defaults yield @_current_env_defaults = {} else if opposite_environment = ([:opposite] or requested_env_defaults[:opposite]) if for_environment?([ environment, args, opposite_environment ].flatten.uniq) @_current_env_defaults = requested_env_defaults = true yield = false @_current_env_defaults = {} end end end else Env.new(args.shift) end end |
#for_environment?(envs) ⇒ Boolean
74 75 76 |
# File 'lib/penchant/file_processor.rb', line 74 def for_environment?(envs) envs.include?(environment) || environment == ANY_ENVIRONMENT end |
#no_deployment ⇒ Object
78 79 80 |
# File 'lib/penchant/file_processor.rb', line 78 def no_deployment yield if !is_deployment end |
#opposites(left, right) ⇒ Object
69 70 71 72 |
# File 'lib/penchant/file_processor.rb', line 69 def opposites(left, right) @defaults[Env.new(left)][:opposite] = right @defaults[Env.new(right)][:opposite] = left end |
#os(*args) ⇒ Object
86 87 88 |
# File 'lib/penchant/file_processor.rb', line 86 def os(*args) yield if args.include?(current_os) end |
#property(name, hash = nil, &block) ⇒ Object
65 66 67 |
# File 'lib/penchant/file_processor.rb', line 65 def property(name, hash = nil, &block) @properties[name] = hash || block end |
#result(_env, _is_deployment) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/penchant/file_processor.rb', line 21 def result(_env, _is_deployment) @environment = _env.to_s.to_sym @is_deployment = _is_deployment @output = [] instance_eval(@data) @output.join("\n") end |