1
0
mirror of https://github.com/meineerde/rackstash.git synced 2026-03-02 15:22:01 +00:00

60 Commits

Author SHA1 Message Date
dab393ee21 Disable moneky patching with RSpec 2018-02-15 16:03:13 +01:00
dda72c2f84 Work around deprecations on Ruby 2.5.0 2018-01-24 20:18:50 +01:00
99d2f489dd Update Copyright year 2018-01-24 00:21:04 +01:00
c194b00b34 Improve code formatting and fix Rubocop issues 2018-01-23 23:21:58 +01:00
9ed350cb8d Allow fields to hold force-inspected BasicObjects 2017-12-21 01:19:10 +01:00
1671b04dfb Add Fields::Hash#each and make the Hash class an Enumerable 2017-12-12 19:58:46 +01:00
e472b7fbce Add Fields::Hash#length to emulate Hash#length 2017-12-12 19:29:28 +01:00
d382a245f3 Add Fields::Hash#fetch to emulate Hash#fetch 2017-12-12 19:26:44 +01:00
8db2c917c2 Fix a couple of Rubocop warnings
All of these changes are either simple formatting changes or clarify
existing meaning. None of these changes affects externally visible
behavior.
2017-10-20 19:51:11 +02:00
2d0f47a813 Do not rescue exceptions on Proc normalization
Rescuing exceptions here would mask errors and make debugging realy hard
when setting e.g. default fields.
2017-10-08 21:35:51 +02:00
e7fd3677ca Ensure more consistent code formatting with Rubocop 2017-10-03 22:52:49 +02:00
59c94a8ecc Insert newline comment below magic comments in ruby file header 2017-09-29 17:15:07 +02:00
2f0755c967 Optionally retain scope when evaluating procs in collections
This allows to receive the scope as the argument to a proc-value instead
of always executing the proc in the scope's context.
2017-09-21 22:30:52 +02:00
fa174bba9d Freeze the raw object along the wrapper for all fields 2017-08-15 18:36:33 +02:00
10993d2b1a Serialize Rational numbers to a String
With this, we are more compatible with the common JSON encoders,
including the one on RUby core.
2017-08-14 14:10:48 +02:00
168e62b63c Remove useless newlines 2017-08-12 14:02:03 +02:00
eab3d16ec5 Fix minor code formatting issues 2017-08-05 23:53:01 +02:00
697641635b Don't use Concurrent::{Hash|Array} objects in Fields
Since the fields are (through the thread-local BufferStack) only ever
accessed from a single Thread, there is no need to accept the additional
locking overhead of the Concurrent raw values.

We can just use simple Hashes and Arrays here for higher performance.
2017-08-03 21:09:50 +02:00
be6e3517de Increase sub-second precision of timestamps to 6 decimal places 2017-07-25 23:32:14 +02:00
67955f8629 Add force parameter to Rackstash::Fields::Hash#set so it works like #merge! 2017-07-20 22:11:11 +02:00
d73b7ba8e1 Extract utf8_encode helper into Rackstash::Helpers::UTF8 module 2017-07-20 14:12:05 +02:00
ca339a84fa Replace specific class-under-test with described_class in all specs 2017-07-19 12:55:29 +02:00
b6768c6547 Test all conditions of Rackstash::Fields::Hash() 2017-07-19 12:02:21 +02:00
2ff1e1e5dc Ensure Rackstash::Fields::Tags.merge! accepts nested procs 2017-07-18 23:33:48 +02:00
a4a6b248cf Use frozen string literals throughout the codebase in Ruby >= 2.3 2017-07-17 13:35:24 +02:00
ba61940a95 Improve code formatting 2017-07-15 14:30:07 +02:00
9f2a330a6c Support arbitrarily nested Procs when setting/merging fields 2017-07-15 11:13:41 +02:00
ee429fa71e Add Rackstash::Fields::Array#shift and #unshift 2017-07-11 23:42:13 +02:00
a461b36b97 Allow to query and replace subarrays of Rackstash::Fields::Array 2017-07-11 23:42:13 +02:00
da1999dba3 Unify the conflict resolution behavior of merge! and deep_merge! in Rackstash::Fields::Hash
When setting `force: true` (the default), in both cases we not raise an
ArgumentError when setting a forbidden field and overwrite existing
fields. When setting it to `false`, we ignore forbidden or existing
fields in both cases.

We also allow a custom conflict resolution block to be passed to both
methods. In the case of deep_merge! and deep_merge, this applies to all
(potentially deeply nested) fields. Compatible objects, i.e. Hashes and
Arrays are still always merged without calling the block.
2017-07-11 22:23:19 +02:00
4eecc559a4 Transform list of forbidden_keys in Rackstash::Fields::Hash.new to a frozen Set
We then expose this frozen Set on the `forbidden_keys` attribute.
2017-06-30 19:27:46 +02:00
d26858c103 Add Rackstash::Fields::Array#size as an alias to length 2017-06-22 23:00:51 +02:00
32b3ef8e0e Add Rackstash::Fields::Array#pop
This method does exactly the same as `::Array#pop`
2017-06-21 01:38:11 +02:00
649de80698 Allow multiple arguments to Rackstash::Fields::Array#push
We now also support the new alias to `Array#push` called `append` which
will be added to the core `Array` with Ruby 2.5.
2017-06-21 01:38:11 +02:00
6eccf6cc37 Don't copy or alter frozen UTF-8 strings in fields
With this, we optimize the common case where we do have valid UTF-8
strings to begin with. If the given String is already frozen, as is
common for e.g. Hash keys, we don't even need to create a new object.

With this change, we also always return frozen strings from
`Rackstash::Fields::AbstractCollection#utf9_encode`. This avoids an
unecessary object copy when inserting it in a Hash and still ensures
that values are always frozen anyway.
2017-06-21 01:38:11 +02:00
da3113e880 Avoid Array instances when normalizing Arrays / Hashes
`each_with_object` allocates an array for each kv pair. Switching to
the slightly more verbose but less allocatey `each_pair` eliminates
array allocations.

This follows the similar change in Rails:
960de47f0e
2017-05-23 13:27:22 +02:00
d9c7a2ad33 Add Fields::Array#push as an alias to #<< 2017-04-06 23:09:22 +02:00
bfa5e33c04 Add Fields::Hash#reverse_merge and reverse_merge! similar to the ActiveSupport methods on Hash 2017-03-07 16:45:47 +01:00
22d1cdb646 Add Rackstash::Fields::Hash#deep_merge! and deep_merge
These methods are useful convenience methods to add (nested) fields to a
hash while optionally retaining existing values. Usually, `#deep_merge!`
or `#set` will be the commonly used ways to set fields to a hash.
2017-02-18 22:36:21 +01:00
4a185096d6 Add Rackstash::Fields::Hash#key? predicate 2017-02-18 01:15:49 +01:00
e13efe5ed3 Add consistent hash method to Rackstash::Fields::AbstractCollection
This follows the rule that two objects which are eql? also have the same
hash value. It is also required to ensure that we can use collections in
sets, hashes and arrays where the hash-equality is checked for certain
operations.
2017-02-17 19:12:47 +01:00
0339d4bced Test Rackstssh::Fields::AbstractCollection#clone 2017-02-16 23:08:42 +01:00
6958b8f509 Add Rubocop config and resolve most style issues 2017-02-16 22:47:17 +01:00
2cff0cb5fa Improve code formatting 2017-02-16 20:54:11 +01:00
057cf2c8f7 Add Rackstash::Fields::Array#merge and #merge! which work similar to the union operator 2017-02-16 20:50:38 +01:00
890b193234 Add basic array operations to Rackstash::Fields::Array 2017-02-16 01:14:20 +01:00
c401a29ab3 Allow to specify a custom scope in Rackstash::Fields::Array#concat 2017-02-16 00:41:40 +01:00
8232d139f4 Add specs for handling of nested procs inside arrays with fields 2017-02-16 00:39:08 +01:00
bd376af884 Use thread-safe raw objects for field hashes and arrays 2017-02-14 22:47:55 +01:00
3ec21e7646 Always resolve procs when setting them into fields 2017-02-13 23:37:02 +01:00