wire-framework 0.1.5.3 → 0.1.5.4

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: 57b6276466fdde480be64d03871a923b517ba4d5
4
- data.tar.gz: 085314f7a229be60dfdb3ad8c8445fa4a993da23
3
+ metadata.gz: 6b5de5f8f3c28bf3c2ef3b16bef0bafe113e1051
4
+ data.tar.gz: 5b544c2cedf9eecb08b7be6a03bfa7e74f1f89b4
5
5
  SHA512:
6
- metadata.gz: d3a6db1b191dd99b39d6dd32756caf687842d3602bec051575374f8d25ad5c0c67bcd67e2be21e28bfacc9620b461515fdadbc396c9fbb98801e754a3f02f948
7
- data.tar.gz: 3cc276cf1e8f171f1176d2d6423cd25738ca2d1506bc035bf1e9718f7a25479a36a04b09ce8bf492af4d2e69ad7e3836a736f1e428d3c8e0c12c16c91224b153
6
+ metadata.gz: 6bf313c114a0f4290cb63b6a71a8bba334eef09766d666fbe21245d2040b96f1bc3944b6764f8476fae9ac80f601b5b85f51961c5c4ab8dca8dd26d938fafdc9
7
+ data.tar.gz: 7855b60d903c318c3ed4eb537eb859e4b78da08e792cc59925ceab335570d0cc6719d82e800ab15ef239c43b47ecfc4af6430ff9333646e0d38d6c5ce88ae22b
data/lib/app/db.rb CHANGED
@@ -115,14 +115,13 @@ module DB
115
115
  def self.do_read(context)
116
116
  model = context.config['models'][context.resource]
117
117
  return 404 unless model
118
- id = context.id
118
+ id = context.uri[3]
119
119
  if id.eql?('new') or id.eql? 'upload'
120
120
  return '{}'
121
121
  end
122
122
  object = model[id]
123
- if object
124
- return [200, {}, object.to_json]
125
- end
123
+ return 404 unless object
124
+ [200, {}, object.to_json]
126
125
  end
127
126
 
128
127
  # Update a specific object in the DB table
@@ -131,7 +130,8 @@ module DB
131
130
  def self.do_update(context)
132
131
  model = context.config['models'][context.resource]
133
132
  return 404 unless model
134
- instance = model[context.id]
133
+ instance = model[context.uri[3]]
134
+ return 404 unless instance
135
135
  instance.update(context.json)
136
136
  end
137
137
 
@@ -141,7 +141,7 @@ module DB
141
141
  def self.do_delete(context)
142
142
  model = context.config['models'][context.resource]
143
143
  return 404 unless model
144
- instance = model[context.id]
144
+ instance = model[context.uri[3]]
145
145
  if instance
146
146
  if instance.delete
147
147
  200
@@ -27,34 +27,36 @@ module Render
27
27
  # @return [Response] a Rack Response triplet, or status code
28
28
  def self.render_template(actions, context, template, content)
29
29
  if template['file']
30
- hash = { actions: actions, context: context, content: content }
31
- template['sources'].each do |k, s|
32
- uri = "http://#{context.config['remote'].split('/')[0]}"
33
- go_ahead = true
34
- if s.is_a? Hash
35
- uri += "/#{s['uri']}"
36
- case s['key']
37
- when 'user'
38
- go_ahead = (context.user and !context.user.empty?)
39
- uri += "/#{context.user}"
40
- when 'resource'
41
- go_ahead = (context.resource and !context.resource.empty?)
42
- uri += "/#{context.resource}"
43
- else
44
- # do nothing
30
+ hash = {actions: actions, context: context, content: content}
31
+ if template['sources']
32
+ template['sources'].each do |k, s|
33
+ uri = "http://#{context.config['remote'].split('/')[0]}"
34
+ go_ahead = true
35
+ if s.is_a? Hash
36
+ uri += "/#{s['uri']}"
37
+ case s['key']
38
+ when 'user'
39
+ go_ahead = (context.user and !context.user.empty?)
40
+ uri += "/#{context.user}"
41
+ when 'resource'
42
+ go_ahead = (context.resource and !context.resource.empty?)
43
+ uri += "/#{context.resource}"
44
+ else
45
+ # do nothing
46
+ end
47
+ else
48
+ uri += "/#{s}"
45
49
  end
46
- else
47
- uri += "/#{s}"
48
- end
49
- temp = []
50
- if go_ahead
51
- temp = RL.request(:get, uri, { remote_user: context.user })
52
- end
53
- if temp[0] == 200
54
- begin
55
- hash[k.to_sym] = JSON.parse_clean(temp[2])
56
- rescue
57
- hash[k.to_sym] = temp[2]
50
+ temp = []
51
+ if go_ahead
52
+ temp = RL.request(:get, uri, {remote_user: context.user})
53
+ end
54
+ if temp[0] == 200
55
+ begin
56
+ hash[k.to_sym] = JSON.parse_clean(temp[2])
57
+ rescue
58
+ hash[k.to_sym] = temp[2]
59
+ end
58
60
  end
59
61
  end
60
62
  end
@@ -77,7 +79,7 @@ module Render
77
79
  if context.resource
78
80
  result = context.forward(specific)
79
81
  #TODO: fix lookup
80
- name = context.config['template']
82
+ name = context.config['template']
81
83
  template = $wire_templates[name]
82
84
  if template
83
85
  result[1]['Content-Type'] = 'text/html'
@@ -28,14 +28,11 @@ module Render
28
28
  def self.configure(conf)
29
29
  conf['resources'].each do |k, v|
30
30
  if v.is_a? Hash
31
- conf['resources'][k]['multiple'] = Tilt.new(v['multiple'], 1, { ugly: true })
32
- conf['resources'][k]['single'] = Tilt.new(v['single'], 1, { ugly: true })
31
+ conf['resources'][k]['multiple'] = Tilt.new(v['multiple'], 1, {ugly: true})
32
+ conf['resources'][k]['single'] = Tilt.new(v['single'], 1, {ugly: true})
33
33
  elsif v.is_a? String
34
34
  #TODO: fix needless duplication
35
- conf['resources'][k] = {
36
- 'multiple': Tilt.new(v, 1, { ugly: true }),
37
- 'single': Tilt.new(v, 1, { ugly: true })
38
- }
35
+ conf['resources'][k] = {'all' => Tilt.new(v, 1, {ugly: true})}
39
36
  end
40
37
  end
41
38
  conf
@@ -46,33 +43,37 @@ module Render
46
43
  # @param [Hash] context the context for this request
47
44
  # @return [Response] a Rack Response triplet, or status code
48
45
  def self.do_read_all(actions, context)
49
- resource = context.uri[2]
50
46
  body = ''
51
47
  mime = ''
52
- if context.app['use_forward']
48
+ resource = context.config['resources'][context.resource]
49
+ if resource['use_forward']
53
50
  response = context.forward(:readAll)
54
51
  return response if response[0] != 200
55
52
  mime = response[1][:content_type]
56
53
  body = response[2]
57
54
  end
58
- template = context.app['resources'][context.resource]['multiple']
55
+ if resource['all']
56
+ template = resource['all']
57
+ else
58
+ template = resource['multiple']
59
+ end
59
60
  if template
60
- hash = { actions: actions,
61
- resource: resource,
62
- mime: mime,
63
- response: body }
64
- if ccontext.app['resources'][context.resource]['extras']
65
- context.app['resources'][context.resource]['extras'].each do |k, v|
61
+ hash = {actions: actions,
62
+ resource: resource,
63
+ mime: mime,
64
+ response: body}
65
+ if resource['extras']
66
+ resource['extras'].each do |k, v|
66
67
  hash[k] = RL.request(:get,
67
- "http://#{context.app['remote']}/#{v}",
68
- { remote_user: context.user }
68
+ "http://#{context.config['remote']}/#{v}",
69
+ {remote_user: context.user}
69
70
  )[2]
70
71
  end
71
72
  end
72
73
  mime = 'text/html'
73
74
  body = template.render(self, hash)
74
75
  end
75
- [200, { 'Content-Type': mime }, body]
76
+ [200, {'Content-Type': mime}, body]
76
77
  end
77
78
 
78
79
  # Read a Partial and render it to HTML
@@ -82,29 +83,35 @@ module Render
82
83
  def self.do_read(actions, context)
83
84
  body = ''
84
85
  mime = ''
85
- if context.app['resources'][context.resource]['use_forward']
86
+ resource = context.config['resources'][context.resource]
87
+
88
+ if resource['use_forward']
86
89
  response = context.forward(:read)
87
90
  return response if response[0] != 200
88
91
  mime = response[1][:content_type]
89
92
  body = response[2]
90
93
  end
91
- template = context.app['resources'][context.resource]['single']
94
+ if resource['all']
95
+ template = resource['all']
96
+ else
97
+ template = resource['single']
98
+ end
92
99
  if template
93
- hash = { actions: actions,
94
- app: context.app,
95
- resource: context.resource,
96
- id: context.id,
97
- mime: mime,
98
- response: body }
99
- if context.app['resources'][context.resource]['extras']
100
- context.app['resources'][context.resource]['extras'].each do |k, v|
101
- hash[k] = RL.request(:get, "http://#{context.app[:remote_host]}/#{v}")[2]
100
+ hash = {actions: actions,
101
+ app: context.app,
102
+ resource: context.resource,
103
+ id: context.id,
104
+ mime: mime,
105
+ response: body}
106
+ if resource['extras']
107
+ resource['extras'].each do |k, v|
108
+ hash[k] = RL.request(:get, "http://#{context.config[:remote_host]}/#{v}")[2]
102
109
  end
103
110
  end
104
111
  mime = 'text/html'
105
112
  body = template.render(self, hash)
106
113
  end
107
- [200, { 'Content-Type': mime }, body]
114
+ [200, {'Content-Type': mime}, body]
108
115
  end
109
116
 
110
117
  # Proxy method used when routing
data/lib/wire.rb CHANGED
@@ -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.3'
36
+ VERSION = '0.1.5.4'
37
37
  end
38
38
 
39
39
  require_relative 'app'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wire-framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5.3
4
+ version: 0.1.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan T. Meyers