Module: EasyqaApi::ClassMethodsSettable

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

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#install_class_methods!(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/easyqa_api/helpers/class_methods_settable.rb', line 5

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