Module: Elasticsearch::Persistence::Model::Rails
- Defined in:
- lib/elasticsearch/persistence/model/rails.rb
Overview
Make the ‘Persistence::Model` models compatible with Ruby On Rails applications
Class Method Summary collapse
-
.__convert_rails_dates(attributes = {}) ⇒ Object
Decorates the passed in ‘attributes` so they extract the date & time values from Rails forms.
- .included(base) ⇒ Object
Class Method Details
.__convert_rails_dates(attributes = {}) ⇒ Object
Decorates the passed in ‘attributes` so they extract the date & time values from Rails forms
34 35 36 37 38 39 40 41 42 |
# File 'lib/elasticsearch/persistence/model/rails.rb', line 34 def __convert_rails_dates(attributes={}) day = attributes.select { |p| p =~ /\([1-3]/ }.reduce({}) { |sum, item| (sum[item.first.gsub(/\(.+\)/, '')] ||= '' )<< item.last+'-'; sum } time = attributes.select { |p| p =~ /\([4-6]/ }.reduce({}) { |sum, item| (sum[item.first.gsub(/\(.+\)/, '')] ||= '' )<< item.last+':'; sum } unless day.empty? attributes.update day.reduce({}) { |sum, item| sum[item.first] = item.last; sum[item.first] += ' ' + time[item.first] unless time.empty?; sum } end return attributes end |
.included(base) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/elasticsearch/persistence/model/rails.rb', line 8 def self.included(base) base.class_eval do def initialize(attributes={}) super(__convert_rails_dates(attributes)) end def update(attributes={}, ={}) super(__convert_rails_dates(attributes), ) end end end |