Class: Pleiades::Command::RoutingProxy
- Inherits:
-
Object
- Object
- Pleiades::Command::RoutingProxy
- Includes:
- Pleiades::Command::Routing::RouteRefine
- Defined in:
- lib/pleiades/core/command/routing_proxy.rb
Instance Attribute Summary collapse
-
#mount_pairs ⇒ Object
readonly
Returns the value of attribute mount_pairs.
-
#routers ⇒ Object
readonly
Returns the value of attribute routers.
Class Method Summary collapse
-
.collect_router_file(event) ⇒ Array<Pathname, ...>
読み込む router_files を決める。.
- .routing(&block) ⇒ Object
Instance Method Summary collapse
- #add(router_name, mnt_key: :default) ⇒ Object
- #default_router ⇒ Object
- #default_routing ⇒ Object
-
#initialize(event) ⇒ RoutingProxy
constructor
A new instance of RoutingProxy.
-
#mount(**paths) ⇒ Object
‘add`で指定するキーワードを登録する。.
- #unmount(*mnt_symbols) ⇒ Object
- #unmount_all ⇒ Object
Methods included from Pleiades::Command::Routing::RouteRefine
Constructor Details
#initialize(event) ⇒ RoutingProxy
Returns a new instance of RoutingProxy.
45 46 47 48 49 50 51 |
# File 'lib/pleiades/core/command/routing_proxy.rb', line 45 def initialize(event) @event = event @routers = [] @mount_pairs = {} mount default: Pleiades::Constants::File::CONFIG_DIR_PATH end |
Instance Attribute Details
#mount_pairs ⇒ Object (readonly)
Returns the value of attribute mount_pairs.
43 44 45 |
# File 'lib/pleiades/core/command/routing_proxy.rb', line 43 def mount_pairs @mount_pairs end |
#routers ⇒ Object (readonly)
Returns the value of attribute routers.
43 44 45 |
# File 'lib/pleiades/core/command/routing_proxy.rb', line 43 def routers @routers end |
Class Method Details
.collect_router_file(event) ⇒ Array<Pathname, ...>
読み込む router_files を決める。
21 22 23 24 25 26 |
# File 'lib/pleiades/core/command/routing_proxy.rb', line 21 def collect_router_file(event) @event = event proxy_exists? ? load(proxy_file) : routing collect! end |
.routing(&block) ⇒ Object
9 10 11 12 13 |
# File 'lib/pleiades/core/command/routing_proxy.rb', line 9 def routing(&block) @_ = new(@event) block_given? ? @_.instance_eval(&block) : @_.default_routing end |
Instance Method Details
#add(router_name, mnt_key: :default) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/pleiades/core/command/routing_proxy.rb', line 57 def add(router_name, mnt_key: :default) no_keyword_err = lambda { |key| " from \#{__FILE__}:\#{__LINE__ - 1}:in `\#{__method__}`:\n Unmounted key `\#{key}`. Please call `mount \#{key}: 'path/to/router'` before `\#{__method__}`.\n MES\n }\n dir = @mount_pairs.fetch(mnt_key) { |key| raise no_keyword_err.call(key) }\n\n @routers << \"\#{dir}/\#{router_name}.rb\"\nend\n" |
#default_router ⇒ Object
102 103 104 |
# File 'lib/pleiades/core/command/routing_proxy.rb', line 102 def default_router :router end |
#default_routing ⇒ Object
53 54 55 |
# File 'lib/pleiades/core/command/routing_proxy.rb', line 53 def default_routing add default_router end |
#mount(**paths) ⇒ Object
‘add`で指定するキーワードを登録する。
## EXAMPLE mount hoge: ‘path/to/hoge’ add :fuga, mnt: :hoge # => path/to/hoge/fuga.rb
80 81 82 83 84 85 86 |
# File 'lib/pleiades/core/command/routing_proxy.rb', line 80 def mount(**paths) validate_mount_keys(paths.keys) paths.each_pair do |symbol, path| @mount_pairs.store(symbol, path =~ %r{(\S+)/$} ? $1 : path) end end |
#unmount(*mnt_symbols) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/pleiades/core/command/routing_proxy.rb', line 88 def unmount(*mnt_symbols) return @mount_pairs.clear && nil if mnt_symbols.include?(:all) warn = ->(key) { "\nWarning from #{__FILE__}:#{__LINE__ - 3}:in `#{__method__}`: `#{key}` is unmounted." } mnt_symbols.each do |symbol| @mount_pairs.delete(symbol) { |sym| puts warn.call(sym) } end end |
#unmount_all ⇒ Object
98 99 100 |
# File 'lib/pleiades/core/command/routing_proxy.rb', line 98 def unmount_all unmount :all end |