Class: MundaneSearch::ResultModel
- Inherits:
-
Object
- Object
- MundaneSearch::ResultModel
- Includes:
- ActiveModel::Validations, AttributeColumn
- Defined in:
- lib/mundane-search/result_model.rb
Class Method Summary collapse
- .model_class_for(result_class) ⇒ Object
- .model_name ⇒ Object
-
.model_name=(name) ⇒ Object
As string, for when ActionView turns a model name into a url.
Instance Method Summary collapse
-
#initialize(result) ⇒ ResultModel
constructor
A new instance of ResultModel.
-
#params ⇒ Object
Added this for the benefit of search_url_for If it stays, it should replace stack.params in the method above.
- #persisted? ⇒ Boolean
- #to_key ⇒ Object
- #to_model ⇒ Object
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.[: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_name ⇒ Object
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
#params ⇒ Object
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
55 56 57 |
# File 'lib/mundane-search/result_model.rb', line 55 def persisted? false end |
#to_key ⇒ Object
47 48 49 |
# File 'lib/mundane-search/result_model.rb', line 47 def to_key ['result-of-to-key'] end |
#to_model ⇒ Object
51 52 53 |
# File 'lib/mundane-search/result_model.rb', line 51 def to_model self end |