-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add hash-bashed sub-document finder; add support for add_conditions t…
…o Array; update README for latest features
- Loading branch information
Showing
5 changed files
with
81 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# AWEXOME | ||
# MissingHash - a Hash reimplementation with direct-access to top-level keys | ||
|
||
module Awexome | ||
module Util | ||
|
||
module MissingHash | ||
def method_missing(method, *args) | ||
unless method.to_s.scan(/=$/).empty? | ||
return self[method.to_s.gsub(/=$/,"").to_sym] = args.shift | ||
else | ||
return self[method] if self.keys.include?(method) | ||
end | ||
super(method, *args) | ||
end | ||
end # MissingHash | ||
|
||
|
||
module CondArray | ||
def add_condition(cond, conj="AND") | ||
if cond.is_a?(Array) | ||
if self.empty? | ||
(self << cond).flatten! | ||
else | ||
self[0] += " #{conj} #{cond.shift}" | ||
(self << cond).flatten! | ||
end | ||
elsif cond.is_a?(String) | ||
self[0] += " #{conj} #{cond}" | ||
else | ||
raise "Condition must be an Array or String" | ||
end | ||
self | ||
end | ||
end | ||
|
||
end # Util | ||
end # Awexome | ||
|