hq-web 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/hq/web/container.rb +119 -0
  2. metadata +142 -0
@@ -0,0 +1,119 @@
1
+ module HQ
2
+ module Web
3
+ class Container
4
+
5
+ def initialize
6
+ end
7
+
8
+ def init config_path
9
+ load_config config_path
10
+ init_apps
11
+ end
12
+
13
+ def load_config config_path
14
+
15
+ config_doc =
16
+ XML::Document.file config_path
17
+
18
+ config_elem =
19
+ config_doc.root
20
+
21
+ config_elem.name == "hq-web" \
22
+ or raise "Error"
23
+
24
+ @config_elem =
25
+ config_elem
26
+ end
27
+
28
+ def init_apps
29
+
30
+ @hq_apps =
31
+ @config_elem
32
+ .find("app")
33
+ .to_a
34
+ .map { |app_elem| init_app app_elem }
35
+
36
+ end
37
+
38
+ def init_app app_elem
39
+
40
+ return {
41
+
42
+ pattern:
43
+ Regexp.new("^#{app_elem.attributes["pattern"]}$"),
44
+
45
+ params:
46
+ app_elem.find("param").to_a \
47
+ .map {
48
+ |param_elem|
49
+ param_elem.attributes["name"]
50
+ },
51
+
52
+ provider:
53
+ get_provider(app_elem)
54
+
55
+ }
56
+
57
+ end
58
+
59
+ def handle env
60
+
61
+ $stdout.sync = true
62
+ $stderr.sync = true
63
+
64
+ # iterate all apps
65
+
66
+ @hq_apps.each do |app|
67
+
68
+ # find app which matches path
69
+
70
+ match =
71
+ app[:pattern].match env["PATH_INFO"]
72
+
73
+ next unless match
74
+
75
+ # create hash from params
76
+
77
+ params = Hash[
78
+ app[:params].each_with_index.map { |name, index|
79
+ [ name.to_sym, match[index + 1] ]
80
+ }
81
+ ]
82
+
83
+ # call that app's provider
84
+
85
+ return app[:provider].call env, params
86
+
87
+ end
88
+
89
+ # default error page
90
+
91
+ headers = {
92
+ "Content-Type" => "text/html",
93
+ }
94
+
95
+ body = [
96
+ "404 Not found",
97
+ ]
98
+
99
+ return [ 404, headers, body ]
100
+ end
101
+
102
+ def get_provider app_elem
103
+
104
+ require \
105
+ app_elem.attributes["require"]
106
+
107
+ provider_class =
108
+ eval app_elem.attributes["class"]
109
+
110
+ provider =
111
+ provider_class.get_provider app_elem
112
+
113
+ return provider
114
+
115
+ end
116
+
117
+ end
118
+ end
119
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hq-web
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - James Pharaoh
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capybara
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.2
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: cucumber
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.2.1
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.2.1
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 10.0.3
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 10.0.3
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 2.12.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 2.12.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec_junit_formatter
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: simplecov
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: HQ web framework
111
+ email:
112
+ - james@phsys.co.uk
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - lib/hq/web/container.rb
118
+ homepage: https://github.com/jamespharaoh/hq-web
119
+ licenses: []
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: 1.3.6
136
+ requirements: []
137
+ rubyforge_project: hq-web
138
+ rubygems_version: 1.8.23
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: HQ web
142
+ test_files: []