Module: Apia::Defineable

Included in:
API, ArgumentSet, Authenticator, Controller, Endpoint, Enum, Error, Object, Polymorph, Scalar
Defined in:
lib/apia/defineable.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **kwargs, &block) ⇒ Object

Passes all other values through to the DSL for the definition if the DSL supoprts it.



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/apia/defineable.rb', line 43

def method_missing(name, *args, **kwargs, &block)
  if definition.dsl.respond_to?(name)
    if kwargs.empty?
      definition.dsl.send(name, *args, &block)
    else
      definition.dsl.send(name, *args, **kwargs, &block)
    end
  else
    super
  end
end

Instance Method Details

#create(id, &block) ⇒ Class

Create a new object

Parameters:

  • id (String)

Returns:

  • (Class)


18
19
20
21
22
23
24
25
# File 'lib/apia/defineable.rb', line 18

def create(id, &block)
  klass = Class.new(self)
  klass.definition.id = id
  if block_given?
    klass.definition.dsl.instance_eval(&block)
  end
  klass
end

#inspectString

Inspect an object

Returns:

  • (String)


9
10
11
12
# File 'lib/apia/defineable.rb', line 9

def inspect
  type = ancestors.find { |c| c.name =~ /\AApia::/ }
  "<#{definition.id} [#{type}]>"
end

#name(new_name = nil) ⇒ String

Ability to set a name (for DSL purposes) but also returns a name of the actual class if no new value is provided

Parameters:

  • new_name (String, nil) (defaults to: nil)

Returns:

  • (String)


32
33
34
35
36
37
38
39
# File 'lib/apia/defineable.rb', line 32

def name(new_name = nil)
  if new_name
    definition.name = new_name
    return new_name
  end

  super()
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/apia/defineable.rb', line 55

def respond_to_missing?(name, include_private = false)
  definition.dsl.respond_to?(name) || super
end