小编iai*_*ain的帖子

是否可能,以及Postgresql的HStore类型中嵌套哈希的语法是什么?

我甚至不确定Postgres的HStore数据类型是否可以包含嵌套哈希,如果可以的话,如何插入它们?

这是我到目前为止所尝试的:

-- Database: test1

-- DROP DATABASE test1;
/*
CREATE DATABASE test1
  WITH OWNER = iainuser
       ENCODING = 'UTF8'
       TABLESPACE = pg_default
       LC_COLLATE = 'en_GB.UTF-8'
       LC_CTYPE = 'en_GB.UTF-8'
       CONNECTION LIMIT = -1;
*/
/* create extension hstore; */
/*drop table my_store;*/
/*
create table my_store (
  id serial primary key not null,
  doc hstore
);

CREATE INDEX my_store_doc_idx_gist
  ON my_store
  USING gist
  (doc);
*/
/* select doc from my_store; */
/*
insert into my_store (doc) values ( '"a" => …
Run Code Online (Sandbox Code Playgroud)

postgresql postgresql-9.1 hstore

9
推荐指数
1
解决办法
5269
查看次数

Sinatra和Grape API在一起?

我一直在读书,我发现这个名为Grape的微框架用于红宝石.我目前正在使用Sinatra来处理Web界面,但我还想实现Grape来处理应用程序的API方面.我找不到任何有用的建议来解决这个问题.葡萄文档说"Grape是一个类似REST的API微框架,用于Ruby.它设计用于在Rack上运行,或通过提供简单的DSL来轻松开发RESTful API,从而补充现有的Web应用程序框架,如Rails和Sinatra." 所以听起来应该有正式的两种方式相结合的方式吗?这个应用程序也将在Heroku上运行.

ruby rubygems heroku sinatra grape-api

9
推荐指数
1
解决办法
5324
查看次数

语法突出显示

我正在寻找一个通用的语法高亮库,输出到html.

它是在一个ruby应用程序中使用,所以一个ruby库会很好,但是一个很好的实用程序可以通过管道传入和传出

还需要猜测适当的语言来自己突出显示

ruby syntax highlighting

8
推荐指数
1
解决办法
3509
查看次数

如何通过方法调用参数传递给proc?(红宝石)

proc = Proc.new do |name|
  puts "Thank you #{name}!"
end
def thank
  yield
end
Run Code Online (Sandbox Code Playgroud)
proc.call # output nothing, just fine
proc.call('God') # => Thank you God!

thank &proc # output nothing, too. Fine;
thank &proc('God') # Error!
thank &proc.call('God') # Error!
thank proc.call('God') # Error!
# So, what should I do if I have to pass the 'God' to the proc and use the 'thank' method at the same time ?
Run Code Online (Sandbox Code Playgroud)

谢谢 :)

ruby parameters block call proc-object

8
推荐指数
2
解决办法
1万
查看次数

git忽略.gitattributes模式

我有一个像这样的目录结构:

root/
  .git
  deploy/
  Site/
    blah/
    more_blah/
      something.local
      else.development
    Rakefile
    .gitattributes
Run Code Online (Sandbox Code Playgroud)

编辑:为了进一步说明上面的内容,目录有一个尾随,子目录/在目录下缩进,所以blah并且more_blah是目录但是Rakefile.gitattributes文件,但所有四个都是子目录Site.


我正在git-archive从这样的Site目录运行:

git archive --format=tar --prefix=git-v0.0.1/ v0.0.1 | gzip > ../deploy/git-v0.0.1.tar.zip
Run Code Online (Sandbox Code Playgroud)

但无论我放入.gitattributes的模式,生成的存档总是包含Rakefile.我试过了:

  • Rake文件
  • 网站/ Rake文件
  • */Rake文件
  • ./Rakefile
  • Rake文件*
  • *

它们都没有像我期望的那样工作.是否有人愿意指出明显但不明显的解决方案?任何帮助深表感谢.


我很抱歉不清楚.

  • 我说我使用的模式似乎不起作用,但我在模式后使用"export-ignore".
  • Rakefile 不是目录,只是一个文件
  • .gitattributes文件成功从存档中删除其他模式,Rakefile不是唯一使用的模式,但是唯一不起作用的模式.无论我是单独使用它还是使用其他模式,以及文件中的任何位置,它都不起作用.这不是真的,因为重命名某些文件但没有使用重命名归档提交我似乎得到了一些好的结果.我的错!:S

这是我.gitattributes(坐在目录中Site)

Rakefile        export-ignore
*.local         export-ignore
*.development   export-ignore
*.staging       export-ignore
Run Code Online (Sandbox Code Playgroud)

git gitattributes

8
推荐指数
2
解决办法
1万
查看次数

使用RSpec在块中包装的测试方法

在我简化的实际操作示例中,假设我有2次调用数据库:

Repo.add( something_stringy )
Repo.remove( something_floaty )
Run Code Online (Sandbox Code Playgroud)

我想使用模拟数据库调用,因为真正的调用将在别处测试:

let(:repo){
  repo = double("Repo")
  repo.should_receive(:add).with(instance_of(String))
  repo.should_receive(:remove).with(instance_of(Float))
  repo
}

before { FakeKlass.const_set :Repo, repo }
Run Code Online (Sandbox Code Playgroud)

这一切都很好,花花公子,但现在如果我在一个事务中包装调用我有点难过:

Repo.transaction do
  # ... some error checking in here somewhere...
  Repo.add( something_stringy )
  Repo.remove( something_floaty )
end
Run Code Online (Sandbox Code Playgroud)

因为如果我写一个接收transaction它的模拟将接收调用,但块中的所有内容都不会被调用,我得到:

预期:1次收到:0次

对于所有其他的嘲笑.有人能告诉我如何编写我的规范来处理这个问题吗?我已经尝试阅读RSpec书中的相关页面,around(:each)但这对我来说就像泥巴一样清晰.

任何帮助深表感谢.

ruby block mocking rspec2

8
推荐指数
1
解决办法
4333
查看次数

Ruby的包装和解包解释

甚至阅读标准文档后,我仍然无法理解如何Ruby的Array#packString#unpack准确的工作.这是导致我最麻烦的例子:

irb(main):001:0> chars = ["61","62","63"]
=> ["61", "62", "63"]
irb(main):002:0> chars.pack("H*")
=> "a"
irb(main):003:0> chars.pack("HHH")
=> "```"
Run Code Online (Sandbox Code Playgroud)

我希望这两个操作都返回相同的输出:"abc".他们每个人都以不同的方式"失败"(因为我可能期待错误的事情,所以不是真的失败).所以有两个问题:

  1. 这些产出背后的逻辑是什么?
  2. 如何实现我想要的效果,即将十六进制数字序列转换为相应的字符串.更好的是 - 给定一个整数n,如何将其转换为与文本文件相同的字符串,将其视为数字(例如,在十六进制编辑器中)等于n?

ruby pack

8
推荐指数
3
解决办法
1万
查看次数

使用Yardoc记录def_delegators

我有一个使用Forwardable模块中的def_delegators方法的类.我还没有办法让Yardoc为它输出文档.我尝试过使用但它不会为这些特定方法输出任何内容(文件中的其他内容都很好,并且没有错误),而且我有几个不同的长度.def_delegators

例如

class A
  extend Forwardable
  # other code…

  # @!macro
  #   @see Array#$1
  #   @see Array#$2
  #   @see Array#$3
  def_delegators :@xs, :size, :<<, :blah # …
Run Code Online (Sandbox Code Playgroud)

如果有人知道宝石或这样做的方式,这意味着我可以避免尝试写Yard扩展来做到这一点,我将非常感激.

ruby documentation yard

8
推荐指数
1
解决办法
621
查看次数

Nokogiri说Libxml2的版本高于2.9.0已被打破,是吗?

安装上的消息是这样说的,但我找不到任何引用."目前已知的被打破",但知道的人,什么问题呢?我检查了Nokogiri代码库并发布了日志,但我找不到对此的引用.

这里的消息(相关部分)Nokogiri(本例中为v1.6.3.1)给出:

IMPORTANT!  Nokogiri builds and uses a packaged version of libxml2.

If this is a concern for you and you want to use the system library
instead, abort this installation process and reinstall nokogiri as
follows:

    gem install nokogiri -- --use-system-libraries

If you are using Bundler, tell it to use the option:

    bundle config build.nokogiri --use-system-libraries
    bundle install

However, note that nokogiri does not necessarily support all versions
of libxml2.

For example, libxml2-2.9.0 …
Run Code Online (Sandbox Code Playgroud)

ruby libxml2 nokogiri

7
推荐指数
1
解决办法
1980
查看次数

如何使我的枚举器接口接受Feed?

来自Ruby v2.5文档

e = [1,2,3].map
p e.next           #=> 1
e.feed "a"
p e.next           #=> 2
e.feed "b"
p e.next           #=> 3
e.feed "c"
begin
  e.next
rescue StopIteration
  p $!.result      #=> ["a", "b", "c"]
end
Run Code Online (Sandbox Code Playgroud)

但是当我创建枚举时Enumerator.new呢?

# a naive rework of the above enum
e2 = Enumerator.new do |y|
  [1,2,3].each do |x|
    y << x
  end
  # raise StopIteration, FED # <= how to get `FED`?
end

p e2.next           #=> 1
e2.feed "a"
p e2.next           #=> …
Run Code Online (Sandbox Code Playgroud)

ruby

7
推荐指数
1
解决办法
133
查看次数