Class: NormalizrRuby::Schema
- Inherits:
-
Object
- Object
- NormalizrRuby::Schema
- Defined in:
- lib/normalizr_ruby/schema.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#props ⇒ Object
readonly
Returns the value of attribute props.
Class Method Summary collapse
- .association(key, options = {}) ⇒ Object
- .attribute(key, options = {}) ⇒ Object
- .inherited(child) ⇒ Object
Instance Method Summary collapse
- #association_resource(association_key) ⇒ Object
- #associations ⇒ Object
- #attributes ⇒ Object
- #entity_key ⇒ Object
-
#initialize(object, context, props) ⇒ Schema
constructor
A new instance of Schema.
Constructor Details
#initialize(object, context, props) ⇒ Schema
Returns a new instance of Schema.
25 26 27 28 29 |
# File 'lib/normalizr_ruby/schema.rb', line 25 def initialize(object, context, props) @object = object @context = context @props = props end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'lib/normalizr_ruby/schema.rb', line 3 def context @context end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
3 4 5 |
# File 'lib/normalizr_ruby/schema.rb', line 3 def object @object end |
#props ⇒ Object (readonly)
Returns the value of attribute props.
3 4 5 |
# File 'lib/normalizr_ruby/schema.rb', line 3 def props @props end |
Class Method Details
.association(key, options = {}) ⇒ Object
21 22 23 |
# File 'lib/normalizr_ruby/schema.rb', line 21 def self.association(key, = {}) _associations[key] = ; end |
.attribute(key, options = {}) ⇒ Object
17 18 19 |
# File 'lib/normalizr_ruby/schema.rb', line 17 def self.attribute(key, = {}) _attributes[key] = ; end |
.inherited(child) ⇒ Object
11 12 13 14 15 |
# File 'lib/normalizr_ruby/schema.rb', line 11 def self.inherited(child) super child._attributes = _attributes.dup child._associations = _associations.dup end |
Instance Method Details
#association_resource(association_key) ⇒ Object
59 60 61 |
# File 'lib/normalizr_ruby/schema.rb', line 59 def association_resource(association_key) object.send(association_key) end |
#associations ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/normalizr_ruby/schema.rb', line 40 def associations hash = {} self.class._associations.each do |key, | next if [:if] && !send([:if]) hash[key] = .except(:if) end hash end |
#attributes ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/normalizr_ruby/schema.rb', line 31 def attributes hash = {} self.class._attributes.each do |key, | next if [:if] && !send([:if]) hash[key] = respond_to?(key) ? send(key) : object.send(key) end hash end |
#entity_key ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/normalizr_ruby/schema.rb', line 49 def entity_key klass = object.class if klass.respond_to?(:base_class) klass = klass.base_class end klass.name .pluralize .to_sym end |