Class: APIQL::Entity
- Inherits:
-
Object
- Object
- APIQL::Entity
- Defined in:
- lib/apiql.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.apiql_attributes ⇒ Object
readonly
Returns the value of attribute apiql_attributes.
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(object, context) ⇒ Entity
constructor
A new instance of Entity.
- #render(schema = nil) ⇒ Object
Constructor Details
#initialize(object, context) ⇒ Entity
163 164 165 166 167 |
# File 'lib/apiql.rb', line 163 def initialize(object, context) @object = object @context = context @context.inject_delegators(self) end |
Class Attribute Details
.apiql_attributes ⇒ Object (readonly)
Returns the value of attribute apiql_attributes.
141 142 143 |
# File 'lib/apiql.rb', line 141 def apiql_attributes @apiql_attributes end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
161 162 163 |
# File 'lib/apiql.rb', line 161 def object @object end |
Class Method Details
.attributes(*attrs) ⇒ Object
155 156 157 158 |
# File 'lib/apiql.rb', line 155 def attributes(*attrs) @apiql_attributes ||= [] @apiql_attributes += attrs.map(&:to_sym) end |
.inherited(child) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/apiql.rb', line 143 def inherited(child) super return if self.class == ::APIQL::Entity attributes = apiql_attributes&.try(:deep_dup) || [] child.instance_eval do @apiql_attributes = attributes end end |
Instance Method Details
#render(schema = nil) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/apiql.rb', line 169 def render(schema = nil) return unless @object.present? respond = {} schema.each do |field| if field.is_a? Hash field.each do |field, sub_schema| name = field.is_a?(Array) ? field.first : field respond[name] = render_attribute(field, sub_schema) end else name = field.is_a?(Array) ? field.first : field respond[name] = render_attribute(field) end end respond end |