Module: EasyqaApi::ClassMethodsSettable

Included in:
Item
Defined in:
lib/easyqa_api/helpers/class_methods_settable.rb

Overview

This module provides extends instance methods to class

Constant Summary collapse

METHODS =

List of allowed instance methods

[:create, :show, :update, :delete].freeze

Instance Method Summary collapse

Instance Method Details

#install_class_methods!(options = {}) ⇒ Object

Provide instance methods to class

Examples:

With only params

install_class_methods! only: [:update, :delete]

With except params

install_class_methods! except: [:create]

Parameters:

  • options (Hash) (defaults to: {})

    options for install class methods

Options Hash (options):

  • :only (Array)

    only few methods from METHODS constant

  • :except (Array)

    except few methods from METHODS constant

See Also:



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/easyqa_api/helpers/class_methods_settable.rb', line 16

def install_class_methods!(options = {})
  METHODS.each do |method_name|
    define_singleton_method method_name do |*attrs|
      instance = new
      instance.install_variables!(
        instance.send(method_name, *attrs).merge(attrs.find { |attr| attr.is_a? Hash } || {})
      )
      instance
    end if method_permitted?(options, method_name)
  end
end