Module: Structure::JSON
- Defined in:
- lib/structure/json.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#as_json(options = nil) ⇒ JSON
Converts structure to its JSON representation.
-
#to_json(*args) ⇒ JSON
Converts structure to its JSON representation.
Class Method Details
.included(base) ⇒ Object
9 10 11 |
# File 'lib/structure/json.rb', line 9 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#as_json(options = nil) ⇒ JSON
Converts structure to its JSON representation
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/structure/json.rb', line 28 def as_json( = nil) subset = if if only = [:only] @attributes.slice(*Array.wrap(only)) elsif except = [:except] @attributes.except(*Array.wrap(except)) else @attributes.dup end else @attributes.dup end { ::JSON.create_id => self.class.name }. merge(subset) end |
#to_json(*args) ⇒ JSON
Converts structure to its JSON representation
17 18 19 20 21 |
# File 'lib/structure/json.rb', line 17 def to_json(*args) { ::JSON.create_id => self.class.name }. merge(@attributes). to_json(*args) end |