summaryrefslogtreecommitdiff
path: root/lib/chef/node/attribute.rb
Commit message (Collapse)AuthorAgeFilesLines
* Convert require to require_relativeLamont Granquist2019-05-081-8/+8
| | | | | | | This gives a speed boost since rubygems does not have to scan through every gem in the gemset in order to find the file. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* fix commentsLamont Granquist2018-11-091-4/+4
| | | | Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* Chef-15: add nillability to attribute deep mergingLamont Granquist2018-11-091-8/+10
| | | | | | | | | | Changes to consistently uses the "NIL" object internally to mean "not present" instead of abusing nil for that purpose. So now "nil means nil" and we can deep merge that so it will effectively override lower precedence levels if you write a nil. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* fix whitespace in node attributes [ci skip]Lamont Granquist2018-11-071-185/+189
| | | | Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* Node Attributes: Build ImmutableMash properly in deep_merge!lcg/deep-merge-cache-fixLamont Granquist2018-10-151-4/+4
| | | | | | | | | | | | | | | | | | | | | | | closes #7738 The root cause here is that there's a difference between doing Chef::Node::VividMash.new( <another VividMash> ) And: Chef::Node::ImmutableMash.new( <a VividMash> ) The former short circuits and does no work in convert_value. The latter will not short circuit and does the proper work to dup and convert the value argument. Since we build an ImmutableMash now, we do not need to wrap it with the extra immutablize() call. This should be perf neutral or very, very slightly better perf. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* fix Style/MutableConstantLamont Granquist2018-07-021-2/+2
| | | | Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* fix Style/PreferredHashMethodsLamont Granquist2018-07-021-4/+4
| | | | | | | absolutely hard requirement on the fixes that went into chef-config 2.2.11, so the floor of that gem is bumped up. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* Revert "Per-container deep merge caching"lcg/revert-lazy-attributesLamont Granquist2018-02-231-48/+70
| | | | This reverts commit 0c29acc106ca774e230c8ef45694c8bffd166b69.
* Revert "remove comments + debugging"Lamont Granquist2018-02-231-0/+2
| | | | This reverts commit 9fe57c38a57135c7bd29ff05a1c7839a4d30c38c.
* Chef-14 Breaking: remove node.set and node.set_unlesslcg/remove-node-setLamont Granquist2018-01-221-6/+1
| | | | | | been deprecated since late-12. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* remove comments + debuggingLamont Granquist2017-12-061-2/+0
| | | | Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* Per-container deep merge cachingLamont Granquist2017-12-061-70/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Replaces the one-big top level deep merge cache with individual deep merge caches in every container. The Immutable container state becomes the deep merge cache. - Does not use a pure decorator style approach since that failed before because of ruby internals breaking things like `===` and `=~` on decorated objects, so we inherit (ultimately from Hash + Array). - The state being the container state is useful in ruby since APIs on Hash and Array poke around in internal state to make things fast. If we inherit from Hash/Array but don't have the correct internal state things go wonky. - Throwing away the internal state is equivalent to flushing the cache. - Since we throw away all linked objects when we do that, we flush at every level below the level being flushed (which is correct semantics). - If a user has a pointer to an old immutable object from a sub-level, that isn't mutated so the old object still contains the old view of the data (which I think is correct, although I have some doubts that its necessary, but it came along free for the ride). - When we reset the cache we do mutate the cache being reset, which might change data in held references. If this becomes an issue the fix would be to reset the cache at the level above by creating a new, "empty" ImmutableHash/ImmutableArray object and inserting it into the deep_merge_cache datastructure instead of clearing the internal state of the child object. I don't know practically how anyone would hit this, though, so would prefer to wait on doing that work until we see an actual bug report. - Because of the way ruby pokes around internally there's some weirdnesses like the pre-generation of the cache for all the values of a subarray when #each is called, which is due to the way that ruby walks through array-serialized hashes when called like: `Array#each { key, value| ... }` (which is an undocumented(?) thing in ruby). Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* immutablize on the fly and reduce dupinglcg/deep-merge-immutablizingLamont Granquist2017-08-311-10/+80
| | | | Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* node attributes: remove useless dup in merge_alllcg/remove-useless-dupLamont Granquist2017-08-281-4/+0
| | | | | | | | | since immutablize now does dup + freeze of everything this is definitively unnecessary, and appears to have been unnecessary even in Chef-12 (at last does not break any specs there either). Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* fix node#debug_value access through arrayslcg/debub-value-arraysLamont Granquist2017-03-161-8/+4
| | | | | | nod to @jaymzh for finding this one. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* Chef-13: remove method_missing access to node object.Lamont Granquist2017-03-131-20/+1
| | | | | | | | | | | | | | | | | | | | So again the reasons why we break this: - node.class vs. node['class'] kinds of problems - adding node#foo to Chef::Node as an extension to the API and breaking node.foo meaning node["foo"] (we can't make exensions to that class without possibly breaking someone) - crazy things like the old CHEF-3799 issue in the old ticketing system where IO#puts in ruby blindly calls #to_ary on stuff and expects it to raise -- whereas we would potentially autovivify a 'to_ary' hash key and return nil which breaks the world. This also has caused issues with the hashie gem and they've gone to spamming warnings by default to try to deal with it: https://github.com/berkshelf/berkshelf/issues/1665 Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* fix specs: RedundantReturn, RedundantSelf, RedundantBeginLamont Granquist2017-02-131-4/+4
| | | | | | department of redundancy department Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* fix comment [ci skip]Lamont Granquist2017-01-111-1/+1
| | | | Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* fix node attribute "unless" API methodsLamont Granquist2017-01-111-6/+5
| | | | | | | | | | closes #5556 corrects behavior to 12.11.x behavior which was lost in the refactor may address #5715 Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* Structure deprecations with additional metadatatm/deprecation_with_urlThom May2016-11-161-3/+3
| | | | | | | | This adds URLs to each class of deprecation, and correctly prints and formats them for maximum user efficiency. We also provide the URL to the data collector for Visibility to ingest. Signed-off-by: Thom May <thom@chef.io>
* Remove debug writeAdam Ward2016-11-161-1/+0
| | | | | | | Obvious fix. Introduced in: e57e29b96b75ff7fc04abb7f9db73920b2a5894a Signed-off-by: Adam Ward <adamw@subdesigns.net>
* add attribute_changed hook to event handlersLamont Granquist2016-10-281-23/+25
| | | | Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* rename __path to __path__ and __node to __node__lcg/node-path-trackingLamont Granquist2016-10-251-1/+1
| | | | | | | | | | | | consistency with Unchain here: https://github.com/chef/chef/blob/master/lib/chef/decorator/unchain.rb#L23-L24 and with SimpleDelegator: https://ruby-doc.org/stdlib-2.1.0/libdoc/delegate/rdoc/SimpleDelegator.html#method-i-__getobj__ Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* standardize initializer args for VividMash+ImmutableMashLamont Granquist2016-10-251-20/+20
| | | | | | | | | | | | | | | | | | | if anyone is using these directly this might be a breaking change, although it makes it considerably easier to use VividMash and IMO ImmutableMash is an implementation detail of the deep merge cache and Chef::Node object. we definitely have never documented these APIs, so I think the onus is on the consumer to update their code. VividMash.new() should now work. VividMash.new({ foo: :bar }) should also now work. IDK what object people would have been passing in as the root object before. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* green testsLamont Granquist2016-10-251-1/+1
| | | | Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* savegame for more aggressive refactoringLamont Granquist2016-10-251-1/+1
| | | | Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* add a deep_merge_cache mixinLamont Granquist2016-10-251-83/+45
| | | | | | gets the inheritence chain correct Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* s/path_tracking/state_tracking and add __root stateLamont Granquist2016-10-251-3/+3
| | | | Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* add code to implement node path trackingLamont Granquist2016-10-251-0/+8
| | | | | | | | | | via node.__path variable using __underscore format because node["path"] could very well be used and we still have to deal with node.path method_missing horribleness. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* Convert attributes defined as literal arraysGiacomo Bagnoli2016-09-211-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | VividMash, unlike Mash, does not recursively convert values inside arrays, just the array itself. As such, hashes inside arrays are not converted to *Mash, introducing a behaviour that differs from Chef 11, e.g. having this attr defined node['foo'] = [ { 'attr' => 'value' } ] in Chef 11 `node[:foo][0][:attr]` returns `'value'` while in Chef 12 it returns `nil` This commit fixes VividMash so arrays are recursively converted and the behaviour restored. Plus, immutablize merge_all result, so to be sure that hashes contained in Arrays are properly immutablized as well, so not existing attributes are not automatically vivified (thus returning an empty VividMash instead of nil) This problem was first reported in chef/chef#2871. Signed-off-by: Giacomo Bagnoli <gbagnoli@gmail.com>
* fix Style/BlockDelimiters, Style/MultilineBlockLayout and 0.42.0 engine upgradeLamont Granquist2016-08-171-2/+2
| | | | Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* autofixing Style/AccessModifierIndentation copLamont Granquist2016-08-161-1/+1
|
* fix stray double quoteslcg/fix-5012Lamont Granquist2016-07-111-2/+2
|
* Attributes v1.1 changeslcg/attributes-v1.1Lamont Granquist2016-06-271-70/+123
| | | | | | | | | | | - fixes *_unless behavior and set_unless_value_present hack from Chef 12 - simplifies rm_* code - introduces functional read/write/unlink/exist? API - deprecates method_missing access to attributes for Chef 13 - deprecates set/set_unless aliases for Chef 14 - removes MultiMash mess that I wrote for Chef 13 https://github.com/chef/chef/pull/5029 for more details
* autofixing some missed copsLamont Granquist2016-02-051-1/+1
| | | | second round of autofixing for some reason...
* autofixing whitespace copsLamont Granquist2016-02-051-279/+279
| | | | | | | | | | | | | | | | | | | | | | 4174 Style/SpaceInsideHashLiteralBraces 1860 Style/SpaceAroundOperators 1336 Style/SpaceInsideBlockBraces 1292 Style/AlignHash 997 Style/SpaceAfterComma 860 Style/SpaceAroundEqualsInParameterDefault 310 Style/EmptyLines 294 Style/IndentationConsistency 267 Style/TrailingWhitespace 238 Style/ExtraSpacing 212 Style/SpaceBeforeBlockBraces 166 Style/MultilineOperationIndentation 144 Style/TrailingBlankLines 120 Style/EmptyLineBetweenDefs 101 Style/IndentationWidth 82 Style/SpaceAroundBlockParameters 40 Style/EmptyLinesAroundMethodBody 29 Style/EmptyLinesAroundAccessModifier 1 Style/RescueEnsureAlignment
* Update all auth email address from opscode.com and getchef.com to chef.io.Noah Kantrowitz2016-02-021-2/+2
| | | Generated via git ls-files | xargs perl -pi -e "s/(Author.*?<[^@]+@)(?:opscode\\.com|getchef\\.com)(>)/\\1chef.io\\2/gi"
* Copyright year update for 2016 and massive cleanup.Noah Kantrowitz2016-02-021-1/+1
| | | Generated via git ls-files | xargs perl -pi -e "s/[Cc]opyright (?:\([Cc]\) )?((?\!$(date +%Y))\\d{4})(-\\d{4})?([, ][ \d]+)*(,|(?= ))/Copyright \\1-$(date +%Y),/g"
* Use double quotes by defaultThom May2016-01-141-5/+5
| | | | | | | This is an entirely mechanically generated (chefstyle -a) change, to go along with chef/chefstyle#5 . We should pick something and use it consistently, and my opinion is that double quotes are the appropriate thing.
* autocorrecting Style/TrailingCommalcg/trailing_commaLamont Granquist2016-01-131-3/+3
| | | | chefstyle -a fixed 1044 occurrances
* tags always an array; fix set_unlessLamont Granquist2015-12-141-1/+1
| | | | | | | previously if the node had a { normal: { tags: nil } } that we read since the key existed (but was nil) we would not initialize with an array. replacing the code with a call to node.set_unless revealed that set_unless was similarly buggy. fixed both issues by fixing set_unless.
* Completing tests for https://github.com/chef/chef/pull/2310, fixes ↵tball/complete-2310tyler-ball2015-02-111-0/+4
| | | | https://github.com/chef/chef/issues/1562
* Use #define_method instead of #class_eval (ruby 1.8 specific, issue #2497)Xabier de Zuazo2015-01-271-5/+3
|
* deep_merge_cache fixes for bugs in 12.0.0Lamont Granquist2015-01-141-4/+4
| | | | | | | | In 12.0.0 we introduced a cache for the merged attributes for the top-level node attribute keys. This fixes this so that node['foo'] and node[:foo] are not cached separately. This also showed up in bugs as issues between node['foo'] access and node.foo access because node.foo is translated into node[:foo].
* WIP: immutabilizing deep mergelcg/remove-knockout-mergeLamont Granquist2014-11-211-1/+3
|
* deleted the last end accidentallyLamont Granquist2014-11-211-2/+4
|
* add more commentaryLamont Granquist2014-11-211-4/+20
|
* add partial deep merge cacheLamont Granquist2014-11-211-1/+48
|
* revert to serdar's deep_merge de-dup versionLamont Granquist2014-11-191-4/+16
|
* fix ImmutableAttributeModification exceptionLamont Granquist2014-11-191-1/+1
|