class SearchEnjoy::Schema::Mapping
class responsible for creating hash schema due to schema DSL
Constants
- FILLED_FIELDS
- NESTED_FIELDS
Attributes
mapping[R]
Public Class Methods
new()
click to toggle source
# File lib/search_enjoy/schema.rb, line 24 def initialize @mapping = {} end
Public Instance Methods
respond_to_missing?()
click to toggle source
# File lib/search_enjoy/schema.rb, line 28 def respond_to_missing?; end
Private Instance Methods
array_type(type, &block)
click to toggle source
# File lib/search_enjoy/schema.rb, line 50 def array_type(type, &block) # @mapping[:array] = if block_given? # nested_mapping = Mapping.new # nested_mapping.instance_eval(&block) # # nested_mapping.mapping # else # type # end hash_key(:array, type, &block) end
hash_key(key, value_type, &block)
click to toggle source
@todo Think about other DSL
attr1(:array).of :integer attr2(:hash).with do
key(:key_1).of :integer
end
# File lib/search_enjoy/schema.rb, line 39 def hash_key(key, value_type, &block) @mapping[key] = if block_given? nested_mapping = Mapping.new nested_mapping.instance_eval(&block) nested_mapping.mapping else value_type end end
method_missing(method, *args, &block)
click to toggle source
# File lib/search_enjoy/schema.rb, line 63 def method_missing(method, *args, &block) type = args.first @mapping[method] = type if FILLED_FIELDS.include? type if NESTED_FIELDS.include? type nested_mapping = Mapping.new nested_mapping.instance_eval(&block) @mapping[method] = nested_mapping.mapping end @mapping[method] end