Rails Metaprogramming:这个gem安装在哪里?

时间:2017-07-02 11:42:45

标签: ruby-on-rails metaprogramming bundler

快速元编程问题。在我的rails 5项目中,我想在代码中找到某个gem的安装位置(即不是命令行)。

我从interpolate=True开始。

在下面看,我看到我为这个ruby安装的各种宝石的所有版本(我使用rbenv,但这也适用于rvm)。

u = u""" Date Date1 Open High Low Close 2017-06-27 2017-06-27 10.75 10.850 10.665 10.70 2017-06-26 2017-06-26 10.57 10.740 10.570 10.69 2017-06-23 2017-06-23 10.59 10.710 10.500 10.63 2017-06-22 2017-06-22 10.56 10.720 10.530 10.65 2017-06-21 2017-06-21 10.75 10.750 10.500 10.53 2017-06-20 2017-06-20 10.88 10.925 10.780 10.81 2017-06-19 2017-06-19 10.77 10.920 10.760 10.82 2017-06-16 2017-06-16 10.74 10.910 10.740 10.78 2017-06-15 2017-06-15 10.86 10.930 10.690 10.76 2017-06-14 2017-06-14 10.96 11.040 10.910 11.02 2017-06-13 2017-06-13 10.57 10.930 10.570 10.93 2017-06-09 2017-06-09 10.59 10.650 10.500 10.57 2017-06-08 2017-06-08 10.28 10.590 10.280 10.57 2017-06-07 2017-06-07 10.35 10.420 10.290 10.35 2017-06-06 2017-06-06 10.66 10.700 10.280 10.38 2017-06-05 2017-06-05 10.80 10.850 10.560 10.70 2017-06-02 2017-06-02 11.32 11.390 11.190 11.19 2017-06-01 2017-06-01 11.26 11.330 11.160 11.20 2017-05-31 2017-05-31 11.22 11.400 11.190 11.27 2017-05-30 2017-05-30 11.10 11.260 11.070 11.23 2017-05-29 2017-05-29 11.36 11.370 11.045 11.08 2017-05-26 2017-05-26 11.55 11.590 11.320 11.36 2017-05-25 2017-05-25 11.62 11.670 11.455 11.66 2017-05-24 2017-05-24 11.67 11.755 11.590 11.62 2017-05-23 2017-05-23 11.77 11.835 11.590 11.64 2017-05-22 2017-05-22 12.06 12.110 11.800 11.83 2017-05-19 2017-05-19 12.15 12.235 11.990 12.03 2017-05-18 2017-05-18 12.00 12.130 11.910 12.13 2017-05-17 2017-05-17 12.28 12.300 12.120 12.14 2017-05-16 2017-05-16 12.23 12.385 12.220 12.30 2017-05-15 2017-05-15 12.10 12.255 12.030 12.22 2017-05-12 2017-05-12 12.30 12.300 12.050 12.12 2017-05-11 2017-05-11 12.30 12.445 12.270 12.34 2017-05-10 2017-05-10 11.99 12.415 11.950 12.25 2017-05-09 2017-05-09 12.07 12.100 11.730 11.79 2017-05-08 2017-05-08 12.14 12.230 12.060 12.10 2017-05-05 2017-05-05 12.24 12.250 12.020 12.04 2017-05-04 2017-05-04 12.23 12.270 12.050 12.14 2017-05-03 2017-05-03 12.43 12.460 12.200 12.23 2017-05-02 2017-05-02 12.44 12.470 12.310 12.46 2017-05-01 2017-05-01 12.25 12.440 12.230 12.44 2017-04-28 2017-04-28 12.47 12.480 12.230 12.32 2017-04-27 2017-04-27 12.39 12.515 12.380 12.50 2017-04-26 2017-04-26 12.03 12.510 12.030 12.37 2017-04-24 2017-04-24 12.00 12.055 11.920 12.03 2017-04-21 2017-04-21 11.88 11.990 11.840 11.88 2017-04-20 2017-04-20 11.78 11.840 11.710 11.80 2017-04-19 2017-04-19 11.70 11.745 11.610 11.74 2017-04-18 2017-04-18 11.95 11.950 11.605 11.74 2017-04-13 2017-04-13 11.95 12.010 11.920 11.95 2017-04-12 2017-04-12 12.05 12.050 11.945 12.01 2017-04-11 2017-04-11 11.95 12.140 11.945 12.08 2017-04-10 2017-04-10 11.79 11.930 11.780 11.91 2017-04-07 2017-04-07 11.83 11.830 11.690 11.78 2017-04-06 2017-04-06 11.85 11.870 11.740 11.78 2017-04-05 2017-04-05 12.06 12.140 11.800 11.96 2017-04-04 2017-04-04 12.03 12.160 11.930 12.07 2017-04-03 2017-04-03 12.14 12.180 11.860 11.98 2017-03-30 2017-03-30 12.01 12.230 11.970 12.14 2017-03-29 2017-03-29 11.99 12.050 11.900 12.03""" import io import matplotlib.pyplot as plt import pandas as pd import numpy as np #%matplotlib inline def WillR(ohlc, window): high, low, close = ohlc['High'], ohlc['Low'], ohlc['Close'] R = (np.nanmax(high, axis=0) - close) / (np.nanmax(high, axis=0) - np.nanmin(low, axis=0)) * -100 return R df = pd.read_csv(io.StringIO(u), delim_whitespace=True, index_col=0, parse_dates=True) ohlc = df[::-1] R = WillR(ohlc, 14) xAxis = ohlc.index fig = plt.figure(figsize=(18,9), dpi=100) ax = plt.subplot() plt.ylabel('Williams '+'%R', fontsize = 16) ax.xaxis.grid(color='grey', linestyle=':') ax.yaxis.grid(color='grey', linestyle=':') ax.plot(R, color='k', alpha=0.8, linewidth=1.2) ax.axhline(-20, color='r', linewidth=0.8) ax.axhline(-50, color='k', linestyle='dashed', linewidth=1.2) ax.axhline(-80, color='g', linewidth=0.8) ax.fill_between(xAxis, R, -20, where=(R >= -20), facecolor='r', edgecolor='r', alpha=0.5, interpolate=True) ax.fill_between(xAxis, R, -80, where=(R <= -80), facecolor='g', edgecolor='g', alpha=0.5, interpolate=True) plt.show() Bundler.install_path

/home/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/mygem-7eafb06c791d/

有没有办法告诉Bundler“你能告诉我安装gem /home/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/mygem-3da2bf38d01a/的目录吗?或者如果有一个宝石名称的哈希与他们的目录(或类似的东西),那也没关系

奖励:如果有关于捆绑器内部工作的指南,那也很酷:)

2 个答案:

答案 0 :(得分:2)

Bundler有show命令来显示gem的位置:

bundle show mygem

答案 1 :(得分:0)

rbenv-bundler是一个插件,它使得rbenv可以识别Bundler,因此你不必在每个命令前输入bundler exec。 你可以在〜/ .bundle / config(mac / linux)中创建一个配置文件来管理bundler的设置

BUNDLE_PATH: ~/vendor/some_path

如果您需要有关配置捆绑程序的更多信息,可以查看this bundler.io link