Module: ActsAsEstraierDoc::InstanceMethods
- Defined in:
- lib/acts_as_estraier_doc.rb
Instance Method Summary collapse
- #add_est_index ⇒ Object
- #est_id ⇒ Object
- #remove_est_index ⇒ Object
- #to_estdoc ⇒ Object
- #to_json_with_estdoc(*args) ⇒ Object
- #to_xml_with_estdoc(*args) ⇒ Object
- #update_est_index ⇒ Object
Instance Method Details
#add_est_index ⇒ Object
182 183 184 185 186 |
# File 'lib/acts_as_estraier_doc.rb', line 182 def add_est_index raise if new_record? return if respond_to?(:est_no_index) and est_no_index raise self.estraier_conn.status.to_s unless self.estraier_conn.put_doc(to_estdoc) end |
#est_id ⇒ Object
193 194 195 196 |
# File 'lib/acts_as_estraier_doc.rb', line 193 def est_id raise if new_record? _estdoc.attr('@id') end |
#remove_est_index ⇒ Object
188 189 190 191 |
# File 'lib/acts_as_estraier_doc.rb', line 188 def remove_est_index raise if new_record? raise self.estraier_conn.status.to_s unless self.estraier_conn.out_doc(est_id) end |
#to_estdoc ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/acts_as_estraier_doc.rb', line 98 def to_estdoc doc = EstraierPure::Document::new doc.add_attr('@uri', self.est_uri.to_s) doc.add_attr('@title', self.est_title.to_s) doc.add_attr('record_id', self.id.to_s) doc.add_attr('record_class', self.class.to_s) if respond_to? :est_attributes est_attributes.each do |name, value| doc.add_attr(name.to_s, value) end end if respond_to? :est_hidden_texts est_hidden_texts.to_a.each do |value| doc.add_hidden_text(value) end end est_texts.to_a.each do |value| doc.add_text(value) end doc end |
#to_json_with_estdoc(*args) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/acts_as_estraier_doc.rb', line 149 def to_json_with_estdoc(*args) obj = ActiveSupport::JSON.decode(to_json_without_estdoc(*args)) = args. doc = estdoc || _estdoc obj['estraier'] = {} if [:with_pseudo_attributes] obj['estraier']['pseudo-attributes'] = {} doc.attr_names.grep(/^#/).each do |name| obj['estraier']['pseudo-attributes'][name.sub('#', '')] = doc.attr(name) end end obj['estraier']['system-attributes'] = {} doc.attr_names.grep(/^@/).each do |name| obj['estraier']['system-attributes'][name.sub('@', '')] = doc.attr(name) end obj['estraier']['attributes'] = {} doc.attr_names.grep(/^[^@#]/).each do |name| next if name == 'record_id' or name == 'record_class' obj['estraier']['attributes'][name] = doc.attr(name) end ActiveSupport::JSON.encode(obj) end |
#to_xml_with_estdoc(*args) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/acts_as_estraier_doc.rb', line 120 def to_xml_with_estdoc(*args) xml = to_xml_without_estdoc(*args).split("\n") = args. xml_foot = xml.pop xml << ' <estraier>' doc = estdoc || _estdoc if [:with_pseudo_attributes] xml << ' <pseudo-attributes>' doc.attr_names.grep(/^#/).each do |name| xml << " <#{name.sub('#', '')}>#{doc.attr(name)}</#{name.sub('#', '')}>" end xml << ' </pseudo-attributes>' end xml << ' <system-attributes>' doc.attr_names.grep(/^@/).each do |name| xml << " <#{name.sub('@', '')}>#{doc.attr(name)}</#{name.sub('@', '')}>" end xml << ' </system-attributes>' xml << ' <attributes>' doc.attr_names.grep(/^[^@#]/).each do |name| next if name == 'record_id' or name == 'record_class' xml << " <#{name}>#{doc.attr(name)}</#{name}>" end xml << ' </attributes>' xml << ' </estraier>' xml << xml_foot xml.join("\n") end |
#update_est_index ⇒ Object
172 173 174 175 176 177 178 179 180 |
# File 'lib/acts_as_estraier_doc.rb', line 172 def update_est_index return if self.skip_update_est_index raise if new_record? begin remove_est_index rescue end add_est_index end |