Class: JsonRpcObjects::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/json-rpc-objects/version.rb

Overview

Generic version class.

Constant Summary collapse

CLASS_NAME_GENERATOR =

Holds class name generator for internal use.

/_\w/
FILE_NAME_GENERATOR =

Holds file name generator for internal use.

/[a-z0-9][A-Z]/
@@cache =

Holds cache of class to module assignments.

{ }
@@files =

Holds loaded files indicator.

{ }

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ JsonRpcObjects::Generic::Object

Handles unknown call as request for appropriate class.

Camel case is defined by underscores, so for example #some_class<tt> will be transformed to <tt>SomeClass.

Parameters:

  • name (Symbol)

    formatted object name

Returns:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/json-rpc-objects/version.rb', line 71

def method_missing(name)
    name = name.to_s 

    # Class name
    class_name = "_" << name
    class_name.gsub!(self.class::CLASS_NAME_GENERATOR) { |s| s[1].chr.upcase }

    # Module name
    module_name = @module.name + "::" + class_name
    
    # File path
    file_path = "x" << module_name
    file_path.gsub!(self.class::FILE_NAME_GENERATOR) { |s| s[0].chr << "-" <<  s[1].chr }
    file_path.replace(file_path[2..-1])
    file_path.gsub!("::", "/")
    file_path.downcase!
    
    if not @@files.has_key? file_path
        require file_path
        @@files[file_path] = true
    end
    
    return __get_module(module_name)
end

Class Method Details

.get(mod) ⇒ Version

Returns version object for appropriate version module.

Parameters:

  • mod (Module)

    appropriate version module

Returns:



53
54
55
56
57
58
59
# File 'lib/json-rpc-objects/version.rb', line 53

def self.get(mod)
    if not @@cache.include? mod
        @@cache[mod] = self::new(mod)
    end
    
    @@cache[mod]
end