wurfl_device 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1,10 +1,12 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
- ruby_string="1.9.3"
3
+ ruby_string="1.9"
4
4
  gemset_name="wurfl_device"
5
5
 
6
6
  if rvm list strings | grep -q "${ruby_string}" ; then
7
7
 
8
+ ruby_string=$(rvm list strings | head -1)
9
+
8
10
  # Load or create the specified environment
9
11
  if [[ -d "${rvm_path:-$HOME/.rvm}/environments" && -s "${rvm_path:-$HOME/.rvm}/environments/${ruby_string}@${gemset_name}" ]] ; then
10
12
  \. "${rvm_path:-$HOME/.rvm}/environments/${ruby_string}@${gemset_name}"
@@ -12,11 +14,6 @@ if rvm list strings | grep -q "${ruby_string}" ; then
12
14
  rvm --create "${ruby_string}@${gemset_name}"
13
15
  fi
14
16
 
15
- if ! command -v bundle ; then
16
- echo "automatically installing bundler"
17
- gem install bundler
18
- fi
19
-
20
17
  else
21
18
 
22
19
  # Notify the user to install the desired interpreter before proceeding.
@@ -11,10 +11,10 @@ app_env = ENV['RACK_ENV'] || 'production'
11
11
  app_root = ::File.expand_path('../..', __FILE__)
12
12
 
13
13
  app_timeout = 60
14
- app_workers = WurflDevice::Settings::WEBSERVICE_WORKER
15
- app_listen_socket = File.join(WurflDevice::Settings::BASE_DIR, WurflDevice::Settings::WEBSERVICE_SOCKET)
16
- app_pid_file = File.join(WurflDevice::Settings::BASE_DIR, WurflDevice::Settings::WEBSERVICE_PID)
17
- app_log_file = File.join(WurflDevice::Settings::BASE_DIR, WurflDevice::Settings::WEBSERVICE_LOG)
14
+ app_workers = ENV['WURFLDEVICE_WORKER'].to_i || WurflDevice::Settings::WEBSERVICE_WORKER
15
+ app_listen_socket = ENV['WURFLDEVICE_SOCKET'] || File.join(WurflDevice::Settings::BASE_DIR, WurflDevice::Settings::WEBSERVICE_SOCKET)
16
+ app_pid_file = ENV['WURFLDEVICE_PIDFILE'] || File.join(WurflDevice::Settings::BASE_DIR, WurflDevice::Settings::WEBSERVICE_PID)
17
+ app_log_file = ENV['WURFLDEVICE_LOGFILE'] || File.join(WurflDevice::Settings::BASE_DIR, WurflDevice::Settings::WEBSERVICE_LOG)
18
18
 
19
19
  timeout app_timeout
20
20
  working_directory app_root
data/config.ru CHANGED
@@ -1,3 +1,5 @@
1
+ require 'bundler/setup'
2
+
1
3
  use Raindrops::Middleware, :stats => $stats, :path => '/_stats'
2
4
 
3
5
  require ::File.expand_path('../lib/wurfl_device/web_service', __FILE__)
@@ -28,7 +28,7 @@ module WurflDevice
28
28
  def entries
29
29
  entry_ids = Array.new
30
30
  Cache.storage.keys(build_cache_id('*')).each do |key|
31
- entry_ids << key.gsub(build_cache_id(''), '')
31
+ entry_ids << key.gsub(build_cache_id(''), '') rescue nil
32
32
  end
33
33
  entry_ids
34
34
  end
@@ -136,6 +136,7 @@ module WurflDevice
136
136
  UserAgentsManufacturers.set user_agent.manufacturer, user_agent, device_id
137
137
  end
138
138
  end
139
+ Status.set_value 'last_updated', Time.now
139
140
  end
140
141
 
141
142
  def update_actual_capabilities(user_agent, capabilities)
@@ -39,6 +39,15 @@ module WurflDevice
39
39
  end
40
40
 
41
41
  protected
42
+ def get_value(name)
43
+ return self[name] if self.key?(name)
44
+ if Settings::CAPABILITY_TO_GROUP.key?(name)
45
+ capability_group = Settings::CAPABILITY_TO_GROUP[name]
46
+ return self[capability_group][name] if self.key?(capability_group)
47
+ end
48
+ return nil
49
+ end
50
+
42
51
  def convert_key(key)
43
52
  key.is_a?(Symbol) ? key.to_s : key
44
53
  end
@@ -49,16 +58,18 @@ module WurflDevice
49
58
  # capability.shebang # => "/usr/lib/local/ruby"
50
59
  # capability.test_framework?(:rspec) # => options[:test_framework] == :rspec
51
60
  #
61
+ # need to rewrite this for deep hash entries
62
+ # use capability to group mapping
52
63
  def method_missing(method, *args, &block)
53
64
  method = method.to_s
54
65
  if method =~ /^(\w+)\?$/
55
66
  if args.empty?
56
- !!self[$1]
67
+ !!get_value($1)
57
68
  else
58
- self[$1] == args.first
69
+ get_value($1) == args.first
59
70
  end
60
71
  else
61
- self[method]
72
+ get_value(method)
62
73
  end
63
74
  end
64
75
  end
@@ -3,6 +3,7 @@ require 'thor'
3
3
  require 'benchmark'
4
4
  require 'wurfl_device'
5
5
  require 'yaml'
6
+ require 'json'
6
7
 
7
8
  module WurflDevice
8
9
  class CLI < Thor
@@ -48,10 +49,10 @@ module WurflDevice
48
49
  unless File.exists?(pid_file)
49
50
  WurflDevice.ui.info "starting webservice..."
50
51
  WurflDevice.ui.info "listening at #{opts.socket}"
52
+
53
+ unicorn_bin = %x[which unicorn].strip
51
54
  args = [
52
- File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']),
53
- '-S',
54
- 'unicorn',
55
+ unicorn_bin,
55
56
  '-E',
56
57
  'production',
57
58
  '-D',
@@ -67,18 +68,18 @@ module WurflDevice
67
68
  args << opts.port
68
69
  end
69
70
 
70
- system(args.join(' '))
71
+ ENV['WURFLDEVICE_WORKER'] = opts.worker.to_s
72
+ ENV['WURFLDEVICE_SOCKET'] = opts.socket.to_s
73
+
74
+ exec args.join(' ')
71
75
  end
72
76
  elsif action == 'stop'
73
77
  if File.exists?(pid_file)
74
78
  WurflDevice.ui.info "stopping webservice..."
75
- args = [
76
- 'kill',
77
- '-QUIT',
78
- "`cat #{pid_file}`",
79
- ]
80
-
81
- system(args.join(' '))
79
+ File.open(pid_file, 'r') do |f|
80
+ pid = f.gets.to_i
81
+ exec 'kill', '-QUIT', pid.to_s
82
+ end
82
83
  end
83
84
  FileUtils.rm_f(pid_file)
84
85
  elsif action == 'restart'
@@ -128,6 +129,12 @@ module WurflDevice
128
129
  end
129
130
  WurflDevice.ui.info "initializing wurfl device cache."
130
131
  WurflDevice::Cache.initialize_cache(xml_file)
132
+
133
+ if options.update?
134
+ WurflDevice.ui.info "rebuilding user agent cache."
135
+ WurflDevice::Cache.rebuild_user_agents
136
+ end
137
+
131
138
  status true
132
139
  end
133
140
 
@@ -153,8 +160,8 @@ module WurflDevice
153
160
  matched_count = matched_count + 1
154
161
  end
155
162
  WurflDevice.ui.info " " + commify(devices.length) + " device id's"
156
- WurflDevice.ui.info " " + commify(user_agents.length) + " exact user agents" + user_agents_message
157
- WurflDevice.ui.info " " + commify(matched_count) + " user agents matched found in cache"
163
+ WurflDevice.ui.info " " + commify(user_agents.length) + " user agents in cache" + user_agents_message
164
+ WurflDevice.ui.info " " + commify(matched_count) + " user agents matched"
158
165
 
159
166
  user_agent_manufacturers = Array.new
160
167
  WurflDevice::Cache::UserAgentsManufacturers.entries.each do |index|