Module: CitrusLoader

Defined in:
lib/citrus-loader/loader.rb,
lib/citrus-loader/version.rb

Overview

Author

MinixLi (gmail: MinixLi1986)

Homepage

citrus.inspawn.com

Date

16 July 2014

Constant Summary collapse

VERSION =
'0.0.1'

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.app_handler_loadedObject (readonly)

Returns the value of attribute app_handler_loaded.



34
35
36
# File 'lib/citrus-loader/loader.rb', line 34

def app_handler_loaded
  @app_handler_loaded
end

.app_remote_loadedObject (readonly)

Returns the value of attribute app_remote_loaded.



34
35
36
# File 'lib/citrus-loader/loader.rb', line 34

def app_remote_loaded
  @app_remote_loaded
end

.handler_filters_loadedObject (readonly)

Returns the value of attribute handler_filters_loaded.



35
36
37
# File 'lib/citrus-loader/loader.rb', line 35

def handler_filters_loaded
  @handler_filters_loaded
end

.rpc_filters_loadedObject (readonly)

Returns the value of attribute rpc_filters_loaded.



35
36
37
# File 'lib/citrus-loader/loader.rb', line 35

def rpc_filters_loaded
  @rpc_filters_loaded
end

Instance Method Details

#get_service_name(subclass) ⇒ Object

Get service name

Parameters:

  • subclass (Class)


139
140
141
142
143
# File 'lib/citrus-loader/loader.rb', line 139

def get_service_name subclass
  service = subclass.name
  service[0] = service[0].downcase
  service
end

#load_app_handler(path) ⇒ Object

Load app handler

Parameters:

  • path (String)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/citrus-loader/loader.rb', line 41

def load_app_handler path
  if !File.directory? path
    raise ArgumentError, 'expected a directory'
  end

  result = []
  Dir.glob(File.join(path, '') + '*.rb').each { |filepath|
    if CitrusLoader.app_handler_loaded[filepath]
      result << CitrusLoader.app_handler_loaded[filepath]
    else
      ::Citrus::AppHandler.define_singleton_method(:inherited) { |subclass|
        CitrusLoader.app_handler_loaded[filepath] = subclass
        result << subclass
      }
      require filepath
    end
  }
  result
end

#load_app_remote(path) ⇒ Object

Load app remote

Parameters:

  • path (String)


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/citrus-loader/loader.rb', line 64

def load_app_remote path
  if !File.directory? path
    raise ArgumentError, 'expected a directory'
  end

  subclasses = []
  Dir.glob(File.join(path, '') + '*.rb').each { |filepath|
    if subclass = CitrusLoader.app_remote_loaded[filepath]
      subclasses << subclass
    else
      ::Citrus::AppRemote.define_singleton_method(:inherited) { |subclass|
        CitrusLoader.app_remote_loaded[filepath] = subclass
        subclasses << subclass
      }
      require filepath
    end
  }

  result = {}
  subclasses.each { |subclass|
    service = get_service_name subclass
    result[service] = subclass
  }
  result
end

#load_handler_filters(path) ⇒ Object

Load handler filters

Parameters:

  • path (String)


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/citrus-loader/loader.rb', line 93

def load_handler_filters path
  if !File.directory? path
    raise ArgumentError, 'expected a directory'
  end

  result = []
  Dir.glob(File.join(path, '') + '*.rb').each { |filepath|
    if CitrusLoader.handler_filters_loaded[filepath]
      result << CitrusLoader.handler_filters_loaded[filepath]
    else
      ::Citrus::HandlerFilter.define_singleton_method(:inherited) { |subclass|
        CitrusLoader.handler_filters_loaded[filepath] = subclass
        result << subclass
      }
      require filepath
    end
  }
  result
end

#load_rpc_filters(path) ⇒ Object

Load rpc filters

Parameters:

  • path (String)


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/citrus-loader/loader.rb', line 116

def load_rpc_filters path
  if !File.directory? path
    raise ArgumentError, 'expected a directory'
  end

  result = []
  Dir.glob(File.join(path, '') + '*.rb').each { |filepath|
    if CitrusLoader.rpc_filters_loaded[filepath]
      result << CitrusLoader.rpc_filters_loaded[filepath]
    else
      ::Citrus::RpcFilter.define_singleton_method(:inherited) { |subclass|
        CitrusLoader.rpc_filters_loaded[filepath] = subclass
        result << subclass
      }
      require filepath
    end
  }
  result
end