Module: SearchObject::Base::ClassMethods

Defined in:
lib/search_object/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



62
63
64
# File 'lib/search_object/base.rb', line 62

def config
  @config
end

Instance Method Details

#inherited(base) ⇒ Object



64
65
66
# File 'lib/search_object/base.rb', line 64

def inherited(base)
  base.instance_variable_set '@config', Helper.deep_copy(config)
end

#option(name, options = nil, &block) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/search_object/base.rb', line 72

def option(name, options = nil, &block)
  options = { default: options } unless options.is_a?(Hash)

  name    = name.to_s
  default = options[:default]
  handler = options[:with] || block

  config[:defaults][name] = default unless default.nil?
  config[:options][name]  = Helper.normalize_search_handler(handler, name)

  define_method(name) { @search.param name }
end

#results(*args) ⇒ Object



85
86
87
# File 'lib/search_object/base.rb', line 85

def results(*args)
  new(*args).results
end

#scope(&block) ⇒ Object



68
69
70
# File 'lib/search_object/base.rb', line 68

def scope(&block)
  config[:scope] = block
end