草庐IT

chef-attributes

全部标签

ruby - Chef : cannot load such file -- moneta/basic_file

我正在运行一个我以前使用过无数次的Recipe,当我用chef+knife启动一个新的EC2实例时,我遇到了这些错误。[2013-01-30T23:44:48+00:00]INFO:Processinguser[dan]actioncreate(/var/chef/cache/cookbooks/users/providers/manage.rbline65)[2013-01-30T23:44:48+00:00]INFO:user[dan]created[2013-01-30T23:44:48+00:00]INFO:Processingdirectory[/home/dan/.ssh]

ruby : how to prevent modification of an array instance variable through an attribute reader

抱歉这个菜鸟问题...假设我们有:classTestMeattr_reader:arraydefinitialize@array=(1..10).to_aend结束然后可以这样做:>>a=TestMe.new=>#>>a.array.map!&:to_s=>["1","2","3","4","5","6","7","8","9","10"]>>a.array=>["1","2","3","4","5","6","7","8","9","10"]这显然不利于封装,不是吗?有什么方法可以快速保护数组变量不被更改吗?...或者每当我的实例变量具有“破坏性”方法时,我是否需要实现一个深拷贝读取

ruby-on-rails - Ruby on Rails : How to validate nested attributes on certain condition?

我有这些模型:classOrganisation:addressable,:dependent=>:destroyaccepts_nested_attributes_for:address,:allow_destroy=>trueendclassPerson:addressable,:dependent=>:destroyaccepts_nested_attributes_for:address,:allow_destroy=>true#Thesetwomethodsseemtohavenoeffectatall!validates_presence_of:organisation,:

ruby - 检查 Chef 中是否存在嵌套属性的正确方法是什么?

有多种方法可以检查Chef中是否存在嵌套属性,我不确定哪种方法是正确的/最好的,如果有的话会导致空属性存储在节点上:node[:parent]andnode[:parent][:child]node.attribute?(:parent)andnode[:parent].attribute?(:child))node[:parent].nil?andnode[:parent][:child].nil?如果能够同时检查父项和子项会更好,但我不知道这是否可能。我使用的是Chef10,而不是Chef11,但欢迎回答解释这两个问题。 最佳答案

ruby-on-rails - Rails 4 强参数 : can I 'exclude' /blacklist attributes instead of permit/whitelist?

我正在将Rails3应用程序迁移到Rails4,并且正在将attr_accessible属性转换为Controller中的强参数。APIDocumentation显示如何“允许”属性:defperson_paramsparams.require(:person).permit(:name,:age)end然而,我的绝大多数属性都是批量分配安全的。我只需要将:account_id和:is_admin等几个属性列入黑名单。是否可以将属性列入黑名单而不是将几乎所有属性列入白名单?例如:defuser_paramsparams.require(:user).exclude(:account_i

ruby-on-rails - 错误 : When assigning attributes, 您必须将散列作为参数传递

嗨,我刚开始使用ruby​​,我正在编写Controller和Controller规范,但我遇到了一些问题。文档.rbclassDocument文档Controller.rbclassAPI::DocumentsControllerdocuments_controller_spec.rbdescribe"POST'index'"dobefore{@attr=FactoryGirl.attributes_for(:document)}describe"failure"dodescribe"withmissingparameters"dobefore{@attr.each{|key,val

ruby-on-rails - Rails,activerecord : self[:attribute] vs self. 属性

在Rails中访问事件记录列/属性时,使用self[:attribute]与self.attribute有什么区别?这会影响getter和setter吗? 最佳答案 它们都只是获取属性的方法-它们都只是getter。self.attribtue是一个更“传统”的getter,而self[:attribute]基本上只是[]方法。在使用两者之间切换不会产生任何影响。我建议只使用self.attribute方法,因为它在语法上更好。但是,当其他内容覆盖self.attribute方法时,使用self[:attribute]会派上用场。例

ruby - 如何在 Chef-repo 中跨 Chef Recipe 共享代码?

我想在ChefRepo中分享一些跨Recipe的方法。我知道在Recipe级别上,我可以将代码放入库目录中的模块中(参见relatedquestion)。我正在寻找的是类似的东西,但在我的Chef存储库中的所有Recipe中都可以找到。我可以想到几个解决方案:创建一个gem,将gem安装为chef运行的一部分。这似乎有点矫枉过正。将文件放在某个文件夹中,然后将该文件夹添加到配方文件中的$LOAD_PATH中。我感觉这不适用于实际部署,因为Chef服务器对repo一无所知。将文件放在某个文件夹中,并将其符号链接(symboliclink)到每本Recipe的库目录中。最后一个选项似乎是最

ruby - 如何将 linux 命令输出到 chef 属性

我想将命令输出到chef属性中。有人可以帮助我如何在执行资源或bash资源中设置它。ruby_block"something"doblockdo#trickywaytoloadthisChef::Mixin::ShellOututilitiesChef::Resource::RubyBlock.send(:include,Chef::Mixin::ShellOut)command='cat#{fileName}'command_out=shell_out(command)node.set['my_attribute']=command_out.stdoutendaction:creat

ruby-on-rails - Elasticsearch /轮胎 : How do I filter a boolean attribute?

我想过滤我类(class)的私有(private)bool值,以便它只显示非私有(private)但对我不起作用的资源。(我大大简化了代码)mappingdoindexes:private,type:"boolean"indexes:name,type:"string"endenddefself.search(params)tire.search(load:true,page:params[:page],per_page:20)doquery{stringparams[:query]}ifparams[:query].present?#SofarI'vetried...#filter: