Class: RhoDevelopment::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/build/development/configuration.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.application_rootObject

Returns the value of attribute application_root.



10
11
12
# File 'lib/build/development/configuration.rb', line 10

def application_root
  @application_root
end

Class Method Details

.auto_refresh?Boolean

Returns:

  • (Boolean)


63
64
65
66
# File 'lib/build/development/configuration.rb', line 63

def self.auto_refresh?
  config = self.read_configuration
  config['refresh'].nil? ? false : config['refresh'] != false && config['refresh'] != 0
end

.auto_update_pid_requestObject



45
46
47
# File 'lib/build/development/configuration.rb', line 45

def self.auto_update_pid_request
  URI.join(self.webserver_uri, 'auto_update_pid')
end

.config_filenameObject



72
73
74
# File 'lib/build/development/configuration.rb', line 72

def self.config_filename
  File.join(self.application_root, 'dev-config.yml')
end

.development_directoryObject



29
30
31
# File 'lib/build/development/configuration.rb', line 29

def self.development_directory
  File.join(self.application_root, '.development')
end

.document_rootObject



163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/build/development/configuration.rb', line 163

def self.document_root
  config = self.read_configuration
  web_server_config = config['webserver']
  if web_server_config.nil? || web_server_config['documentRoot'].nil?
    document_root = Dir.mktmpdir
    self.document_root=document_root
  else
    document_root = web_server_config['documentRoot']
  end
  FileUtils.mkpath(document_root) unless File.exist?(document_root)
  document_root
end

.document_root=(aString) ⇒ Object



157
158
159
160
161
# File 'lib/build/development/configuration.rb', line 157

def self.document_root=(aString)
  config = self.read_configuration
  config['webserver'] = {'documentRoot' => aString}
  self.save_to_file(config)
end

.enabled_subscriber_platformsObject



132
133
134
# File 'lib/build/development/configuration.rb', line 132

def self.enabled_subscriber_platforms
  (self.enabled_subscribers.collect { |each| each.normalized_platform_name }).to_set
end

.enabled_subscribersSubscribers

Returns all subscribers in dev-config.yml

Returns:

  • (Subscribers)

    array of subscribers



105
106
107
# File 'lib/build/development/configuration.rb', line 105

def self.enabled_subscribers
  self.subscribers.select { | each | each.enabled?}
end

.enabled_subscribers_by_platform(platform_string) ⇒ Object



136
137
138
# File 'lib/build/development/configuration.rb', line 136

def self.enabled_subscribers_by_platform(platform_string)
  (self.enabled_subscribers.select { |each| (each.normalized_platform_name) == platform_string || (each.platform == platform_string) })
end

.full_bundle_nameObject



144
145
146
# File 'lib/build/development/configuration.rb', line 144

def self.full_bundle_name
  return 'upgrade_bundle.zip'
end

.handledNetworkExceptionsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/build/development/configuration.rb', line 13

def self.handledNetworkExceptions
  exceptions = [Errno::ECONNREFUSED, Errno::EHOSTDOWN, Errno::EHOSTUNREACH]
  if Net.const_defined?(:OpenTimeout)
    exceptions << Net::ReadTimeout
  end

  if Net.const_defined?(:OpenTimeout)
    exceptions << Net::OpenTimeout
  else
    exceptions << Timeout::Error
  end
  return exceptions
  #[Errno::ECONNREFUSED, Errno::EHOSTDOWN, Errno::EHOSTUNREACH, Net::ReadTimeout, Net.const_defined?(:OpenTimeout) ? Net::OpenTimeout : Timeout::Error]
end

.has_enabled_subscribers?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/build/development/configuration.rb', line 113

def self.has_enabled_subscribers?
  self.enabled_subscribers.empty? == false
end

.has_subscribers?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/build/development/configuration.rb', line 109

def self.has_subscribers?
  self.subscribers.empty? == false
end

.next_filename_for_downloadingObject



148
149
150
151
152
153
154
155
# File 'lib/build/development/configuration.rb', line 148

def self.next_filename_for_downloading
  config = self.read_configuration
  key = (config['last_bundle_key'].nil?) ? 0 : config['last_bundle_key']
  key = key + 1
  config['last_bundle_key'] = key
  self.save_to_file(config)
  return "bundle_#{key}.zip"
end

.own_ip_addressObject



33
34
35
# File 'lib/build/development/configuration.rb', line 33

def self.own_ip_address
  Network::available_addresses.first
end

.partial_bundle_nameObject



140
141
142
# File 'lib/build/development/configuration.rb', line 140

def self.partial_bundle_name
   return 'upgrade_bundle_partial.zip'
end

.read_configurationObject



76
77
78
79
80
81
82
# File 'lib/build/development/configuration.rb', line 76

def self.read_configuration
  config = {}
  if File.exist?(self.config_filename)
    config = YAML.load_file(self.config_filename)
  end
  config
end

.save_to_file(config) ⇒ Object



176
177
178
179
# File 'lib/build/development/configuration.rb', line 176

def self.save_to_file(config)
  yml = config.to_yaml
  File.open(self.config_filename, 'w') { |file| file.write yml }
end

.shut_down_webserver_requestObject



41
42
43
# File 'lib/build/development/configuration.rb', line 41

def self.shut_down_webserver_request
  URI.join(self.webserver_uri, 'shutdown')
end

.store_subscribers(anArray) ⇒ Object



117
118
119
120
121
# File 'lib/build/development/configuration.rb', line 117

def self.store_subscribers(anArray)
  config = self.read_configuration
  config['devices'] = anArray
  self.save_to_file(config)
end

.subscriber_by_ip(aString) ⇒ Object



123
124
125
126
127
128
129
130
# File 'lib/build/development/configuration.rb', line 123

def self.subscriber_by_ip(aString)
  self.subscribers.each { |each|
    if each.has_ip(aString)
      return each
    end
  }
  raise "Subscriber with IP #{aString} not found"
end

.subscribersSubscribers

Returns all subscribers in dev-config.yml

Returns:

  • (Subscribers)

    array of subscribers



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/build/development/configuration.rb', line 86

def self.subscribers
  subscribers = []
  config = self.read_configuration
  unless config['devices'].nil?
    config['devices'].each { |each|
      subscriber = RhoDevelopment::Subscriber.new
      subscriber.uri = each['uri']
      subscriber.platform = each['platform']
      subscriber.name = each['name']
      subscriber.application = each['application']
      (each['enabled'] == true || each['enabled'] == 1) ? subscriber.beEnabled : subscriber.beDisabled
      subscribers << subscriber
    }
  end
  subscribers
end

.webserver_alive_requestObject



37
38
39
# File 'lib/build/development/configuration.rb', line 37

def self.webserver_alive_request
  URI.join(self.webserver_uri, 'alive')
end

.webserver_ipObject



53
54
55
56
57
58
59
60
61
# File 'lib/build/development/configuration.rb', line 53

def self.webserver_ip
  config = self.read_configuration
  web_server_config = config['webserver']
  if web_server_config.nil? || web_server_config['ip'].nil?
    self.own_ip_address
  else
    web_server_config['ip']
  end
end

.webserver_portObject



68
69
70
# File 'lib/build/development/configuration.rb', line 68

def self.webserver_port
  3000
end

.webserver_uriObject



49
50
51
# File 'lib/build/development/configuration.rb', line 49

def self.webserver_uri
  URI("http://#{self.webserver_ip}:#{self.webserver_port}")
end