Module: Dilute::Modelize
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/dilute/modelize.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #attributes_without_elasticsearch_vars ⇒ Object
- #destroy ⇒ Object
- #id ⇒ Object
- #initialize(attributes = {}) ⇒ Object
- #save ⇒ Object
- #type ⇒ Object
Instance Method Details
#attributes_without_elasticsearch_vars ⇒ Object
80 81 82 83 |
# File 'lib/dilute/modelize.rb', line 80 def attributes_without_elasticsearch_vars # elasticsearch_vars = %w(ok _index _type _id _version) attributes["_source"] end |
#destroy ⇒ Object
103 104 105 106 |
# File 'lib/dilute/modelize.rb', line 103 def destroy raise "id can't be nil" unless id type.delete(id) end |
#id ⇒ Object
76 77 78 |
# File 'lib/dilute/modelize.rb', line 76 def id attributes["_id"] end |
#initialize(attributes = {}) ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/dilute/modelize.rb', line 108 def initialize(attributes = {}) @attributes = if attributes.has_key?("_source") attributes else {"_source" => HashWithIndifferentAccess.new.merge(attributes)} end end |
#save ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/dilute/modelize.rb', line 85 def save run_callbacks :save do if valid? if id type.put(id, attributes_without_elasticsearch_vars) else results = type.post(attributes_without_elasticsearch_vars) if results["ok"] == true attributes.merge!(results) else puts "Something went wrong!" puts "attributes: #{attributes}" end end end end end |
#type ⇒ Object
116 117 118 |
# File 'lib/dilute/modelize.rb', line 116 def type self.class.type.type end |