Class: Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/release_party/environment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(party, config) ⇒ Environment

Returns a new instance of Environment.



7
8
9
10
11
# File 'lib/release_party/environment.rb', line 7

def initialize(party, config)
  @party = party
  @cap_config = config
  @variables = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/release_party/environment.rb', line 13

def method_missing(method_id, *args, &block)
  case method_id.to_s
  when /\A(.*)=\Z/
    @variables[$1.to_sym] = args.first || block

  else
    key = method_id.to_sym
    value = if @variables.key?(key)
              @variables[key]
            else
              @cap_config.fetch(key, defaults[key])
            end
    return value.call if value.is_a?(Proc)
    value

  end
end

Instance Attribute Details

#partyObject (readonly)

Returns the value of attribute party.



5
6
7
# File 'lib/release_party/environment.rb', line 5

def party
  @party
end

Instance Method Details

#defaultsObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/release_party/environment.rb', line 37

def defaults
  {
    :user => `git config user.name`.chomp,
    :branch => 'master',
    :stage => 'staging',
    :domain => 'releaseparty.org',
    :display_name => 'Release Party',
    :from_address => 'Release Party <[email protected]>',
    :smtp_address => 'localhost',
    :smtp_port => 25,
    :subject => Proc.new {"#{display_name} was released to http://#{domain}/"},
    :finished_stories => [],
    :known_bugs => [],
    :send_email => true,
    :template_engine => :haml,
    :deliver_stories => false,
    :template => 'config/release_party/template.text.html.haml',
  }
end

#load_release_fileObject

Process the Releasefile and merge the variables loaded



32
33
34
35
# File 'lib/release_party/environment.rb', line 32

def load_release_file
  release_file = ReleaseFile.new
  @variables = @variables.merge release_file.variables
end