sinatra-backstage 0.2.3.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2fe6aa6d4025104f3cd16efd4c0c2a5ce3d61f68
4
- data.tar.gz: 0b8006c04ee79a60c4a32a46633570674e3cf229
3
+ metadata.gz: b83633623dbf543d85186a19488832fcd7ec46bc
4
+ data.tar.gz: 282236a8b6055e173583e34a4803df1855e51587
5
5
  SHA512:
6
- metadata.gz: a013460aa8eae9b4d8034a3abf539915348433c6d6eb3b31a28c5da4c2604ddd9e708cdaa4362ee7c2e47bc69f34c9e06c1dd2b0c71d1528029e8303097eb8b1
7
- data.tar.gz: 8db14557af72b3e2132583448ab21211171877b8c5169d1092545adaf07a6de19152ad486d52e346af37c974d17cf5d9b35cf157c16c1d5db1b9d31f9faa8319
6
+ metadata.gz: fa5d87d94f1c11f8af4aac892bfa9b0191fbe494cd1aa9a32b50019baff5a45ddb92d007f91d46e289b3cddf6016db2b5b0ee9732a6e45320088cce39e78f07f
7
+ data.tar.gz: 83cdbaea1046c545090f9f62b4c3ea70543266ba7f942c9928c02f1a14c82f2057d84dc763134bf1524ceb4d3b6bc7d871a0aec9356c3bc4f5c9e6e932fd0ba7
@@ -1,3 +1,7 @@
1
+ ## gorilla-patch
2
+ require 'gorilla-patch'
3
+
4
+ ## datamapper
1
5
  require 'dm-serializer'
2
6
 
3
7
  module Sinatra
@@ -5,6 +9,10 @@ module Sinatra
5
9
  module REST
6
10
  module Routing
7
11
 
12
+ using GorillaPatch::ArrayExt
13
+ using GorillaPatch::HashExt
14
+ using GorillaPatch::ModuleExt
15
+
8
16
  def self.included(controller)
9
17
  controller.extend self
10
18
  end
@@ -18,7 +26,7 @@ module Sinatra
18
26
  # puts "-- REST.Routing get namespace ( params = #{params})"
19
27
  format = params.delete('format') || 'html'
20
28
  # puts "-- REST.Routing get namespace after format ( params = #{params})"
21
- format = 'json' if request.accept.include?('text/json') || request.accept.include?('application/json')
29
+ format = 'json' if request.accept.include_any?('text/json', 'application/json')
22
30
  ## get json options
23
31
  json_method = params.delete('json_method')
24
32
  json_opts = {:methods => ([json_method] || [])}
@@ -31,7 +39,7 @@ module Sinatra
31
39
  ## return
32
40
  case format
33
41
  when 'html'
34
- halt eval "#{settings.render_engine} '#{demodulize(klass).downcase}/list'"
42
+ halt eval "#{settings.render_engine} '#{klass.demodulize.downcase}/list'"
35
43
  when 'json'
36
44
  halt @objects.to_json(json_opts)
37
45
  end
@@ -40,10 +48,10 @@ module Sinatra
40
48
 
41
49
  ### get add-form
42
50
  get "#{namespace}/new" do
43
- template = ["#{demodulize(klass).downcase}/new"]
51
+ template = ["#{klass.demodulize.downcase}/new"]
44
52
  if display_list
45
53
  @objects = rest_get_all(klass)
46
- template.unshift "#{demodulize(klass).downcase}/list"
54
+ template.unshift "#{klass.demodulize.downcase}/list"
47
55
  end
48
56
  eval "#{settings.render_engine} ['#{template.join('\',\'')}']"
49
57
  end
@@ -70,10 +78,10 @@ module Sinatra
70
78
 
71
79
  get "#{namespace}/:id" do |id|
72
80
  @object = klass.get!(id)
73
- template = ["#{demodulize(klass).downcase}/edit"]
81
+ template = ["#{klass.demodulize.downcase}/edit"]
74
82
  if display_list
75
83
  @objects = rest_get_all(klass)
76
- template.unshift "#{demodulize(klass).downcase}/list"
84
+ template.unshift "#{klass.demodulize.downcase}/list"
77
85
  end
78
86
  eval "#{settings.render_engine} ['#{template.join('\',\'')}']"
79
87
  end
@@ -93,7 +101,7 @@ module Sinatra
93
101
  end
94
102
 
95
103
  def rest_get_all(klass, params = {})
96
- klass.all params.inject({}){ | hash_sym, (key, val) | hash_sym[key.to_sym] = val; hash_sym }
104
+ klass.all params.to_sym_keys
97
105
  end
98
106
 
99
107
  end
@@ -1,3 +1,6 @@
1
+ ## gorilla-patch
2
+ require 'gorilla-patch'
3
+
1
4
  ## sinatra gems
2
5
  require 'sinatra'
3
6
 
@@ -8,25 +11,30 @@ module Sinatra
8
11
  module User
9
12
  module Helper
10
13
 
14
+ using GorillaPatch::ArrayExt
15
+
11
16
  def self.included(app)
12
17
  if app.ancestors.include? Sinatra::Base
13
- app.set(:user_routes) do |bool|
18
+ app.set(:user_access) do |roles|
14
19
  condition do
15
- (request.path =~ ( bool ?
16
- /^\/(login|signup)/ :
17
- /^(?!\/(login|signup))/
18
- )) != nil
20
+ settings.site_routes.each do |controller, hash|
21
+ if request.path =~ /^(#{hash['href']}$|#{hash['href']}\/.*$)/
22
+ # puts "-- Backstage::UserHelper :user_access ( controller = #{controller} )"
23
+ # puts "-- Backstage::UserHelper :user_access ( hash = #{hash} )"
24
+ return hash['access'].compare(roles)
25
+ end
26
+ end
19
27
  end
20
28
  end
21
29
 
22
30
  ## Hooks
23
- app.before :user_routes => true do
24
- # puts "-- Backstage::User login|signup authorized? = #{authorized?}"
31
+ app.before :user_access => [:anon] do
32
+ # puts "-- Backstage::User before authorized? = #{authorized?}"
25
33
  redirect '/' if authorized?
26
34
  # settings.site_routes[request.path]['active'] = true if settings.site_routes[request.path]
27
35
  end
28
36
 
29
- # app.after :user_routes => true do
37
+ # app.after :user_access => [:anon] do
30
38
  # settings.site_routes[request.path]['active'] = false if settings.site_routes[request.path]
31
39
  # end
32
40
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-backstage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Popov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-25 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2015-05-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gorilla-patch
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: Sinatra-Backstage simplifies the use of the basic routes and models for
14
28
  Sinatra and DataMapper. Currently it includes REST and User.
15
29
  email: alex.wayfer@gmail.com