wire-framework 0.1.5.4 → 0.1.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b5de5f8f3c28bf3c2ef3b16bef0bafe113e1051
4
- data.tar.gz: 5b544c2cedf9eecb08b7be6a03bfa7e74f1f89b4
3
+ metadata.gz: 1de513e0952b185809c295af2ad4626e6ab110c3
4
+ data.tar.gz: 852e93f18f3635ec0f9c2ab2d4b37e8ee8e71e93
5
5
  SHA512:
6
- metadata.gz: 6bf313c114a0f4290cb63b6a71a8bba334eef09766d666fbe21245d2040b96f1bc3944b6764f8476fae9ac80f601b5b85f51961c5c4ab8dca8dd26d938fafdc9
7
- data.tar.gz: 7855b60d903c318c3ed4eb537eb859e4b78da08e792cc59925ceab335570d0cc6719d82e800ab15ef239c43b47ecfc4af6430ff9333646e0d38d6c5ce88ae22b
6
+ metadata.gz: b74027d84c68f4b4c8183e7fa5a6d33e7b44c7083cf522efef74d424806d9c87c1e2acbbf714b928867f97dc710dccd0bd28299cf056275787568cac080fcfac
7
+ data.tar.gz: 538320181f48a3f45b2dbc5c45beee80e94603855419235ece206f9ee40e6c4cb71217e79dec50b0e954df5b08d9bf47b3769a77b1a43b3d75957875646bacf9
data/lib/app.rb CHANGED
@@ -38,7 +38,7 @@ module Wire
38
38
  # Read all of the configs in './configs/apps'
39
39
  # @return [void]
40
40
  def self.read_configs
41
- $wire_apps = Wire::Config.read_config_dir('config/apps', method(:configure))
41
+ Wire::Config.read_config_dir('config/apps', method(:configure))
42
42
  end
43
43
  end
44
44
  end
@@ -19,12 +19,12 @@ require 'lmdb'
19
19
  module Cache
20
20
  module Memory
21
21
 
22
- $cache = {}
22
+ @@cache = {}
23
23
 
24
24
  def self.update_cached(context)
25
25
  uri = context.uri.join('/')
26
26
  all = context.uri[0..2].join('/')
27
- env = $cache[context.config['remote']]
27
+ env = @@cache[context.config['remote']]
28
28
  db = env.database
29
29
  if context.id
30
30
  result = context.forward(:read)
@@ -55,7 +55,7 @@ module Cache
55
55
 
56
56
  def self.get_cached(context)
57
57
  uri = context.uri.join('/')
58
- env = $cache[context.config['remote']]
58
+ env = @@cache[context.config['remote']]
59
59
  db = env.database
60
60
  result = nil
61
61
  env.transaction do
@@ -66,7 +66,7 @@ module Cache
66
66
 
67
67
  def self.purge_cached(context)
68
68
  uri = context.uri.join('/')
69
- env = $cache[context.config['remote']]
69
+ env = @@cache[context.config['remote']]
70
70
  db = env.database
71
71
  result = 200
72
72
  env.transaction do
@@ -82,8 +82,8 @@ module Cache
82
82
  def self.invoke(actions, context)
83
83
 
84
84
  # Create Cache if not set up
85
- unless $cache[context.config['remote']]
86
- $cache[context.config['remote']] = LMDB.new("/tmp/cache/#{context.config['remote']}", mapsize: 2**30)
85
+ unless @@cache[context.config['remote']]
86
+ @@cache[context.config['remote']] = LMDB.new("/tmp/cache/#{context.config['remote']}", mapsize: 2**30)
87
87
  end
88
88
 
89
89
  case context.action
@@ -25,7 +25,7 @@ module DB
25
25
  # @param [Hash] conf the existing configuration
26
26
  # @return [Hash] post-processed configuration
27
27
  def self.configure(conf)
28
- conf['models'].each do |m,k|
28
+ conf['models'].each do |m, k|
29
29
  conf['models'][m] = Object.const_get(k)
30
30
  end
31
31
  conf
@@ -79,7 +79,6 @@ module DB
79
79
  else
80
80
  begin
81
81
  instance = model.create(context.json)
82
- instance.save
83
82
  if instance.modified?
84
83
  200
85
84
  else
@@ -25,8 +25,7 @@ module Static
25
25
  # @return [Response] a listing, or status code
26
26
  def self.do_read_all(context)
27
27
  path = context.config['path']
28
- if path
29
- return 404 unless File.exists?(path)
28
+ if path and File.exists?(path)
30
29
  if File.directory? path
31
30
  Dir.entries(path).sort.to_s
32
31
  else
@@ -23,7 +23,7 @@ module Login
23
23
  # @param [Hash] context the context for this request
24
24
  # @return [Response] a redirect message returning to the previous page
25
25
  def self.invoke(actions, context)
26
- [307, { 'Location' => context.referer.join('/') }, ['Login Redirect']]
26
+ [307, {'Location' => context.referer.join('/')}, ['Login Redirect']]
27
27
  end
28
28
 
29
29
  end
@@ -27,14 +27,13 @@ module Render
27
27
  def self.do_read(actions, context, specific)
28
28
  response = context.forward(specific)
29
29
  mime = response[1]['content-type']
30
- #TODO: Fix lookup
31
- renderer = $wire_renderers[mime]
30
+ renderer = context.closet.renderers[mime]
32
31
  if renderer
33
32
  template = renderer['partial']
34
- template.render(self, { actions: actions,
35
- context: context,
36
- mime: mime,
37
- response: response[2] })
33
+ template.render(self, {actions: actions,
34
+ context: context,
35
+ mime: mime,
36
+ response: response[2]})
38
37
  else
39
38
  response
40
39
  end
@@ -35,13 +35,13 @@ module Render
35
35
  return [404, {}, 'EDITOR: Document type not set for new document']
36
36
  end
37
37
  #TODO: Fix lookup
38
- template = $wire_editors[mime]
38
+ template = context.closet.editors[mime]
39
39
  if template
40
- template.render(self, { actions: actions,
41
- resource: context.resource,
42
- id: context.id,
43
- mime: mime,
44
- response: body })
40
+ template.render(self, {actions: actions,
41
+ resource: context.resource,
42
+ id: context.id,
43
+ mime: mime,
44
+ response: body})
45
45
  else
46
46
  body
47
47
  end
@@ -24,7 +24,7 @@ module Render
24
24
  # @return [Hash] post-processed configuration
25
25
  def self.configure(conf)
26
26
  conf['errors'].each do |k, v|
27
- conf['errors'][k] = Tilt.new(v, 1, { ugly: true })
27
+ conf['errors'][k] = Tilt.new(v, 1, {ugly: true})
28
28
  end
29
29
  conf
30
30
  end
@@ -34,9 +34,9 @@ module Render
34
34
  if errors
35
35
  template = errors[result[0]]
36
36
  if template
37
- result[2] = template.render(self, { actions: actions,
38
- context: context,
39
- result: result })
37
+ result[2] = template.render(self, {actions: actions,
38
+ context: context,
39
+ result: result})
40
40
  end
41
41
  end
42
42
  result
@@ -25,8 +25,8 @@ module Render
25
25
  # @return [Response] a Rack Response triplet, or status code
26
26
  def self.do_update(actions, context)
27
27
  ## Default to not found
28
- message = ''
29
- status = 404
28
+ message = ''
29
+ status = 404
30
30
  if context.resource
31
31
  body = context.body
32
32
  if body
@@ -38,19 +38,19 @@ module Render
38
38
  ## Assume unsupported mime type
39
39
  status = 415
40
40
  message = 'INSTANT: Unsupported MIME Type'
41
- renderer = $wire_renderers["#{context.resource}/#{context.id}"]
41
+ renderer = context.closet.renderers["#{context.resource}/#{context.id}"]
42
42
  if renderer
43
- template = $wire_templates[renderer]
44
- result = template.render(self, { actions: actions,
45
- context: context,
46
- mime: "#{context.resource}/#{context.id}",
47
- response: body, })
48
- #TODO: Fix template lookup
49
- template = context.app[:template]
43
+ template = context.closet.templates[renderer]
44
+ result = template.render(self, {actions: actions,
45
+ context: context,
46
+ mime: "#{context.resource}/#{context.id}",
47
+ response: body, })
48
+ name = context.config['template']
49
+ template = context.closet.templates[name]
50
50
  if template
51
- message = template[:path].render(self, { actions: actions,
51
+ message = template['file'].render(self, {actions: actions,
52
52
  context: context,
53
- content: result })
53
+ content: result})
54
54
  else
55
55
  message = result
56
56
  end
@@ -62,7 +62,7 @@ module Render
62
62
  end
63
63
  message = template['file'].render(self, hash)
64
64
  if template['use_layout']
65
- message = render_template(actions, context, $wire_templates['layout'], message)
65
+ message = render_template(actions, context, context.closet.templates['layout'], message)
66
66
  end
67
67
  else
68
68
  message = 'Invalid Template'
@@ -78,9 +78,8 @@ module Render
78
78
  def self.do_read(actions, context, specific)
79
79
  if context.resource
80
80
  result = context.forward(specific)
81
- #TODO: fix lookup
82
81
  name = context.config['template']
83
- template = $wire_templates[name]
82
+ template = context.closet.templates[name]
84
83
  if template
85
84
  result[1]['Content-Type'] = 'text/html'
86
85
  result[2] = render_template(actions, context, template, result[2])
@@ -31,7 +31,6 @@ module Render
31
31
  conf['resources'][k]['multiple'] = Tilt.new(v['multiple'], 1, {ugly: true})
32
32
  conf['resources'][k]['single'] = Tilt.new(v['single'], 1, {ugly: true})
33
33
  elsif v.is_a? String
34
- #TODO: fix needless duplication
35
34
  conf['resources'][k] = {'all' => Tilt.new(v, 1, {ugly: true})}
36
35
  end
37
36
  end
@@ -64,16 +63,22 @@ module Render
64
63
  response: body}
65
64
  if resource['extras']
66
65
  resource['extras'].each do |k, v|
67
- hash[k] = RL.request(:get,
68
- "http://#{context.config['remote']}/#{v}",
69
- {remote_user: context.user}
66
+ temp = RL.request(:get,
67
+ "http://#{context.config['remote'].split('/')[0]}/#{v}",
68
+ {remote_user: context.user}
70
69
  )[2]
70
+ begin
71
+ hash[k.to_sym] = JSON.parse_clean(temp)
72
+ rescue
73
+ hash[k.to_sym] = temp
74
+ end
75
+
71
76
  end
72
77
  end
73
78
  mime = 'text/html'
74
79
  body = template.render(self, hash)
75
80
  end
76
- [200, {'Content-Type': mime}, body]
81
+ [200, {'Content-Type' => mime}, body]
77
82
  end
78
83
 
79
84
  # Read a Partial and render it to HTML
@@ -105,13 +110,18 @@ module Render
105
110
  response: body}
106
111
  if resource['extras']
107
112
  resource['extras'].each do |k, v|
108
- hash[k] = RL.request(:get, "http://#{context.config[:remote_host]}/#{v}")[2]
113
+ temp = RL.request(:get, "http://#{context.config['remote'].split('/')[0]}/#{v}")[2]
114
+ begin
115
+ hash[k.to_sym] = JSON.parse_clean(temp)
116
+ rescue
117
+ hash[k.to_sym] = temp
118
+ end
109
119
  end
110
120
  end
111
121
  mime = 'text/html'
112
122
  body = template.render(self, hash)
113
123
  end
114
- [200, {'Content-Type': mime}, body]
124
+ [200, {'Content-Type' => mime}, body]
115
125
  end
116
126
 
117
127
  # Proxy method used when routing
@@ -26,7 +26,7 @@ module Repo
26
26
  # @param [Hash] conf the raw configuration
27
27
  # @return [Hash] post-processed configuration
28
28
  def self.configure(conf)
29
- conf['listing'] = Tilt.new(conf['listing'], 1, { ugly: true })
29
+ conf['listing'] = Tilt.new(conf['listing'], 1, {ugly: true})
30
30
  conf
31
31
  end
32
32
 
@@ -51,10 +51,10 @@ module Repo
51
51
  # @param [Hash] context the context for this request
52
52
  # @return [Response] the listing, or status code
53
53
  def do_read_all(context)
54
- mime = 'text/html'
55
- list = do_read_listing(context.config['web'],
56
- context.config['repos'],
57
- context.resource)
54
+ mime = 'text/html'
55
+ list = do_read_listing(context.config['web'],
56
+ context.config['repos'],
57
+ context.resource)
58
58
  if list == 404
59
59
  return 404
60
60
  end
@@ -64,9 +64,9 @@ module Repo
64
64
  resource: context.resource,
65
65
  id: '',
66
66
  referrer: context.referer)
67
- headers = { 'Content-Type': mime,
68
- 'Cache-Control': 'public',
69
- 'Expires': "#{(Time.now + 1000).utc}" }
67
+ headers = {'Content-Type' => mime,
68
+ 'Cache-Control' => 'public',
69
+ 'Expires' => "#{(Time.now + 1000).utc}"}
70
70
  [200, headers, [list]]
71
71
  end
72
72
 
@@ -101,9 +101,9 @@ module Repo
101
101
  end
102
102
  mime = do_read_mime(rev, web, repos, path, id)
103
103
  end
104
- headers = { 'Content-Type': mime,
105
- 'Cache-Control': 'public',
106
- 'Expires': "#{(Time.now + 1000).utc}" }
104
+ headers = {'Content-Type' => mime,
105
+ 'Cache-Control' => 'public',
106
+ 'Expires' => "#{(Time.now + 1000).utc}"}
107
107
  [200, headers, [body]]
108
108
  end
109
109
 
@@ -18,30 +18,25 @@ require 'nori'
18
18
  require 'fileutils'
19
19
  require_relative '../repo'
20
20
 
21
- # Force Nori to convert tag names to Symbols
22
- $nori = Nori.new :convert_tags_to => lambda { |tag| tag.snakecase.to_sym }
23
-
24
21
  module Repo
25
22
  # Repo::SVN is a connector for svnserve
26
23
  # @author Bryan T. Meyers
27
24
  module SVN
28
25
  extend Repo
29
26
 
27
+ # Force Nori to convert tag names to Symbols
28
+ @@nori = Nori.new :convert_tags_to => lambda { |tag| tag.snakecase.to_sym }
29
+
30
30
  # Make a new SVN repo
31
31
  # @param [String] path the path to the repositories
32
32
  # @param [String] repo the new repo name
33
33
  # @return [Integer] status code
34
34
  def self.do_create_file(path, repo)
35
- result = 200
36
35
  `svnadmin create #{path}/#{repo}`
37
- if $?.exitstatus != 0
38
- return 500
39
- end
40
-
41
36
  if $?.exitstatus != 0
42
37
  500
43
38
  else
44
- result
39
+ 200
45
40
  end
46
41
  end
47
42
 
@@ -94,7 +89,7 @@ module Repo
94
89
  unless $?.exitstatus == 0
95
90
  return 404
96
91
  end
97
- list = $nori.parse(list)
92
+ list = @@nori.parse(list)
98
93
  list[:lists][:list][:entry]
99
94
  end
100
95
 
@@ -119,7 +114,7 @@ module Repo
119
114
  unless $?.exitstatus == 0
120
115
  return 404
121
116
  end
122
- info = $nori.parse(info)
117
+ info = @@nori.parse(info)
123
118
  info[:info][:entry]
124
119
  end
125
120
 
@@ -140,11 +135,10 @@ module Repo
140
135
  else
141
136
  mime = `svn propget #{options} -r #{rev} --xml svn:mime-type 'svn://localhost/#{repo}/#{web}/#{id}'`
142
137
  end
143
-
144
138
  unless $?.success?
145
139
  return 500
146
140
  end
147
- mime = $nori.parse(mime)
141
+ mime = @@nori.parse(mime)
148
142
  if mime[:properties].nil?
149
143
  'application/octet-stream'
150
144
  else
@@ -165,9 +159,9 @@ module Repo
165
159
  def self.do_update_file(web, path, repo, id, content, message, mime, user)
166
160
  options = "--username #{$environment[:repos_user]} --password #{$environment[:repos_password]}"
167
161
  status = 500
168
- id = id.split('/')
162
+ id = id.split('/')
169
163
  id.pop
170
- id = id.join('/')
164
+ id = id.join('/')
171
165
  if web.nil?
172
166
  repo_path = "/tmp/svn/#{repo}/#{id}"
173
167
  else
@@ -180,9 +174,9 @@ module Repo
180
174
  `svn checkout #{options} 'svn://localhost/#{repo}' '/tmp/svn/#{repo}'`
181
175
  id = CGI.unescape(id)
182
176
  if $?.exitstatus == 0
183
- id = id.split('/')
177
+ id = id.split('/')
184
178
  id.pop
185
- id = id.join('/')
179
+ id = id.join('/')
186
180
  if web.nil?
187
181
  file_path = "/tmp/svn/#{repo}/#{id}"
188
182
  else
@@ -28,13 +28,15 @@ module Wire
28
28
  class Closet
29
29
  include Wire::Auth
30
30
 
31
+ attr_reader :apps, :editors, :renderers, :templates
32
+
31
33
  # Create an empty Closet
32
34
  # @return [Wire::Closet] the new closet
33
35
  def initialize
34
- $wire_apps = {}
35
- $wire_editors = {}
36
- $wire_renderers = {}
37
- $wire_templates = {}
36
+ @apps = {}
37
+ @editors = {}
38
+ @renderers = {}
39
+ @templates = {}
38
40
  end
39
41
 
40
42
  # Route a Request to the correct Wire::App
@@ -54,7 +56,7 @@ module Wire
54
56
  # @return [Response] a Rack Response triplet, or status code
55
57
  def call(env)
56
58
  begin
57
- context = Wire::Context.new(env)
59
+ context = Wire::Context.new(self, env)
58
60
  response = route(context)
59
61
  rescue Exception => e
60
62
  $stderr.puts e.message
@@ -62,10 +64,8 @@ module Wire
62
64
  response = [500, {}, e.message]
63
65
  end
64
66
  if response.is_a? Array
65
- if response[2]
66
- unless response[2].is_a? Array
67
- response[2] = [response[2]]
68
- end
67
+ if response[2] and not response[2].is_a? Array
68
+ response[2] = [response[2]]
69
69
  end
70
70
  else
71
71
  if response.is_a? Integer
@@ -86,8 +86,8 @@ module Wire
86
86
  $stderr.puts 'Starting Up Wire...'
87
87
  $stderr.puts 'Starting Apps...'
88
88
  end
89
- Wire::App.read_configs
90
- Wire::Renderer.read_configs
89
+ @apps = Wire::App.read_configs
90
+ @editors, @renderers, @templates = Wire::Renderer.read_configs
91
91
  if ENV['RACK_ENV'].eql? 'development'
92
92
  closet.info
93
93
  end
@@ -98,7 +98,7 @@ module Wire
98
98
  # @return [void]
99
99
  def info
100
100
  $stderr.puts "Apps:\n"
101
- $wire_apps.each do |app, config|
101
+ @apps.each do |app, config|
102
102
  $stderr.puts "\u{2502}"
103
103
  $stderr.puts "\u{251c} Name: #{app}"
104
104
  if config['auth_handler']
@@ -49,9 +49,9 @@ module Wire
49
49
  #@!attribute [r] verb
50
50
  # @return [Symbol] the HTTP verb
51
51
 
52
- attr_reader :action, :app, :body, :config, :id, :json, :query,
53
- :query_string, :rack_env, :referer, :resource,
54
- :uri, :user, :verb
52
+ attr_reader :action, :app, :body, :closet, :config, :id,
53
+ :json, :query, :query_string, :rack_env,
54
+ :referer, :resource, :uri, :user, :verb
55
55
  attr_writer :referer
56
56
 
57
57
  # Maps HTTP verbs to actions
@@ -85,9 +85,11 @@ module Wire
85
85
  end
86
86
 
87
87
  # Builds a new Context
88
+ # @param [Closet] closet the Wire::Closet
88
89
  # @param [Hash] env the Rack environment
89
90
  # @return [Context] a new Context
90
- def initialize(env)
91
+ def initialize(closet, env)
92
+ @closet = closet
91
93
  @rack_env = update_session(env)
92
94
  @user = env['rack.session']['user']
93
95
  @verb = HTTP_VERBS[env['REQUEST_METHOD'].to_sym]
@@ -98,7 +100,7 @@ module Wire
98
100
  else
99
101
  @referer = ['http:', '', env['HTTP_HOST']].concat(@uri[1...@uri.length])
100
102
  end
101
- @config = $wire_apps[@uri[1]]
103
+ @config = @closet.apps[@uri[1]]
102
104
  if @config
103
105
  @app = @uri[1]
104
106
  @resource = @uri[2]
@@ -134,8 +136,8 @@ module Wire
134
136
  # @param [Symbol] method the action to use when forwarding
135
137
  # @return [Response] a Rack Response triplet, or status code
136
138
  def forward(method)
137
- headers = { referer: @referer.join('/'),
138
- remote_user: @user }
139
+ headers = {referer: @referer.join('/'),
140
+ remote_user: @user}
139
141
  verb = CONVERT[method]
140
142
  uri = "http://#{@config['remote']}/#{@resource}"
141
143
  if [:update, :read, :delete].include?(method)
@@ -26,7 +26,7 @@ module Wire
26
26
  # @param [Hash] conf the raw configuration
27
27
  # @return [Hash] post-processed configuration
28
28
  def self.configure_partial(conf)
29
- conf['partial'] = Tilt.new(conf['partial'], 1, { ugly: true })
29
+ conf['partial'] = Tilt.new(conf['partial'], 1, {ugly: true})
30
30
  conf
31
31
  end
32
32
 
@@ -34,16 +34,17 @@ module Wire
34
34
  # @param [Hash] conf the raw configuration
35
35
  # @return [Hash] post-processed configuration
36
36
  def self.configure_template(conf)
37
- conf['file'] = Tilt.new(conf['file'], 1, { ugly: true })
37
+ conf['file'] = Tilt.new(conf['file'], 1, {ugly: true})
38
38
  conf
39
39
  end
40
40
 
41
41
  # Read all of the configs in './configs/apps'
42
42
  # @return [void]
43
43
  def self.read_configs
44
- $wire_editors = Wire::Config.read_config_dir('config/editors', method(:configure_template))
45
- $wire_renderers = Wire::Config.read_config_dir('config/renderers', method(:configure_partial))
46
- $wire_templates = Wire::Config.read_config_dir('config/templates', method(:configure_template))
44
+ editors = Wire::Config.read_config_dir('config/editors', method(:configure_template))
45
+ renderers = Wire::Config.read_config_dir('config/renderers', method(:configure_partial))
46
+ templates = Wire::Config.read_config_dir('config/templates', method(:configure_template))
47
+ [editors, renderers, templates]
47
48
  end
48
49
  end
49
50
  end
@@ -33,7 +33,7 @@ end
33
33
  # @author Bryan T. Meyers
34
34
  module Wire
35
35
  # Current version of the Wire Gem
36
- VERSION = '0.1.5.4'
36
+ VERSION = '0.1.5.5'
37
37
  end
38
38
 
39
39
  require_relative 'app'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wire-framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5.4
4
+ version: 0.1.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan T. Meyers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-17 00:00:00.000000000 Z
11
+ date: 2017-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print