Module: Synaptic4r::StorageRest::ClassMethods

Defined in:
lib/synaptic4r/rest.rb

Overview


Constant Summary collapse

@@method_defs =

.….….….….….….….….….….….….….….….….….….….….….….….….……

Hash.new{|h,k| h[k] = {:required => [], :optional => []}}
@@arg_defs =
Hash.new{|h,k| h[k] = {}}

Instance Method Summary collapse

Instance Method Details

#arg_defsObject

.….….….….….….….….….….….….….….….….….….….….….….….….……



68
69
70
# File 'lib/synaptic4r/rest.rb', line 68

def arg_defs
  @@arg_defs
end

#argsObject

.….….….….….….….….….….….….….….….….….….….….….….….….……



94
95
96
# File 'lib/synaptic4r/rest.rb', line 94

def args
  method_defs
end

#args_all_methods(type) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



138
139
140
# File 'lib/synaptic4r/rest.rb', line 138

def args_all_methods(type)
  args[:all][type].inject([]){|r,a| rest_arg(a)[:header].eql?(:hide) ? r : r << a}
end

.….….….….….….….….….….….….….….….….….….….….….….….….……



153
154
155
# File 'lib/synaptic4r/rest.rb', line 153

def banner(meth)
  args[meth][:banner]
end

#define_rest_arg(arg, opts) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



89
90
91
# File 'lib/synaptic4r/rest.rb', line 89

def define_rest_arg(arg, opts)
  arg_defs[arg].update(opts)
end

#define_rest_method(meth, args) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/synaptic4r/rest.rb', line 73

def define_rest_method(meth, args)
  [meth].flatten.each do |m|
    method_defs[m][:required] += args[:required] if args[:required]
    method_defs[m][:optional] += args[:optional] if args[:optional]
    method_defs[m][:http_method] = args[:http_method]
    method_defs[m][:desc] = args[:desc]
    method_defs[m][:result_class] = args[:result_class]
    method_defs[m][:query] = args[:query]
    method_defs[m][:exe] = args[:exe]
    method_defs[m][:map_required_args] = args[:map_required_args]
    method_defs[m][:banner] = args[:banner]
    method_defs[m][:diagnostics] = args[:diagnostics]
  end  
end

#desc(meth) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



143
144
145
# File 'lib/synaptic4r/rest.rb', line 143

def desc(meth)
  args[meth][:desc]
end

#diagnostics(meth) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



158
159
160
# File 'lib/synaptic4r/rest.rb', line 158

def diagnostics(meth)
  args[meth][:diagnostics].nil? ? true : args[meth][:diagnostics]
end

#emc_headersObject

.….….….….….….….….….….….….….….….….….….….….….….….….……



184
185
186
# File 'lib/synaptic4r/rest.rb', line 184

def emc_headers
  arg_defs.inject([]){|r, (a, d)| d[:header].eql?(:emc) ? r.push(a) : r}
end

#exclusive_rest_args(meth) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



123
124
125
# File 'lib/synaptic4r/rest.rb', line 123

def exclusive_rest_args(meth)
  args[meth][:required].inject([]){|r,a| a.kind_of?(Array) ? r << a : r}
end

#exe(meth) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



148
149
150
# File 'lib/synaptic4r/rest.rb', line 148

def exe(meth)
  args[meth][:exe]
end

#has_rest_method?(meth) ⇒ Boolean

.….….….….….….….….….….….….….….….….….….….….….….….….……

Returns:

  • (Boolean)


99
100
101
# File 'lib/synaptic4r/rest.rb', line 99

def has_rest_method?(meth)
 rest_methods.include?(meth)
end

#header_args(meth) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



178
179
180
181
# File 'lib/synaptic4r/rest.rb', line 178

def header_args(meth)
  unary_rest_args(meth) + exclusive_rest_args(meth).flatten + optional_rest_args(meth) - 
    non_header_args(meth)
end

#http_method(meth) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



108
109
110
# File 'lib/synaptic4r/rest.rb', line 108

def http_method(meth)
  args[meth][:http_method]
end

#map_required_args(meth) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



163
164
165
# File 'lib/synaptic4r/rest.rb', line 163

def map_required_args(meth)
  args[meth][:map_required_args]
end

#method_defsObject

.….….….….….….….….….….….….….….….….….….….….….….….….……



63
64
65
# File 'lib/synaptic4r/rest.rb', line 63

def method_defs
  @@method_defs
end

#non_header_args(meth) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



189
190
191
# File 'lib/synaptic4r/rest.rb', line 189

def non_header_args(meth)
  arg_defs.inject([]){|r, (a, d)| d[:header].eql?(:none) ? r.push(a) : r}
end

#optional_rest_args(meth) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



128
129
130
# File 'lib/synaptic4r/rest.rb', line 128

def optional_rest_args(meth)
  args[meth][:optional] + args_all_methods(:optional)
end

#query(meth) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



173
174
175
# File 'lib/synaptic4r/rest.rb', line 173

def query(meth)
  args[meth][:query]
end

#required_rest_args(meth) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



113
114
115
# File 'lib/synaptic4r/rest.rb', line 113

def required_rest_args(meth)
  args[meth][:required] + args_all_methods(:required) 
end

#rest_arg(arg) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



133
134
135
# File 'lib/synaptic4r/rest.rb', line 133

def rest_arg(arg)
  arg_defs[arg]
end

#rest_methodsObject

.….….….….….….….….….….….….….….….….….….….….….….….….……



104
105
106
# File 'lib/synaptic4r/rest.rb', line 104

def rest_methods
  args.keys.inject([]){|r,m| m.eql?(:all) ? r : r << m}
end

#result_class(meth) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



168
169
170
# File 'lib/synaptic4r/rest.rb', line 168

def result_class(meth)
  args[meth][:result_class]
end

#unary_rest_args(meth) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



118
119
120
# File 'lib/synaptic4r/rest.rb', line 118

def unary_rest_args(meth)
  args[meth][:required].inject([]){|r,a| a.kind_of?(Array) ?  r : r << a}
end