Class: ActionService::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/action_service/base.rb

Class Method Summary collapse

Class Method Details

.export(name, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/action_service/base.rb', line 13

def export(name, options={})
  validate_options([:expects, :returns, :expects_and_returns], options.keys)
  if options[:expects_and_returns]
    expects = options[:expects_and_returns]
    returns = options[:expects_and_returns]
  else
    expects = options[:expects]
    returns = options[:returns]
  end
  if expects.nil?
    arity = instance_method(name).arity
    expects = [Object] * arity if arity > 0
  end
  if returns.nil?
    returns = [NilClass]
  end

  name = name.to_sym
  public_name = public_export_name(name)
  info = { :expects => expects, :returns => returns }
  write_inheritable_hash("action_service_exports", name => info)
  write_inheritable_hash("action_service_public_exports", public_name => name)
end

.exportsObject



57
58
59
# File 'lib/action_service/base.rb', line 57

def exports
  read_inheritable_attribute("action_service_exports") || {}
end

.has_export?(name) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/action_service/base.rb', line 37

def has_export?(name)
  exports.has_key?(name)
end

.has_public_export?(name) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/action_service/base.rb', line 41

def has_public_export?(name)
  public_exports.has_key?(name)
end

.internal_export_name(public_name) ⇒ Object



53
54
55
# File 'lib/action_service/base.rb', line 53

def internal_export_name(public_name)
  public_exports[public_name]
end

.public_export_name(export_name) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/action_service/base.rb', line 45

def public_export_name(export_name)
  if export_name_mangling
    Inflector.camelize(export_name.to_s)
  else
    export_name.to_s
  end
end