Class: Dao::Params
- Inherits:
-
Map
- Object
- Map
- Dao::Params
- Includes:
- Validations::Mixin
- Defined in:
- lib/dao/params.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#form ⇒ Object
Returns the value of attribute form.
-
#path ⇒ Object
Returns the value of attribute path.
-
#result ⇒ Object
instance methods.
-
#route ⇒ Object
Returns the value of attribute route.
-
#status ⇒ Object
Returns the value of attribute status.
-
#validations ⇒ Object
Returns the value of attribute validations.
Class Method Summary collapse
- .keys_for(keys) ⇒ Object
- .parse(prefix, params = {}, options = {}) ⇒ Object
- .process(path, params, options = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(*args, &block) ⇒ Params
constructor
A new instance of Params.
-
#inspect ⇒ Object
look good for inspect.
- #update(*args, &block) ⇒ Object
Methods included from Validations::Mixin
Constructor Details
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
73 74 75 |
# File 'lib/dao/params.rb', line 73 def errors @errors end |
#form ⇒ Object
Returns the value of attribute form.
75 76 77 |
# File 'lib/dao/params.rb', line 75 def form @form end |
#path ⇒ Object
Returns the value of attribute path.
71 72 73 |
# File 'lib/dao/params.rb', line 71 def path @path end |
#result ⇒ Object
instance methods
69 70 71 |
# File 'lib/dao/params.rb', line 69 def result @result end |
#route ⇒ Object
Returns the value of attribute route.
70 71 72 |
# File 'lib/dao/params.rb', line 70 def route @route end |
#status ⇒ Object
Returns the value of attribute status.
72 73 74 |
# File 'lib/dao/params.rb', line 72 def status @status end |
#validations ⇒ Object
Returns the value of attribute validations.
74 75 76 |
# File 'lib/dao/params.rb', line 74 def validations @validations end |
Class Method Details
.keys_for(keys) ⇒ Object
53 54 55 |
# File 'lib/dao/params.rb', line 53 def keys_for(keys) keys.strip.split(%r/\s*,\s*/).map{|key| key =~ %r/^\d+$/ ? Integer(key) : key} end |
.parse(prefix, params = {}, options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/dao/params.rb', line 10 def parse(prefix, params = {}, = {}) prefix = prefix.to_s params = Map.new(params || {}) base = Map.new(params || {}) = Map.( || {}) parsed = Params.new parsed.update(params[prefix]) if params.has_key?(prefix) re = %r/^ #{ Regexp.escape(prefix) } (?: [(] ([^)]+) [)] )? $/x params.each do |key, value| next unless(key.is_a?(String) or key.is_a?(Symbol)) key = key.to_s matched, keys = re.match(key).to_a next unless matched next unless keys keys = keys_for(keys) parsed.set(keys => value) base.delete(key) end whitelist = Set.new( [.getopt([:include, :select, :only])].flatten.compact.map{|k| k.to_s} ) blacklist = Set.new( [.getopt([:exclude, :reject, :except])].flatten.compact.map{|k| k.to_s} ) unless blacklist.empty? base.keys.dup.each do |key| base.delete(key) if blacklist.include?(key.to_s) end end unless whitelist.empty? base.keys.dup.each do |key| base.delete(key) unless whitelist.include?(key.to_s) end end if .getopt(:fold, default=true) parsed_and_folded = base.merge(parsed) else parsed end end |
Instance Method Details
#inspect ⇒ Object
look good for inspect
88 89 90 |
# File 'lib/dao/params.rb', line 88 def inspect ::JSON.pretty_generate(self, :max_nesting => 0) end |
#update(*args, &block) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/dao/params.rb', line 97 def update(*args, &block) if args.size==1 and args.first.respond_to?(:to_dao) to_dao = args.first.to_dao return super(to_dao) end super end |