lux-fw 0.5.36 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/bin/README.md +26 -13
  4. data/bin/cli/benchmark.rb +18 -0
  5. data/bin/cli/cerb.rb +90 -0
  6. data/bin/cli/config.rb +4 -11
  7. data/bin/cli/console.rb +72 -30
  8. data/bin/cli/eval.rb +5 -27
  9. data/bin/cli/generate.rb +9 -11
  10. data/bin/cli/get.rb +14 -6
  11. data/bin/cli/memory.rb +12 -0
  12. data/bin/cli/new.rb +2 -0
  13. data/bin/cli/secrets.rb +3 -31
  14. data/bin/cli/server.rb +28 -9
  15. data/bin/cli/stats.rb +26 -20
  16. data/bin/cli/template.rb +10 -0
  17. data/bin/generate_doc +168 -0
  18. data/bin/lux +73 -10
  19. data/lib/README.md +18 -8
  20. data/lib/common/crypt.rb +60 -9
  21. data/lib/common/string_base.rb +54 -15
  22. data/lib/common/struct_opts.rb +30 -0
  23. data/lib/common/time_difference.rb +75 -0
  24. data/lib/loader.rb +41 -0
  25. data/lib/lux/application/README.md +67 -105
  26. data/lib/lux/application/application.rb +87 -329
  27. data/lib/lux/application/lib/magic_routes.rb +22 -0
  28. data/lib/lux/application/lib/nav.rb +218 -99
  29. data/lib/lux/application/lib/render.rb +47 -67
  30. data/lib/lux/application/lib/routes.rb +242 -0
  31. data/lib/lux/application/lib/shared.rb +47 -0
  32. data/lib/lux/application/lux_adapter.rb +6 -0
  33. data/lib/lux/application/lux_config.rb +26 -0
  34. data/lib/lux/cache/Find Results +24 -0
  35. data/lib/lux/cache/README.md +28 -35
  36. data/lib/lux/cache/cache.rb +78 -26
  37. data/lib/lux/cache/lib/memcached_server.rb +36 -0
  38. data/lib/lux/cache/lib/memory_server.rb +44 -0
  39. data/lib/lux/cache/lib/null_server.rb +33 -0
  40. data/lib/lux/cache/lib/sqlite_server.rb +62 -0
  41. data/lib/lux/cache/lux_adapter.rb +19 -0
  42. data/lib/lux/config/config.rb +93 -144
  43. data/lib/lux/config/lux_adapter.rb +27 -0
  44. data/lib/lux/controller/README.md +67 -12
  45. data/lib/lux/controller/controller.rb +237 -187
  46. data/lib/lux/current/README.md +29 -10
  47. data/lib/lux/current/current.rb +166 -77
  48. data/lib/lux/current/lib/current.rb +6 -0
  49. data/lib/lux/current/lib/encrypt_params.rb +38 -36
  50. data/lib/lux/current/lib/session.rb +86 -65
  51. data/lib/lux/current/lux_adapter.rb +5 -0
  52. data/lib/lux/environment/README.md +24 -0
  53. data/lib/lux/environment/environment.rb +91 -0
  54. data/lib/lux/environment/lux_adapter.rb +13 -0
  55. data/lib/lux/error/README.md +18 -19
  56. data/lib/lux/error/error.rb +207 -152
  57. data/lib/lux/error/lux_adapter.rb +9 -0
  58. data/lib/lux/logger/README.md +45 -0
  59. data/lib/lux/logger/lux_adapter.rb +27 -0
  60. data/lib/lux/lux.rb +72 -129
  61. data/lib/lux/mailer/README.md +12 -5
  62. data/lib/lux/mailer/lux_config.rb +4 -0
  63. data/lib/lux/mailer/mailer.rb +81 -59
  64. data/lib/lux/plugin/README.md +19 -0
  65. data/lib/lux/plugin/lux_adapter.rb +8 -0
  66. data/lib/lux/plugin/plugin.rb +65 -0
  67. data/lib/lux/render/README.md +100 -0
  68. data/lib/lux/render/render.rb +12 -0
  69. data/lib/lux/response/README.md +57 -1
  70. data/lib/lux/response/lib/file.rb +87 -65
  71. data/lib/lux/response/lib/flash.rb +49 -34
  72. data/lib/lux/response/lib/header.rb +34 -33
  73. data/lib/lux/response/response.rb +252 -164
  74. data/lib/lux/template/helper.rb +130 -0
  75. data/lib/lux/template/inline_render_proxy.rb +31 -0
  76. data/lib/lux/template/lux_adapter.rb +5 -0
  77. data/lib/lux/template/template.rb +127 -0
  78. data/lib/lux-fw.rb +15 -33
  79. data/lib/overload/array.rb +33 -7
  80. data/lib/overload/blank.rb +8 -3
  81. data/lib/overload/boolean.rb +46 -0
  82. data/lib/overload/class.rb +28 -0
  83. data/lib/overload/dir.rb +117 -7
  84. data/lib/overload/file.rb +40 -5
  85. data/lib/overload/float.rb +38 -3
  86. data/lib/overload/hash.rb +81 -91
  87. data/lib/overload/integer.rb +15 -0
  88. data/lib/overload/json.rb +26 -0
  89. data/lib/overload/nil.rb +4 -8
  90. data/lib/overload/object.rb +91 -24
  91. data/lib/overload/pathname.rb +11 -0
  92. data/lib/overload/raise_variants.rb +26 -36
  93. data/lib/overload/string.rb +100 -27
  94. data/lib/overload/thread_simple.rb +100 -0
  95. data/lib/overload/time.rb +60 -38
  96. data/tasks/loader.rb +20 -7
  97. metadata +170 -169
  98. data/bin/.DS_Store +0 -0
  99. data/bin/build_gem +0 -77
  100. data/bin/cli/dbconsole.rb +0 -8
  101. data/bin/cli/routes.rb +0 -90
  102. data/lib/.DS_Store +0 -0
  103. data/lib/common/.DS_Store +0 -0
  104. data/lib/common/class_attributes.rb +0 -51
  105. data/lib/common/class_callbacks.rb +0 -47
  106. data/lib/common/free_struct.rb +0 -42
  107. data/lib/common/hash_with_indifferent_access.rb +0 -74
  108. data/lib/common/html_tag_builder.rb +0 -91
  109. data/lib/common/method_attr.rb +0 -69
  110. data/lib/common/url.rb +0 -191
  111. data/lib/lux/.DS_Store +0 -0
  112. data/lib/lux/README.md +0 -10
  113. data/lib/lux/cache/.DS_Store +0 -0
  114. data/lib/lux/cache/lib/memory.rb +0 -36
  115. data/lib/lux/cache/lib/null.rb +0 -21
  116. data/lib/lux/config/README.md +0 -63
  117. data/lib/lux/config/lib/plugin.rb +0 -65
  118. data/lib/lux/config/lib/secrets.rb +0 -48
  119. data/lib/lux/current/.DS_Store +0 -0
  120. data/lib/lux/delayed_job/.DS_Store +0 -0
  121. data/lib/lux/delayed_job/README.md +0 -3
  122. data/lib/lux/delayed_job/delayed_job.rb +0 -51
  123. data/lib/lux/delayed_job/lib/memory.rb +0 -16
  124. data/lib/lux/delayed_job/lib/nsq.rb +0 -3
  125. data/lib/lux/delayed_job/lib/postgre.rb +0 -6
  126. data/lib/lux/delayed_job/lib/redis.rb +0 -19
  127. data/lib/lux/event_bus/README.md +0 -36
  128. data/lib/lux/event_bus/event_bus.rb +0 -27
  129. data/lib/lux/view/README.md +0 -85
  130. data/lib/lux/view/cell.rb +0 -102
  131. data/lib/lux/view/helper.rb +0 -120
  132. data/lib/lux/view/lib/cell_helpers.rb +0 -29
  133. data/lib/lux/view/view.rb +0 -95
  134. data/lib/overload/it.rb +0 -29
  135. data/plugins/api/README.md +0 -49
  136. data/plugins/api/api.rb +0 -153
  137. data/plugins/api/lib/attr.rb +0 -31
  138. data/plugins/api/lib/dsl.rb +0 -52
  139. data/plugins/api/lib/error.rb +0 -3
  140. data/plugins/api/lib/model_api.rb +0 -203
  141. data/plugins/api/lib/response.rb +0 -85
  142. data/plugins/db/.DS_Store +0 -0
  143. data/plugins/db/README.md +0 -29
  144. data/plugins/db/auto_migrate/auto_migrate.rb +0 -268
  145. data/plugins/db/auto_migrate/db.rake +0 -15
  146. data/plugins/db/helpers/array_search.rb +0 -27
  147. data/plugins/db/helpers/before_save_filters.rb +0 -32
  148. data/plugins/db/helpers/composite_primary_keys.rb +0 -36
  149. data/plugins/db/helpers/core.rb +0 -94
  150. data/plugins/db/helpers/dataset_methods.rb +0 -138
  151. data/plugins/db/helpers/enums_plugin.rb +0 -52
  152. data/plugins/db/helpers/find_precache.rb +0 -31
  153. data/plugins/db/helpers/link_objects.rb +0 -84
  154. data/plugins/db/helpers/schema_checks.rb +0 -83
  155. data/plugins/db/helpers/typero_adapter.rb +0 -71
  156. data/plugins/db/logger/config.rb +0 -22
  157. data/plugins/db/logger/lux_response_adapter.rb +0 -10
  158. data/plugins/db/paginate/helper.rb +0 -32
  159. data/plugins/db/paginate/sequel_adapter.rb +0 -23
  160. data/plugins/exceptions/exceptions.rake +0 -43
  161. data/plugins/exceptions/simple_exception.rb +0 -64
  162. data/plugins/favicon/favicon.rb +0 -10
  163. data/plugins/html/README.md +0 -3
  164. data/plugins/html/html_form.rb +0 -118
  165. data/plugins/html/html_input.rb +0 -98
  166. data/plugins/html/html_menu.rb +0 -79
  167. data/plugins/html/input_types.rb +0 -346
  168. data/plugins/js_widgets/README.md +0 -5
  169. data/plugins/js_widgets/js/html_tag.coffee +0 -42
  170. data/plugins/js_widgets/js/widgets.coffee +0 -161
  171. data/plugins/js_widgets/js_widgets.rb +0 -15
  172. data/plugins/oauth/lib/facebook.rb +0 -35
  173. data/plugins/oauth/lib/github.rb +0 -38
  174. data/plugins/oauth/lib/google.rb +0 -41
  175. data/plugins/oauth/lib/linkedin.rb +0 -41
  176. data/plugins/oauth/lib/stackexchange.rb +0 -41
  177. data/plugins/oauth/lib/twitter.rb +0 -38
  178. data/plugins/oauth/oauth.rb +0 -42
  179. data/plugins/policy/policy.rb +0 -53
  180. data/tasks/nginx.rake +0 -23
  181. /data/lib/lux/{view/lib → mailer}/helper_modules.rb +0 -0
@@ -1,161 +0,0 @@
1
- 'use strict'
2
-
3
- # Micro Widget/Component lib by @dux
4
- # Super simple component lib for server side rendered templates
5
- # if you need someting similar but more widely adopted, use https://stimulusjs.org/
6
-
7
- # instance public interface
8
- # init() - called on every wiget $init
9
- # once() - called once on every page
10
- # css() - will add css to document head if present
11
- # set(k,v) - set state k to v and call render() if render defined
12
- # id - instance_id
13
- # node - dom_node
14
- # ref - "Widget.ref[this.id]", dom instance reference
15
- # state - data-json="{...}" -> @state all data-attributes are translated to state
16
-
17
- # Widget public interface
18
- # registere(name, object) - register widget
19
- # bind(node) - init widget by id or dom node
20
- # get(node) - get closest widget instance
21
- # refresh() - call render() on all widgets instances
22
-
23
- # Example code
24
- # <div class="w yes_no" data-filed="yes"></div>
25
- # Widget.register 'yes_no',
26
- # init:
27
- # @root = $ @node
28
- # @state =
29
- # field: @root.data('field')
30
-
31
- # render_button: (name, state) ->
32
- # $tag 'button.btn.btn-sm', name,
33
- # class: "btn-#{klass}"
34
- # onclick: @ref+".update_state('"+state+"')"
35
-
36
- # render: ->
37
- # data = @render_button(@state.no, 0)
38
- # @root.html $tag('div.btn-group', data)
39
-
40
- # update_state: (state) ->
41
- # @state.state = state
42
- # @render()
43
-
44
- # $ -> Widget.bind()
45
-
46
- @Widget =
47
- css_klass: 'w'
48
- inst_id_name: 'data-widget_id'
49
- registered: {},
50
- count: 0,
51
- ref: {},
52
-
53
- get: (node) ->
54
- parts = node.split('#', 2)
55
-
56
- if parts[1]
57
- node = document.getElementById(parts[1])
58
- @bind node
59
-
60
- node = node.closest(".#{@css_klass}") || alert('Cant find closest widgets')
61
- Widget.ref[parseInt(node.getAttribute(@inst_id_name))]
62
-
63
- clear: ->
64
- for i, w of @ref
65
- delete @ref[i] unless document.body.contains(w.node)
66
-
67
- init: (data) ->
68
- @clear()
69
-
70
- while node = @get_next_widget_node(data)
71
- @bind(node)
72
-
73
- get_next_widget_node: (root) ->
74
- root ||= window.document
75
-
76
- for node in root.getElementsByClassName(@css_klass)
77
- return node if node && !node.getAttribute('data-widget_id')
78
-
79
- null
80
-
81
- # refresh all widgets
82
- refresh: ->
83
- @clear()
84
-
85
- for node in @registered.values()
86
- node.render() if node.render
87
-
88
- # register widget, trigger once method, insert css if present
89
- register: (name, widget) ->
90
- return if @registered[name]
91
-
92
- @registered[name] = widget
93
-
94
- if widget.once
95
- widget.once()
96
- delete widget.once
97
-
98
- if widget.css
99
- data = if typeof(widget.css) == 'function' then widget.css() else widget.css
100
- document.head.innerHTML += """<style id="widget_#{name}_css">#{data}</style>"""
101
- delete widget.css
102
-
103
- # create set method unless defined
104
- widget.set ||= (name, value) ->
105
- @state[name] = value
106
- @render() if @render
107
-
108
- # runtime apply registered widget to dom node
109
- bind: (dom_node) ->
110
- dom_node = document.getElementById(dom_node) if typeof(dom_node) == 'string'
111
-
112
- instance_id = dom_node.getAttribute(@inst_id_name)
113
-
114
- if instance_id
115
- instance_id = parseInt instance_id
116
- else
117
- instance_id = ++@count
118
- dom_node.setAttribute(@inst_id_name, instance_id)
119
-
120
- return if @ref[instance_id]
121
-
122
- dom_node.setAttribute('id', "widget-#{instance_id}") unless dom_node.getAttribute('id')
123
- dom_node.setAttribute(@inst_id_name, instance_id)
124
-
125
- widget_name = dom_node.getAttribute('class').split(' ')[1]
126
- widget_opts = @registered[widget_name]
127
-
128
- # return if widget is not defined
129
- return alert "Widget #{widget_name} is not registred" unless widget_opts
130
-
131
- # define widget instance
132
- widget = {}
133
-
134
- # apply basic methods
135
- widget[key] = widget_opts[key] for key in Object.keys(widget_opts)
136
-
137
- # bind root to root
138
- widget.id = instance_id
139
- widget.ref = "Widget.ref[#{instance_id}]"
140
- widget.node = dom_node
141
-
142
- # set widget state, copy all date-attributes to state
143
- json = dom_node.getAttribute('data-json') || '{}'
144
- json = JSON.parse json
145
- widget.state = Object.assign(json, dom_node.dataset)
146
-
147
- # store in global object
148
- @ref[instance_id] = widget
149
-
150
- # init and render
151
- widget.init() if widget.init
152
- widget.render() if widget.render
153
-
154
- is_widget: (node) ->
155
- klass = node.getAttribute('class')
156
-
157
- if klass?.split(' ')[0] == 'w'
158
- node
159
- else
160
- undefined
161
-
@@ -1,15 +0,0 @@
1
- ApplicationHelper.class_eval do
2
-
3
- def widget name, opts={}
4
- tag, name = name.split(':') if name === String
5
-
6
- tag = :div
7
- id = Lux.current.uid
8
-
9
- data = block_given? ? yield : nil
10
-
11
- { class: 'w %s' % name, id: id, 'data-json': opts.to_json }.tag(tag, data) +
12
- %[<script>Widget.bind('#{id}');</script>]
13
- end
14
-
15
- end
@@ -1,35 +0,0 @@
1
- # https://developers.facebook.com
2
- # https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow
3
-
4
- class LuxOauth::Facebook < LuxOauth
5
- def login
6
- 'https://www.facebook.com/v2.8/dialog/oauth?scope=email&client_id=%s&redirect_uri=%s' % [@opts.key, CGI::escape(redirect_url)]
7
- end
8
-
9
- def format_response opts
10
- {
11
- email: opts['email'],
12
- avatar: '//graph.facebook.com/%s/picture?type=large' % opts['id'],
13
- name: opts['name']
14
- }
15
- end
16
-
17
- def callback session_code
18
- result = RestClient.post('https://graph.facebook.com/v2.8/oauth/access_token', {
19
- redirect_uri: redirect_url,
20
- client_id: @opts.key,
21
- client_secret: @opts.secret,
22
- code: session_code
23
- }, { :accept => :json })
24
-
25
- access_token = JSON.parse(result)['access_token']
26
-
27
- response = RestClient.get('https://graph.facebook.com/me', {
28
- :accept => :json,
29
- :params => { :access_token => access_token }
30
- })
31
-
32
- format_response JSON.parse response
33
- end
34
- end
35
-
@@ -1,38 +0,0 @@
1
- # https://github.com/settings/developers
2
- # https://github.com/github/platform-samples/tree/master/api/ruby/basics-of-authentication
3
- # https://github.com/settings/applications
4
-
5
- class LuxOauth::Github < LuxOauth
6
- def login
7
- "https://github.com/login/oauth/authorize?scope=user:email&client_id=#{@opts.key}"
8
- end
9
-
10
- def format_response opts
11
- {
12
- email: opts['email'],
13
- avatar: opts['avatar_url'],
14
- github: opts['login'],
15
- company: opts['company'],
16
- location: opts['location'],
17
- bio: opts['description'],
18
- name: opts['name']
19
- }
20
- end
21
-
22
- def callback session_code
23
- result = RestClient.post('https://github.com/login/oauth/access_token', {
24
- client_id: @opts.key,
25
- client_secret: @opts.secret,
26
- code: session_code
27
- }, { :accept => :json })
28
-
29
- # extract token and granted scopes
30
- access_token = JSON.parse(result)['access_token']
31
- # scopes = JSON.parse(result)['scope'].split(',')
32
-
33
- opts = JSON.parse(RestClient.get('https://api.github.com/user', {:params => {:access_token => access_token}, :accept => :json}))
34
-
35
- format_response opts
36
- end
37
- end
38
-
@@ -1,41 +0,0 @@
1
- # https://console.developers.google.com
2
- # https://developers.google.com/identity/protocols/googlescopes
3
-
4
- class LuxOauth::Google < LuxOauth
5
- def scope
6
- [
7
- 'https://www.googleapis.com/auth/userinfo.email',
8
- 'https://www.googleapis.com/auth/userinfo.profile'
9
- ]
10
- end
11
-
12
- def format_response opts
13
- {
14
- email: opts['email'],
15
- name: opts['name'],
16
- avatar: opts['picture'],
17
- locale: opts['locale'],
18
- gender: opts['gender']
19
- }
20
- end
21
-
22
- def login
23
- "https://accounts.google.com/o/oauth2/auth?client_id=#{@opts.key}&redirect_uri=#{redirect_url}&scope=#{scope.join('%20')}&response_type=code"
24
- end
25
-
26
- def callback session_code
27
- result = RestClient.post('https://www.googleapis.com/oauth2/v3/token', {
28
- grant_type: 'authorization_code',
29
- client_id: @opts.key,
30
- client_secret: @opts.secret,
31
- code: session_code,
32
- redirect_uri: redirect_url
33
- })
34
-
35
- hash = JSON.parse(result)
36
-
37
- user = JSON.parse RestClient.get('https://www.googleapis.com/oauth2/v1/userinfo', { :params => {:access_token => hash['access_token'], :alt=>:json }})
38
-
39
- format_response user
40
- end
41
- end
@@ -1,41 +0,0 @@
1
- # https://developer.linkedin.com/docs/oauth2
2
- # https://developer.linkedin.com/docs/fields/basic-profile
3
-
4
- class LuxOauth::Linkedin < LuxOauth
5
- def scope
6
- [
7
- 'r_basicprofile',
8
- 'r_emailaddress'
9
- ]
10
- end
11
-
12
- def login
13
- "https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=#{@opts.key}&redirect_uri=#{redirect_url}&state=987654321&scope=#{scope.join('%20')}"
14
- end
15
-
16
- def format_response opts
17
- {
18
- email: opts['emailAddress'],
19
- linkedin: opts['publicProfileUrl'],
20
- description: opts['specialties'],
21
- location: opts['location'],
22
- avatar: opts['pictureUrl'],
23
- name: "#{opts['firstName']} #{opts['lastName']}"
24
- }
25
- end
26
-
27
- def callback session_code
28
- result = RestClient.post('https://www.linkedin.com/oauth/v2/accessToken', {
29
- grant_type: 'authorization_code',
30
- client_id: @opts.key,
31
- client_secret: @opts.secret,
32
- code: session_code,
33
- redirect_uri: redirect_url
34
- })
35
-
36
- access_token = JSON.parse(result)['access_token']
37
- opts = JSON.parse RestClient::Request.execute(:method=>:get, :url=>'https://api.linkedin.com/v1/people/~:(id,picture-url,first-name,last-name,email-address,public-profile-url,specialties,location)?format=json', :headers => {'Authorization'=>"Bearer #{access_token}"})
38
-
39
- format_response opts
40
- end
41
- end
@@ -1,41 +0,0 @@
1
- # https://api.stackexchange.com/docs/authentication
2
-
3
- class LuxOauth::Stackexchange < LuxOauth
4
- def intialize
5
- raise ArgumentError.new('OAUTH_ID needed') unless @opts.id
6
- end
7
-
8
- def login
9
- 'https://stackexchange.com/oauth?client_id=%d&redirect_uri=%s' % [@opts.id, CGI::escape(redirect_url)]
10
- end
11
-
12
- def format_response opts
13
- {
14
- stackexchnage_user_id: opts['items'].first['user_id'],
15
- user: opts['items'].first
16
- }
17
- end
18
-
19
- def callback session_code
20
- result = RestClient.post('https://stackexchange.com/oauth/access_token', {
21
- redirect_uri: redirect_url,
22
- client_id: @opts.id,
23
- client_secret: @opts.secret,
24
- code: session_code
25
- }, { :accept => :json })
26
-
27
- access_token = result.to_s.css_to_hash['access_token']
28
-
29
- response = RestClient.get('https://api.stackexchange.com/2.2/me', {
30
- accept: :json,
31
- params: {
32
- site: 'stackoverflow',
33
- access_token: access_token,
34
- key: @opts.key
35
- }
36
- })
37
-
38
- format_response JSON.parse response
39
- end
40
- end
41
-
@@ -1,38 +0,0 @@
1
- class LuxOauth::Twitter < LuxOauth
2
- # def scope
3
- # [
4
- # 'r_basicprofile',
5
- # 'r_emailaddress'
6
- # ]
7
- # end
8
-
9
- # def login
10
- # 'https://api.twitter.com/oauth/authorize?oauth_token=%s' % @key
11
- # end
12
-
13
- # def format_response opts
14
- # {
15
- # email: opts['emailAddress'],
16
- # linkedin: opts['publicProfileUrl'],
17
- # description: opts['specialties'],
18
- # location: opts['location'],
19
- # avatar: opts['pictureUrl'],
20
- # name: "#{opts['firstName']} #{opts['lastName']}"
21
- # }
22
- # end
23
-
24
- # def callback(session_code)
25
- # result = RestClient.post('https://www.linkedin.com/oauth/v2/accessToken', {
26
- # grant_type: 'authorization_code',
27
- # client_id: @key,
28
- # client_secret: @secret,
29
- # code: session_code,
30
- # redirect_uri: redirect_url
31
- # })
32
-
33
- # access_token = JSON.parse(result)['access_token']
34
- # opts = JSON.parse RestClient::Request.execute(:method=>:get, :url=>'https://api.linkedin.com/v1/people/~:(id,picture-url,first-name,last-name,email-address,public-profile-url,specialties,location)?format=json', :headers => {'Authorization'=>"Bearer #{access_token}"})
35
-
36
- # format_response opts
37
- # end
38
- end
@@ -1,42 +0,0 @@
1
- class LuxOauth
2
- class_attribute :local_path, 'callback'
3
-
4
- class << self
5
- def get target
6
- "LuxOauth::#{target.to_s.classify}".constantize.new
7
- end
8
-
9
- def login target
10
- get(target).login
11
- end
12
- end
13
-
14
- ###
15
-
16
- def initialize
17
- @target = self.class.to_s.split('::').last.downcase.to_sym
18
- @opts = opts_loader
19
-
20
- raise ArgumentError, 'Host is invalid' unless host =~ /^https?:/
21
-
22
- for el in %i[key secret]
23
- raise ArgumentError.new('OAUTH %s needed for %s' % [el, @target]) unless @opts.send(el)
24
- end
25
- end
26
-
27
- def redirect_url
28
- [host, LuxOauth.local_path, @target].join('/')
29
- end
30
-
31
- private
32
-
33
- def opts_loader
34
- Lux.secrets.send(@target).oauth
35
- rescue
36
- raise "Can't load Oauth secrets for #{@target}: #{$!.message}"
37
- end
38
-
39
- def host
40
- Lux.config(:host)
41
- end
42
- end
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # base caller
4
- # Policy::User.new(model: @model, user: User.current).can?(:update) -> can current user update @user
5
-
6
- # block will capture error message and be triggered only if error is present
7
- # User.can?(:login) { |msg| http_error 401, "Err: #{msg}".red; return 'no access' }
8
-
9
- class Policy
10
-
11
- def initialize hash
12
- for k, v in hash
13
- instance_variable_set "@#{k}", v
14
- end
15
- end
16
-
17
- # pass block if you want to handle errors yourself
18
- # return true if false if block is passed
19
- def can? action, &block
20
- @action = action.to_s.sub('?','') + '?'
21
- @action = @action.to_sym
22
-
23
- # pre check
24
- raise RuntimeError, 'Method name not allowed' if %w(can).index(@action)
25
- raise NoMethodError, %[Policy check "#{action}" not found in #{self.class}] unless respond_to?(@action)
26
-
27
- call &block
28
- end
29
-
30
- # call has to be isolated because specific of error handling
31
- def call &block
32
- return true if before(@action)
33
- return true if send(@action)
34
- raise Lux::Error.unauthorized('Access disabled in policy')
35
- rescue Lux::Error
36
- error = $!.message
37
- error += " - #{self.class}.#{@action}" if Lux.config(:dump_errors)
38
- raise Lux::Error.unauthorized(error) unless block
39
- block.call(error)
40
- false
41
- end
42
-
43
- ###
44
-
45
- def before action
46
- false
47
- end
48
-
49
- def error message
50
- raise Lux::Error.unauthorized(message)
51
- end
52
-
53
- end
data/tasks/nginx.rake DELETED
@@ -1,23 +0,0 @@
1
- namespace :nginx do
2
- desc 'Generate sample config'
3
- task :generate do
4
- command = ARGV[1]
5
-
6
- ROOT = Dir.pwd
7
- FOLDER = Dir.pwd.split('/').last
8
-
9
- conf = Lux.fw_root.join('misc/nginx.conf').read
10
- conf = conf.gsub(/`([^`]+)`/) { `#{$1}`.chomp }
11
- conf = conf.gsub('$ROOT', ROOT)
12
- conf = conf.gsub('$FOLDER', FOLDER)
13
- puts conf
14
- end
15
-
16
- desc 'Edit nginx config'
17
- task :edit do
18
- folder = Dir.pwd.split('/').last
19
-
20
- run 'sudo vim /etc/sites-enabled/%s.conf' % folder
21
- end
22
- end
23
-
File without changes