Class: Mongokit::Options
- Inherits:
-
Object
- Object
- Mongokit::Options
- Defined in:
- lib/mongokit/utils/options.rb
Defined Under Namespace
Modules: Store
Constant Summary collapse
- CRITERIAS =
[:only, :except, :add, :replace]
Class Method Summary collapse
- .add(fields, options) ⇒ Object
- .except(fields, options) ⇒ Object
- .only(fields, options) ⇒ Object
- .process(fields, options, criterias = nil) ⇒ Object
- .replace(fields, options) ⇒ Object
Instance Method Summary collapse
- #all ⇒ Object
- #get(name, field = nil) ⇒ Object
-
#initialize(options = {}) ⇒ Options
constructor
A new instance of Options.
- #put(name, values) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Options
Returns a new instance of Options.
6 7 8 |
# File 'lib/mongokit/utils/options.rb', line 6 def initialize( = {}) @options = end |
Class Method Details
.add(fields, options) ⇒ Object
33 34 35 36 37 |
# File 'lib/mongokit/utils/options.rb', line 33 def add(fields, ) return unless [:add] fields.is_a?(Hash) ? fields.merge([:add]) : fields.concat([:add]) end |
.except(fields, options) ⇒ Object
28 29 30 31 |
# File 'lib/mongokit/utils/options.rb', line 28 def except(fields, ) fields = fields.reject{ |f, _| [:except].include?(f) } if [:except] fields end |
.only(fields, options) ⇒ Object
23 24 25 26 |
# File 'lib/mongokit/utils/options.rb', line 23 def only(fields, ) fields = fields.select{ |f, _| [:only].include?(f) } if [:only] fields end |
.process(fields, options, criterias = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/mongokit/utils/options.rb', line 44 def process(fields, , criterias = nil) criterias = .keys unless criterias criterias.each do |c| fields = send(c, fields, ) if CRITERIAS.include?(c) end fields end |
.replace(fields, options) ⇒ Object
39 40 41 42 |
# File 'lib/mongokit/utils/options.rb', line 39 def replace(fields, ) [:replace].each { |old_f, new_f| fields[new_f] = fields.delete(old_f) } if [:replace] fields end |
Instance Method Details
#all ⇒ Object
10 11 12 |
# File 'lib/mongokit/utils/options.rb', line 10 def all @options end |
#get(name, field = nil) ⇒ Object
18 19 20 |
# File 'lib/mongokit/utils/options.rb', line 18 def get(name, field = nil) field ? @options[name][field] : @options[name] end |
#put(name, values) ⇒ Object
14 15 16 |
# File 'lib/mongokit/utils/options.rb', line 14 def put(name, values) @options[name] = values end |