Class: MundaneSearch::ResultModel

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, AttributeColumn
Defined in:
lib/mundane-search/result_model.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ ResultModel

Returns a new instance of ResultModel.



43
44
45
# File 'lib/mundane-search/result_model.rb', line 43

def initialize(result)
  @result = result
end

Class Method Details

.model_class_for(result_class) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mundane-search/result_model.rb', line 11

def self.model_class_for(result_class)
  builder = result_class.builder
  Class.new(ResultModel) do |model_class|
    model_class.model_name = result_class.options[:name] || result_class.name
    builder.filter_canisters.each do |fc|
      fc.option_keys_with_types.each do |key, type|
        attribute_column(key, type)
        define_method(key) do
          send(:result).stack.params[key.to_s]
        end
      end
    end
  end
end

.model_nameObject



32
33
34
35
36
# File 'lib/mundane-search/result_model.rb', line 32

def self.model_name
  name = 'GenericSearch' unless self.name
  namespace = nil
  ForcedSingularRouteKeyName.new(self, namespace, (@model_name || name))
end

.model_name=(name) ⇒ Object

As string, for when ActionView turns a model name into a url.



39
40
41
# File 'lib/mundane-search/result_model.rb', line 39

def self.model_name=(name)
  @model_name = name
end

Instance Method Details

#paramsObject

Added this for the benefit of search_url_for If it stays, it should replace stack.params in the method above.



28
29
30
# File 'lib/mundane-search/result_model.rb', line 28

def params
  send(:result).stack.params
end

#persisted?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/mundane-search/result_model.rb', line 55

def persisted?
  false
end

#to_keyObject



47
48
49
# File 'lib/mundane-search/result_model.rb', line 47

def to_key
  ['result-of-to-key']
end

#to_modelObject



51
52
53
# File 'lib/mundane-search/result_model.rb', line 51

def to_model
  self
end