Class: DNApi::App

Inherits:
Struct
  • Object
show all
Includes:
ComponentPossessor
Defined in:
lib/dnapi/app.rb

Instance Attribute Summary collapse

Attributes inherited from Struct

#parent

Instance Method Summary collapse

Methods included from ComponentPossessor

#add_component, #component, #component_group, #has_component?, included

Methods inherited from Struct

#==, #_many, _many, #_many_values, #_ones, _ones, #_ones_values, _umembers, belongs_to, from, #inspect, many, map, one, #to_hash, #umember_inspect, unserialized_member

Methods included from Test::Ext

#default_fauxture_name, #fixture, #generate, #generate_attributes, #pick

Constructor Details

#initialize(attributes = {}) ⇒ App

Returns a new instance of App.



12
13
14
15
16
17
18
19
20
21
# File 'lib/dnapi/app.rb', line 12

def initialize(attributes = {})
  gem_attributes = attributes.delete(:gems)
  ebuild_names   = attributes.delete(:ebuilds)

  super(attributes)

  gem_attributes.each {|attrs| build_gem(attrs) } if gem_attributes
  ebuild_names.each {|name| build_ebuild(:name => name) } if ebuild_names
  vhosts.each {|vhost| vhost.app = self } if vhosts
end

Instance Attribute Details

#branchObject

Returns the value of attribute branch

Returns:

  • (Object)

    the current value of branch



2
3
4
# File 'lib/dnapi/app.rb', line 2

def branch
  @branch
end

#bundledObject

Returns the value of attribute bundled

Returns:

  • (Object)

    the current value of bundled



2
3
4
# File 'lib/dnapi/app.rb', line 2

def bundled
  @bundled
end

#database_nameObject

Returns the value of attribute database_name

Returns:

  • (Object)

    the current value of database_name



2
3
4
# File 'lib/dnapi/app.rb', line 2

def database_name
  @database_name
end

#deploy_actionObject

Returns the value of attribute deploy_action

Returns:

  • (Object)

    the current value of deploy_action



2
3
4
# File 'lib/dnapi/app.rb', line 2

def deploy_action
  @deploy_action
end

#deploy_keyObject

Returns the value of attribute deploy_key

Returns:

  • (Object)

    the current value of deploy_key



2
3
4
# File 'lib/dnapi/app.rb', line 2

def deploy_key
  @deploy_key
end

#migration_commandObject

Returns the value of attribute migration_command

Returns:

  • (Object)

    the current value of migration_command



2
3
4
# File 'lib/dnapi/app.rb', line 2

def migration_command
  @migration_command
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



2
3
4
# File 'lib/dnapi/app.rb', line 2

def name
  @name
end

#newrelicObject

Returns the value of attribute newrelic

Returns:

  • (Object)

    the current value of newrelic



2
3
4
# File 'lib/dnapi/app.rb', line 2

def newrelic
  @newrelic
end

#repository_nameObject

Returns the value of attribute repository_name

Returns:

  • (Object)

    the current value of repository_name



2
3
4
# File 'lib/dnapi/app.rb', line 2

def repository_name
  @repository_name
end

#revisionObject

Returns the value of attribute revision

Returns:

  • (Object)

    the current value of revision



2
3
4
# File 'lib/dnapi/app.rb', line 2

def revision
  @revision
end

#run_deployObject

Returns the value of attribute run_deploy

Returns:

  • (Object)

    the current value of run_deploy



2
3
4
# File 'lib/dnapi/app.rb', line 2

def run_deploy
  @run_deploy
end

#run_migrationsObject

Returns the value of attribute run_migrations

Returns:

  • (Object)

    the current value of run_migrations



2
3
4
# File 'lib/dnapi/app.rb', line 2

def run_migrations
  @run_migrations
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



2
3
4
# File 'lib/dnapi/app.rb', line 2

def type
  @type
end

Instance Method Details

#build_ebuild(attributes = {}) ⇒ Object



123
124
125
126
127
128
# File 'lib/dnapi/app.rb', line 123

def build_ebuild(attributes = {})
  ebuild = EbuildDep.new(attributes)
  ebuild.app = self
  ebuilds << ebuild
  ebuild
end

#build_gem(attributes = {}) ⇒ Object



116
117
118
119
120
121
# File 'lib/dnapi/app.rb', line 116

def build_gem(attributes = {})
  gem = GemDep.new(attributes)
  gem.app = self
  gems << gem
  gem
end

#build_vhost(attributes = {}) ⇒ Object



23
24
25
26
27
28
# File 'lib/dnapi/app.rb', line 23

def build_vhost(attributes = {})
  vhost = VHost.new(attributes)
  vhost.app = self
  vhosts << vhost
  vhost
end

#bundled?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/dnapi/app.rb', line 58

def bundled?
  !! bundled
end

#domain_nameObject



30
31
32
# File 'lib/dnapi/app.rb', line 30

def domain_name
  vhosts.map {|vhost| vhost.domain_name }.compact.first
end

#domain_name=(value) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/dnapi/app.rb', line 34

def domain_name=(value)
  if vhosts.empty?
    build_vhost(:domain_name => value)
  else
    vhosts.first.domain_name = value
  end
end

#gems_hashObject



98
99
100
101
102
# File 'lib/dnapi/app.rb', line 98

def gems_hash
  gems.map do |gem|
    gem.to_legacy_hash
  end
end

#https?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/dnapi/app.rb', line 54

def https?
  vhosts.any? {|vhost| vhost.https? }
end

#jruby?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/dnapi/app.rb', line 108

def jruby?
  environment.ruby_component.is_a?(DNApi::Components::JRuby)
end

#newrelic?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/dnapi/app.rb', line 62

def newrelic?
  !! newrelic
end

#recipe_namesObject



112
113
114
# File 'lib/dnapi/app.rb', line 112

def recipe_names
  recipes.map {|r| r.name }
end

#recipesObject



104
105
106
# File 'lib/dnapi/app.rb', line 104

def recipes
  Recipe.defaults + environment.stack.recipes
end

#ssl_certObject



42
43
44
# File 'lib/dnapi/app.rb', line 42

def ssl_cert
  vhosts.map {|vhost| vhost.ssl_cert }.compact.first
end

#ssl_cert=(attributes = {}) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/dnapi/app.rb', line 46

def ssl_cert=(attributes = {})
  if vhosts.empty?
    build_vhost.build_ssl_cert(attributes || {})
  else
    vhosts.first.build_ssl_cert(attributes || {})
  end
end

#to_legacy_hashObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/dnapi/app.rb', line 66

def to_legacy_hash
  shared = %w( deploy_key repository_name type branch
    deploy_action migration_command revision
    run_deploy run_migrations )
  data = to_hash.select {|k,v| shared.include?(k.to_s)}
  Hash[*data.flatten].merge(
    :newrelic => newrelic?,
    :vhosts => vhost_legacy_array,
    :recipes => recipe_names,
    :http_bind_port => 80,
    :https_bind_port => 443,
    :auth => {:active => false},
    :services => [{
      :resource => :mongrel,
      :mongrel_base_port => 5000,
      :mongrel_mem_limit => 150,
      :mongrel_instance_count => 3
    },
    {
      :resource => :memcached,
      :base_port => 11211,
      :mem_limit => 128
    }]
  )
end

#vhost_legacy_arrayObject



92
93
94
95
96
# File 'lib/dnapi/app.rb', line 92

def vhost_legacy_array
  array = vhosts.map {|vhost| vhost.to_legacy_hash }
  vhosts.select {|vhost| vhost.https? }.inject(array) {|a,vhost| a.push(vhost.to_legacy_hash(true)) } if https? # legacy shit has 2 entries for an https vhost
  array
end