Module: ApiTools
- Included in:
- ActiveRecord::Base
- Defined in:
- lib/api_tools.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#as_json(_options = {}) ⇒ Object
TODO: Add relationships for object.
- #for_api(_options = {}) ⇒ Object
- #json_root ⇒ Object
- #list_json(_options = {}) ⇒ Object
- #to_xml(options = {}) ⇒ Object
- #to_yaml(options = {}) ⇒ Object
Class Method Details
.included(base) ⇒ Object
3 4 5 |
# File 'lib/api_tools.rb', line 3 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#as_json(_options = {}) ⇒ Object
TODO: Add relationships for object
29 30 31 |
# File 'lib/api_tools.rb', line 29 def as_json( = {}) { json_root => self.class.render_class.to_hash(self), 'lims' => configatron.amqp.lims_id! } end |
#for_api(_options = {}) ⇒ Object
13 14 15 |
# File 'lib/api_tools.rb', line 13 def for_api( = {}) self.class.render_class.to_hash(self) end |
#json_root ⇒ Object
37 38 39 |
# File 'lib/api_tools.rb', line 37 def json_root self.class.to_s.underscore end |
#list_json(_options = {}) ⇒ Object
24 25 26 |
# File 'lib/api_tools.rb', line 24 def list_json( = {}) self.class.render_class.to_hash_for_list(self) end |
#to_xml(options = {}) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/api_tools.rb', line 17 def to_xml( = {}) renamed_keys = for_api.inject({}) { |renamed_keys, (key, value)| renamed_keys.tap { renamed_keys[key.underscore] = value } } .reverse_merge!(root: self.class.to_s.underscore, skip_types: true) renamed_keys.to_xml() end |
#to_yaml(options = {}) ⇒ Object
33 34 35 |
# File 'lib/api_tools.rb', line 33 def to_yaml( = {}) for_api.to_yaml() end |