hash_conditions 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGY2YzgxMmQ0ZTIzOTIyOGM1NGI0MDlkOGI4ZjIyNDQ2NmY5ZTFlZQ==
4
+ YTIwY2E0OGRlZGU5NzE1YTI2MmFjZDI1OGMxZTFlZDhmOTYzZTExOA==
5
5
  data.tar.gz: !binary |-
6
- OTE5ZTk3M2VjMjhmODIwNjJlNGQ1ZDZkYWU0M2IzMWYwMTMwYzUyMg==
6
+ NmU2NDQ4M2E3ZmFlNGRkNDZiMjdmNzgyZTYwNzE4ODMxNjM2ODRkMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OWU3YWQxNDZiMzI5Yjk1ODg4NWM5N2EzODQwYjM1OTRkZTBkY2YzMzY2ZTc3
10
- OTAxMzFiZTRhMzU4ZmNhYzUzZmUxYzJiODhmZDg0NzYxMTQ5Y2MzZTk5NTUx
11
- MTdlOGFmZjRjNjkwNWUwOGVhODVlODAyODA5YTdmMTMxNWJlZWQ=
9
+ ZDQxNWRkOTNiNTNkZDFkMzZhNzIwZTkyYjI3YWZhNzE3NTA1OTUyMDZkOTk4
10
+ ZjQ0Zjc2NTI5YjRkMGY2Zjk5MjQyNjdjNmMwYzFlOTg4NzhmODg4NDJhZDJi
11
+ ZjRjZWM2NjJlYTkzMzc2NDE4NDlkNDQ1N2I4MGM3YmQwYjdkOGY=
12
12
  data.tar.gz: !binary |-
13
- MjUxMTY0NzcxNjkzNTFkOGIwZDA0OGMyMzA4MmM2NmE4ZTJkZDRmNThhOTBk
14
- ODRjNWU1NmMxODQwYWM2NTI3ODI1MjkxMTdhNzJjMDYxMzcyNTg5NWZmMDJi
15
- ZTcxNTM2MjI3ZGExY2MwZTUxNDA4MDJkNGJmYzM3OWY4NTI4YjE=
13
+ N2NmMWE0YjdjNTYwZGMxYTU0ZDBhY2E1OGZhOTRhNjY4YmZkMTQ1MTZiNDRk
14
+ NjgxZmEwYjhiNDA3OTFlODFkZmI1MjFiMWZjNDVjMmMyNmE3YWJmOWZiMjU1
15
+ ZTVmMWJkNjZhMDUyMWEzMjdlOTRjMmMzNGM4YWZlMmNmYmE3MWU=
@@ -1,4 +1,8 @@
1
1
  module HashConditions
2
+ class KeyNotFound < Exception; end
3
+ class UnexpectedExpression < Exception; end
4
+ class InvalidExpression < Exception; end
5
+
2
6
  module Core
3
7
  # Modular Matchers
4
8
  DEBUG=false
@@ -143,6 +147,19 @@ module HashConditions
143
147
  end
144
148
  end
145
149
 
150
+ def get_key hash, key
151
+ if hash.has_key? key
152
+ hash[ key ]
153
+ else
154
+ key_type = key.class
155
+ key.to_s.split('.').inject(hash) do |ret, k|
156
+ typed_key = key_type == Symbol ? k.to_sym : k
157
+ raise KeyNotFound, "key #{key} not found" unless ret.has_key? typed_key
158
+ ret = ret[ typed_key ]
159
+ end
160
+ end
161
+ end
162
+
146
163
  def eval_operand hash, key, options = {}
147
164
  __get_values = lambda do | values |
148
165
  values.map{ |x| eval_operand hash, x, options }
@@ -152,7 +169,7 @@ module HashConditions
152
169
  if key.to_s == '$now'
153
170
  options[:current_time] || Time.now
154
171
  else
155
- val = options[:is_key] ? hash[key] : key
172
+ val = options[:is_key] ? get_key( hash, key ) : key
156
173
  re_type val
157
174
  end
158
175
  when Array
@@ -1,3 +1,3 @@
1
1
  module HashConditions
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_conditions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giancarlo Palavicini