Module: ModuleHelper

Defined in:
lib/module_helper.rb

Constant Summary collapse

CLIENT_METHODS_FOLDER =
'mapper_methods'

Class Method Summary collapse

Class Method Details

.parse_signature(signature, client_name = nil, table_name = nil, field_name = nil) ⇒ Object

‘shared/phone/number/normalize(phonenumber)’ -> [‘shared’, ‘phone’, ‘number’], ‘normalize’, [‘phonenumber’]

‘(status)’, client_name: ‘reliable’, field_name: ‘active’ -> [‘reliable’, ‘mapper_methods’], ‘active’, [‘status’]



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/module_helper.rb', line 8

def self.parse_signature(signature, client_name=nil, table_name=nil, field_name=nil)
  match = signature.match(/^(.*)\((.*)\)/)

  result = {arguments: match[2].delete(' ').split(',')}

  if shared_method?(signature)
    path = match[1].split('/')

    result[:method_name] = path.pop.to_sym
    result[:path] = path
  else
    result[:method_name] = field_name
    result[:path] = [client_name, CLIENT_METHODS_FOLDER, table_name]
  end

  result
end

.shared_method?(signature) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/module_helper.rb', line 28

def self.shared_method?(signature)
  !!(signature =~ /^shared\//)
end