Class: Raiblocks::ProxyContext
- Inherits:
-
Object
- Object
- Raiblocks::ProxyContext
- Defined in:
- lib/raiblocks/proxy_context.rb
Instance Method Summary collapse
- #ensure_no_forbidden_params! ⇒ Object
- #ensure_required_params! ⇒ Object
-
#initialize(klass, m, opts = {}) ⇒ ProxyContext
constructor
A new instance of ProxyContext.
- #populate_params(params) ⇒ Object
- #valid_proxy_method? ⇒ Boolean
- #validate_opts! ⇒ Object
- #validate_params! ⇒ Object
Constructor Details
#initialize(klass, m, opts = {}) ⇒ ProxyContext
Returns a new instance of ProxyContext.
3 4 5 6 7 8 9 |
# File 'lib/raiblocks/proxy_context.rb', line 3 def initialize(klass, m, opts = {}) @klass = klass @method_def = klass.proxy_method_def @param_def = klass.proxy_param_def @m = m @opts = opts end |
Instance Method Details
#ensure_no_forbidden_params! ⇒ Object
42 43 44 45 46 47 |
# File 'lib/raiblocks/proxy_context.rb', line 42 def ensure_no_forbidden_params! forbidden_params = base_param_keys + opts_keys - allowed_params return unless forbidden_params.any? raise Raiblocks::ForbiddenParameter, "Forbidden parameter(s) passed: #{forbidden_params.join(', ')}" end |
#ensure_required_params! ⇒ Object
35 36 37 38 39 40 |
# File 'lib/raiblocks/proxy_context.rb', line 35 def ensure_required_params! missing_params = required_params - opts_keys return unless missing_params.any? raise Raiblocks::MissingParameters, "Missing required parameter(s): #{missing_params.join(', ')}" end |
#populate_params(params) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/raiblocks/proxy_context.rb', line 15 def populate_params(params) opts = validate_opts! opts.merge!(params) if params validate_params! opts.delete_if { |_k, v| v.nil? } opts end |
#valid_proxy_method? ⇒ Boolean
11 12 13 |
# File 'lib/raiblocks/proxy_context.rb', line 11 def valid_proxy_method? rpc_action? end |
#validate_opts! ⇒ Object
23 24 25 26 27 28 |
# File 'lib/raiblocks/proxy_context.rb', line 23 def validate_opts! return @opts if @opts.is_a?(Hash) return {} if @opts.nil? raise Raiblocks::InvalidParameterType, 'You must pass a hash to an action method' end |
#validate_params! ⇒ Object
30 31 32 33 |
# File 'lib/raiblocks/proxy_context.rb', line 30 def validate_params! ensure_required_params! ensure_no_forbidden_params! end |