Module: ZerigoDNS::Resource::Naming::ClassMethods

Defined in:
lib/zerigodns/resource/naming.rb

Instance Method Summary collapse

Instance Method Details

#base_path(path = nil) ⇒ String

Sets or gets the “base path”, where the resource is located.

Parameters:

  • path (String) (defaults to: nil)

    base path

Returns:

  • (String)

    the base path



35
36
37
38
39
40
# File 'lib/zerigodns/resource/naming.rb', line 35

def base_path path=nil
  if path
    @base_path = path
  end
  @base_path || default_base_path
end

#default_base_pathString

Default base path.

Returns:

  • (String)

    Generated base path from class name (default_resource_name + “s”)



17
18
19
# File 'lib/zerigodns/resource/naming.rb', line 17

def default_base_path
  "#{resource_name}s"
end

#default_resource_nameString

Default Resource Name

Returns:

  • (String)

    generated resource name from class name “e.g. ZerigoDNS::ZoneTemplate -> zone_template”



9
10
11
12
# File 'lib/zerigodns/resource/naming.rb', line 9

def default_resource_name
  result = self.to_s.split("::").last.gsub(/([A-Z])/, '_\1').downcase
  result.slice 1, result.length
end

#resource_name(name = nil) ⇒ String

Sets & gets the “resource name”, which is required for the create & update actions.

Parameters:

  • name (String) (defaults to: nil)

    resource name

Returns:

  • (String)

    the base path



25
26
27
28
29
30
# File 'lib/zerigodns/resource/naming.rb', line 25

def resource_name name=nil
  if name
    @resource_name = name
  end
  @resource_name || default_resource_name
end