Class: Shirtsio::DSL::QueryBuilder
- Inherits:
-
Object
- Object
- Shirtsio::DSL::QueryBuilder
- Defined in:
- lib/shirtsio/dsl.rb
Instance Method Summary collapse
-
#initialize(dsl, prefixes_with_index = []) {|_self| ... } ⇒ QueryBuilder
constructor
A new instance of QueryBuilder.
- #method_missing(method, *args, &block) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(dsl, prefixes_with_index = []) {|_self| ... } ⇒ QueryBuilder
Returns a new instance of QueryBuilder.
65 66 67 68 69 70 71 72 |
# File 'lib/shirtsio/dsl.rb', line 65 def initialize(dsl, prefixes_with_index = [], &block) @dsl = dsl @prefixes_with_index = [] @prefixes_with_index << prefixes_with_index @prefixes_with_index.flatten! @params = {} yield self end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/shirtsio/dsl.rb', line 74 def method_missing(method, *args, &block) index = extract_index(method.to_sym) return super unless index params = {} if index.kind_of?(Symbol) if args[0].kind_of?(Array) args[0].each_with_index do |v,i| params[method] = { i => v } end elsif args[0].kind_of?(File) params[method] = Faraday::UploadIO.new(args[0].path, Shirtsio::Utils.mime_type(args[0].path)) else params[method] = args[0] end elsif index.kind_of?(Array) params[method] = QueryBuilder.new(index, @prefixes_with_index, &block).to_hash end params.map do |k,v| if @prefixes_with_index.include?(k) @params[k] = {} if @params[k].nil? @params[k].merge!({ @params[k].size => v }) else @params.merge!({ k => v }) end end end |
Instance Method Details
#to_hash ⇒ Object
101 102 103 |
# File 'lib/shirtsio/dsl.rb', line 101 def to_hash @params end |