flame 4.17.0 → 4.18.0

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: e6ccec989786ef96d130c6526ac47ef646defd74
4
- data.tar.gz: 20f122fcea6d8eebeb420eb58e93d00f85243084
3
+ metadata.gz: ebb50e9412146b4ff8539c37a33078d360bd7414
4
+ data.tar.gz: 80a08f804d28d61dd8bf6cfcd9681d923b23cb41
5
5
  SHA512:
6
- metadata.gz: bdcedf23fb41f2cab59be449f0daa40dc529e3b832bf11fe04fa4d1d01c0e008b199580bd107bc7dec5a2935554b5b9016d0277b7c63439b229c37e9bb02275e
7
- data.tar.gz: 07e37694dd64ab3da6a0ca659fccc3c4832b620a4be57ef13a512b7694acc963e778aeaabb4cf20f7934b75ef92340d0a40b195caa31a9aa581fb91f4770b0e2
6
+ metadata.gz: 9680f9cd7ddca87d9024211c0c98c20e611061b2a6934c16a364e083f57076a92dbe5e15d14ce97f090450658517bec0fb3b84a8a3800ccc9da5a7532efdbda9
7
+ data.tar.gz: 50d5041a23247616a53dd3e605def07edef86705c89cda45dc8f988e55d7f439fde677fef0fca088dcd0265f582556a812581863bc9f7920556ae656f280ecbc
@@ -9,6 +9,8 @@ module Flame
9
9
  class Controller
10
10
  extend Forwardable
11
11
 
12
+ FORBIDDEN_ACTIONS = [].freeze
13
+
12
14
  ## Shortcut for not-inherited public methods: actions
13
15
  def self.actions
14
16
  public_instance_methods(false)
@@ -121,8 +123,7 @@ module Flame
121
123
  ## Execute the method of the controller with hooks (may be overloaded)
122
124
  ## @param method [Symbol] name of the controller method
123
125
  def execute(method)
124
- # send method
125
- body send(method, *extract_params_for(method).values)
126
+ body send(method, *extract_params_for(method))
126
127
  end
127
128
 
128
129
  ## Default method for Internal Server Error, can be inherited
@@ -148,12 +149,18 @@ module Flame
148
149
  end
149
150
 
150
151
  def extract_params_for(action)
151
- # p action, params, parameters
152
- method(action).parameters.each_with_object({}) do |parameter, result|
153
- key = parameter.last
154
- next if params[key].nil?
155
- result[key] = params[key]
152
+ # Take parameters from action method
153
+ parameters = method(action).parameters
154
+ # Fill variables with values from params
155
+ req_values, opt_values = %i[req opt].map! do |type|
156
+ params.values_at(
157
+ *parameters.select { |key, _value| key == type }.map!(&:last)
158
+ )
156
159
  end
160
+ # Remove nils from the end of optional values
161
+ opt_values.pop while opt_values.last.nil? && !opt_values.empty?
162
+ # Concat values
163
+ req_values + opt_values
157
164
  end
158
165
 
159
166
  def add_controller_class(args)
@@ -201,8 +208,10 @@ module Flame
201
208
  end
202
209
 
203
210
  ## Module for public instance methods re-defining from superclass
204
- ## @example Inherit controller with parent actions by `extend`
211
+ ## @example Inherit controller with parent actions without forbidden
212
+ ## actions by `extend`
205
213
  ## class MyController < BaseController
214
+ ## FORBIDDEN_ACTIONS = %[foo bar baz].freeze
206
215
  ## extend Flame::Controller::ParentActions
207
216
  ## end
208
217
  module ParentActions
@@ -215,7 +224,7 @@ module Flame
215
224
  end
216
225
 
217
226
  def define_parent_actions
218
- superclass.actions.each do |public_method|
227
+ (superclass.actions - self::FORBIDDEN_ACTIONS).each do |public_method|
219
228
  um = superclass.public_instance_method(public_method)
220
229
  define_method public_method, um
221
230
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flame
4
- VERSION = '4.17.0'
4
+ VERSION = '4.18.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flame
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.17.0
4
+ version: 4.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Popov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-14 00:00:00.000000000 Z
11
+ date: 2017-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack