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.



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

def config
  @config
end

Instance Method Details

#inherited(base) ⇒ Object



54
55
56
# File 'lib/search_object/base.rb', line 54

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

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



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/search_object/base.rb', line 62

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



75
76
77
# File 'lib/search_object/base.rb', line 75

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

#scope(&block) ⇒ Object



58
59
60
# File 'lib/search_object/base.rb', line 58

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