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.



45
46
47
# File 'lib/search_object/base.rb', line 45

def config
  @config
end

Instance Method Details

#inherited(base) ⇒ Object



47
48
49
# File 'lib/search_object/base.rb', line 47

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

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



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/search_object/base.rb', line 55

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[:actions][name]  = Helper.normalize_search_handler(handler, name)

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

#results(*args) ⇒ Object



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

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

#scope(&block) ⇒ Object



51
52
53
# File 'lib/search_object/base.rb', line 51

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