Module: WiseGopher::Base::ClassMethods

Defined in:
lib/wise_gopher/base.rb

Overview

class methods for WiseGopher::Base

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



25
26
27
# File 'lib/wise_gopher/base.rb', line 25

def params
  @params
end

#raw_paramsObject (readonly)

Returns the value of attribute raw_params.



25
26
27
# File 'lib/wise_gopher/base.rb', line 25

def raw_params
  @raw_params
end

#row_classObject (readonly)

Returns the value of attribute row_class.



25
26
27
# File 'lib/wise_gopher/base.rb', line 25

def row_class
  @row_class
end

Instance Method Details

#ensure_all_params_are_given(inputs = {}) ⇒ Object



67
68
69
70
71
# File 'lib/wise_gopher/base.rb', line 67

def ensure_all_params_are_given(inputs = {})
  missing_params = required_params.keys - inputs.keys.map(&:to_s)

  raise WiseGopher::ArgumentError, required_params.slice(*missing_params) if missing_params.any?
end

#executeObject



55
56
57
58
59
# File 'lib/wise_gopher/base.rb', line 55

def execute
  ensure_all_params_are_given

  new.execute
end

#execute_with(inputs) ⇒ Object



61
62
63
64
65
# File 'lib/wise_gopher/base.rb', line 61

def execute_with(inputs)
  ensure_all_params_are_given(inputs)

  new(inputs).execute
end

#param(name, type, transform = nil) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/wise_gopher/base.rb', line 31

def param(name, type, transform = nil)
  new_param = WiseGopher::Param.new(name, type, transform)

  ensure_param_name_is_available(new_param.name)

  params[new_param.name] = new_param
end

#query(query) ⇒ Object



27
28
29
# File 'lib/wise_gopher/base.rb', line 27

def query(query)
  const_set "QUERY", query.freeze
end

#raw_param(name, **kwargs) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/wise_gopher/base.rb', line 39

def raw_param(name, **kwargs)
  raw_param = WiseGopher::RawParam.new(name, **kwargs)

  ensure_param_name_is_available(raw_param.name)

  raw_params[raw_param.name] = raw_param
end

#row(base = nil, &block) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/wise_gopher/base.rb', line 47

def row(base = nil, &block)
  @row_class ||= base || define_generic_row_class

  @row_class.include WiseGopher::Row unless @row_class.ancestors.include?(WiseGopher::Row)

  @row_class.class_eval(&block) if block_given?
end

#set_defaultsObject



73
74
75
76
# File 'lib/wise_gopher/base.rb', line 73

def set_defaults
  @raw_params = {}
  @params = {}
end